Wednesday, April 13, 2011

Moving forward

Just some notes for the upcoming iteration:

We are currently at the stage where all of the clients are waiting in the lobby for the host to start the game.

When a host player presses the "start game" button:
1. the host must stop broadcasting its game information via UDP to requesting clients
2. the host send a TCP notification to all of the clients that the game will start.
3. the host closes current activity and opens a new activity for the actual game.

While a player is in a lobby, he/she is updated with the player list. Trivioid is waiting for a TCP packet from the host player that the game will begin. When that TCP packet is received, the lobby activity is closed and a game activity is opened  containing class ClientGameController. ClientGameController is a wrapper class for the client end of the game. It contains information like (1) the name of the game (2) the host of the game (3) the type of game (4) number of players (5) team information (6) score information (7) the open TCP connection over which game information is exchanged. ClientGameController contains several methods including parseGamePacket(), sendGamePacket(string data), etc. When the lobby is exited and the new game activity starts, a new ClientGameController is created. Upon creation, it attempts to establish a TCP connection with the host and stores that connection information. In the activity, methods are called like ClientGameController.sendGamePacket("C"). The ClientGameController then sends the following string down the TCP connection to the host "TRIVIOID - ANSWER STRING - |!|playerIP|@|timeDifference|#|C|@@|"

When the host exits the lobby, it opens a new activity to manage the new game. A new class is created by this activity; HostGameController. HostGameController is a wrapper for an arrayList of HostClientConnection. A HostClientConnection is a THREAD managing  the TCP connection between the host and a particular client. So, the host activity contains a HostGameController with various functions like openPolling(time T), closePolling(time T), endGame(). HostGameController contains the game information, see above, along with the list of HostClientConnection, one for each of the clients connected with the host. For example, the host's game activity will call HostGameController.openPolling(time 19:34:21). This would run a for-each loop over the arrayList of HostClientConnection:

forEach(HostClientConnection conn : connectionsList) {
conn.openPoll(19:34:21);
conn.startListening();
}

openPoll(Time theTimeOpen) in HostClientConnection pushes the following string down the TCP connection "TRIVIOID - POLL OPENING - theTimeOpen"

startListening() in HostClientConnection waits on a response from the client or closes when the closePolling() method is called.

hope this makes some sense, Derek.

No comments:

Post a Comment