Mahjong Game

24
Mahjong Game Server Clients

description

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. - PowerPoint PPT Presentation

Transcript of Mahjong Game

Page 1: Mahjong Game

Mahjong Game

Server

Clients

Page 2: Mahjong Game

Mahjong Game

Server

Clients

Page 3: Mahjong Game

Mahjong Game Good design will pay off in the long run Item

Identify appropriate classes and interfaces

Page 4: Mahjong Game

Mahjong Game

Design a communication protocol

Server

Clients

JOIN, PlayerName

Page 5: Mahjong Game

Mahjong Game

Design a communication protocol

Server

Clients

PLAYER_JOINED, PlayerName

PLAYER_JOINED, PlayerName

PLAYER_JOINED, PlayerName

Page 6: Mahjong Game

Mahjong Game

Design a communication protocol

Server

Clients

READY

READY

READY

Page 7: Mahjong Game

Mahjong Game

Design a communication protocol

Server

Clients

TILE_SET, … … …

TILE_SET, … … …

TILE_SET, … … …

Page 8: Mahjong Game

Mahjong Game

Design a communication protocol

Server

Clients

GUESS, 9, 2

Page 9: Mahjong Game

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

Page 10: Mahjong Game

Mahjong Game

Design a communication protocol

Server

Clients

NEW_TILES, 8, 3

NEW_TILES, 8, 3

NEW_TILES, 8, 3

Page 11: Mahjong Game

Design communication protocol – packets of data of agreed upon format

Join Request:

Mahjong Game

JOIN PlayerName

Page 12: Mahjong Game

Design communication protocol – packets of data of agreed upon format

Join Request:

Ready Request:

Mahjong Game

JOIN PlayerName

READY

Page 13: Mahjong Game

Design communication protocol – packets of data of agreed upon format

Join Request:

Ready Request:

Player Joined:

Mahjong Game

JOIN PlayerName

READY

PLAYER_JOINED PlayerName

Page 14: Mahjong Game

Design communication protocol – packets of data of agreed upon format

Join Request:

Ready Request:

Player Joined:

Player Guess:

Mahjong Game

JOIN PlayerName

READY

PLAYER_JOINED PlayerName

Guess Tile 1 Tile 2

Page 15: Mahjong Game

Design communication protocol – packets of data of agreed upon format

Join Request:

Ready Request:

Player Joined:

Player Guess:

Replace Tiles:

Mahjong Game

JOIN PlayerName

READY

PLAYER_JOINED PlayerName

Guess Tile 1 Tile 2

REPLACE Old Tile 1 New Tile 1 Old Tile 2 New Tile 2

Page 16: Mahjong Game

Design communication protocol – packets of data of agreed upon format

Join Request:

Ready Request:

Player Joined:

Player Guess:

Replace Tiles:

Initial Tiles:

Mahjong Game

JOIN PlayerName

READY

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

Page 17: Mahjong Game

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

JOIN PlayerName

READY

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

Page 18: Mahjong Game

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

JOIN PlayerName

READY

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

Page 19: 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

Page 20: 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

Page 21: Mahjong Game

Class design

Mahjong Game

players

SERVER

round

tiles

Page 22: Mahjong Game

Class design (server side)

Mahjong Game

players

SERVER

round

tiles

PLAYER

name

score

socket connection

input channel

output channel

Page 23: Mahjong Game

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

Page 24: Mahjong Game

Class design (client side)

Mahjong Game

SOCKET IO(Thread)

input steam (reads in run method)

output steam (writes as needed)