250 likes | 418 Views
Mahjong Game. Clients. Server. Mahjong Game. Clients. Server. Mahjong Game. Good design will pay off in the long run Item Identify appropriate classes and interfaces. Mahjong Game. Clients. JOIN, PlayerName. Server. Design a communication protocol. Mahjong Game. Clients.
E N D
Mahjong Game Clients Server
Mahjong Game Clients Server
Mahjong Game Good design will pay off in the long run Item Identify appropriate classes and interfaces
Mahjong Game Clients JOIN, PlayerName Server Design a communication protocol
Mahjong Game Clients Server Design a communication protocol PLAYER_JOINED, PlayerName PLAYER_JOINED, PlayerName PLAYER_JOINED, PlayerName
Mahjong Game Clients READY Server Design a communication protocol READY READY
Mahjong Game Clients Server Design a communication protocol TILE_SET, … … … TILE_SET, … … … TILE_SET, … … …
Mahjong Game Clients Server Design a communication protocol GUESS, 9, 2
Mahjong Game Clients Server Good design will pay off in the long run Item Identify appropriate classes and interfaces Design a communication protocol SCORE, +1
Mahjong Game Clients Server Design a communication protocol NEW_TILES, 8, 3 NEW_TILES, 8, 3 NEW_TILES, 8, 3
Mahjong Game JOIN PlayerName Design communication protocol – packets of data of agreed upon format Join Request:
Mahjong Game JOIN PlayerName READY Design communication protocol – packets of data of agreed upon format Join Request: Ready Request:
Mahjong Game JOIN PlayerName READY Design communication protocol – packets of data of agreed upon format Join Request: Ready Request: Player Joined: PLAYER_JOINED PlayerName
Mahjong Game JOIN PlayerName READY Design communication protocol – packets of data of agreed upon format Join Request: Ready Request: Player Joined: Player Guess: PLAYER_JOINED PlayerName Guess Tile 1 Tile 2
Mahjong Game JOIN PlayerName READY Design communication protocol – packets of data of agreed upon format Join Request: Ready Request: Player Joined: Player Guess: Replace Tiles: PLAYER_JOINED PlayerName Guess Tile 1 Tile 2 REPLACE Old Tile 1 New Tile 1 Old Tile 2 New Tile 2
Mahjong Game JOIN PlayerName READY Design communication protocol – packets of data of agreed upon format Join Request: Ready Request: Player Joined: Player Guess: Replace Tiles: Initial Tiles: PLAYER_JOINED PlayerName Guess Tile 1 Tile 2 REPLACE Old Tile 1 New Tile 1 Old Tile 2 New Tile 2 TILES Count Tile 1 Tile 2 Tile N
Mahjong Game JOIN PlayerName READY Design communication protocol – packets of data of agreed upon format Join Request: Ready Request: Player Joined: Player Guess: Replace Tiles: Initial Tiles: Update Score: PLAYER_JOINED PlayerName Guess Tile 1 Tile 2 REPLACE Old Tile 1 New Tile 1 Old Tile 2 New Tile 2 TILES Count Tile 1 Tile 2 Tile N UPDATE_SCORE Amount
Mahjong Game JOIN PlayerName READY Design communication protocol – packets of data of agreed upon format Join Request: Ready Request: Player Joined: Player Guess: Replace Tiles: Initial Tiles: Update Score: PLAYER_JOINED PlayerName Guess Tile 1 Tile 2 REPLACE Old Tile 1 New Tile 1 Old Tile 2 New Tile 2 TILES Count Tile 1 Tile 2 Tile N UPDATE_SCORE Amount
Mahjong Game 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 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 SERVER players Class design round tiles
Mahjong Game SERVER PLAYER players name Class design (server side) score socket connection round input channel tiles output channel
Mahjong Game MIDLET (main app) TILES CANVAS TILE user interface widgets displayed tiles image Class design (client side) ulx, uly name selected tiles selected score round
Mahjong Game SOCKET IO (Thread) Class design (client side) input steam (reads in run method) output steam (writes as needed)