Download presentation
Presentation is loading. Please wait.
1
Mahjong Game Server Clients
2
Mahjong Game Server Clients
3
Mahjong Game Good design will pay off in the long run Item Identify appropriate classes and interfaces
4
Mahjong Game Design a communication protocol Server Clients JOIN, PlayerName
5
Mahjong Game Design a communication protocol Server Clients PLAYER_JOINED, PlayerName
6
Mahjong Game Design a communication protocol Server Clients READY
7
Mahjong Game Design a communication protocol Server Clients TILE_SET, … … …
8
Mahjong Game Design a communication protocol Server Clients GUESS, 9, 2
9
Mahjong Game Good design will pay off in the long run Item Identify appropriate classes and interfaces Design a communication protocol Server Clients SCORE, +1
10
Mahjong Game Design a communication protocol Server Clients NEW_TILES, 8, 3
11
Design communication protocol – packets of data of agreed upon format Join Request: Mahjong Game JOINPlayerName
12
Design communication protocol – packets of data of agreed upon format Join Request: Ready Request: Mahjong Game JOINPlayerName READY
13
Design communication protocol – packets of data of agreed upon format Join Request: Ready Request: Player Joined: Mahjong Game JOINPlayerName READY PLAYER_JOINEDPlayerName
14
Design communication protocol – packets of data of agreed upon format Join Request: Ready Request: Player Joined: Player Guess: Mahjong Game JOINPlayerName READY PLAYER_JOINEDPlayerName GuessTile 1Tile 2
15
Design communication protocol – packets of data of agreed upon format Join Request: Ready Request: Player Joined: Player Guess: Replace Tiles: Mahjong Game JOINPlayerName READY PLAYER_JOINEDPlayerName GuessTile 1Tile 2 REPLACEOld Tile 1New Tile 1Old Tile 2New Tile 2
16
Design communication protocol – packets of data of agreed upon format Join Request: Ready Request: Player Joined: Player Guess: Replace Tiles: Initial Tiles: Mahjong Game JOINPlayerName READY PLAYER_JOINEDPlayerName GuessTile 1Tile 2 REPLACEOld Tile 1New Tile 1Old Tile 2New Tile 2 TILESCountTile 1Tile 2Tile N
17
Design communication protocol – packets of data of agreed upon format Join Request: Ready Request: Player Joined: Player Guess: Replace Tiles: Initial Tiles: Update Score: Mahjong Game JOINPlayerName READY PLAYER_JOINEDPlayerName GuessTile 1Tile 2 REPLACEOld Tile 1New Tile 1Old Tile 2New Tile 2 TILESCountTile 1Tile 2Tile N UPDATE_SCOREAmount
18
Design communication protocol – packets of data of agreed upon format Join Request: Ready Request: Player Joined: Player Guess: Replace Tiles: Initial Tiles: Update Score: Mahjong Game JOINPlayerName READY PLAYER_JOINEDPlayerName GuessTile 1Tile 2 REPLACEOld Tile 1New Tile 1Old Tile 2New Tile 2 TILESCountTile 1Tile 2Tile N UPDATE_SCOREAmount
19
Server listening thread while (...) { int action = input.readInt(); if (action == JOIN) { processPlayerJoin(); // <-- read rest of data } else if (action == READY) { processPlayerReady(); // <-- read rest of data } else if (action == GUESS) { processPlayerGuess(); // <-- read rest of data } Mahjong Game
20
Client listening thread (similar structure as server) while (...) { int action = input.readInt(); if (action == REPLACE) { processReplaceTiles(); // <-- read rest of data } else if (action == TILES) { processTileSet(); // <-- read rest of data } else if (action == UPDATE_SCORE) { processUpdateScore(); // <-- read rest of data } Mahjong Game
21
Class design Mahjong Game players SERVER round tiles
22
Class design (server side) Mahjong Game players SERVER round tiles PLAYER name score socket connection input channel output channel
23
Class design (client side) Mahjong Game user interface widgets MIDLET (main app) round TILES CANVAS name score displayed tiles selected tiles TILE selected image ulx, uly
24
Class design (client side) Mahjong Game SOCKET IO (Thread) input steam (reads in run method) output steam (writes as needed)
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.