mahjong game server clients. mahjong game server clients

24
Mahjong Game Server Clients

Post on 21-Dec-2015

231 views

Category:

Documents


0 download

TRANSCRIPT

Mahjong Game

Server

Clients

Mahjong Game

Server

Clients

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

Identify appropriate classes and interfaces

Mahjong Game

Design a communication protocol

Server

Clients

JOIN, PlayerName

Mahjong Game

Design a communication protocol

Server

Clients

PLAYER_JOINED, PlayerName

PLAYER_JOINED, PlayerName

PLAYER_JOINED, PlayerName

Mahjong Game

Design a communication protocol

Server

Clients

READY

READY

READY

Mahjong Game

Design a communication protocol

Server

Clients

TILE_SET, … … …

TILE_SET, … … …

TILE_SET, … … …

Mahjong Game

Design a communication protocol

Server

Clients

GUESS, 9, 2

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

Mahjong Game

Design a communication protocol

Server

Clients

NEW_TILES, 8, 3

NEW_TILES, 8, 3

NEW_TILES, 8, 3

Design communication protocol – packets of data of agreed upon format

Join Request:

Mahjong Game

JOIN PlayerName

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:

Mahjong Game

JOIN PlayerName

READY

PLAYER_JOINED PlayerName

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

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

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

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

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

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

Class design

Mahjong Game

players

SERVER

round

tiles

Class design (server side)

Mahjong Game

players

SERVER

round

tiles

PLAYER

name

score

socket connection

input channel

output channel

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

Class design (client side)

Mahjong Game

SOCKET IO(Thread)

input steam (reads in run method)

output steam (writes as needed)