dotsnboxes. overview dots and boxes is played originally with the use of paper, pen and 2 players....
DESCRIPTION
Requirements Design a graphical user interface Create a multi-threaded client/server application that utilizes stream sockets Handle disconnects on either the client or server side Server to support multiple game instances Appropriate edit-checking on user-submitted dataTRANSCRIPT
DOTSNBOXES
Overview• Dots and Boxes is played originally with the use of paper, pen
and 2 players. • The Game board is a matrix of points and vary in size.
However an odd number of squares is desired to reduce a tie.• Players draw one line at a time. If they complete a square
they get to put their initial in the box and go again. • Ideally the goal of the game is to get as many boxes with your
initial in it.• This is ideally done with a long collection of boxes collected
one after the other.
Requirements• Design a graphical user interface• Create a multi-threaded client/server application that utilizes
stream sockets• Handle disconnects on either the client or server side• Server to support multiple game instances• Appropriate edit-checking on user-submitted data
Additional Features• Login screen for clients to choose their own usernames to
uniquely identify themselves.• Lobby area, to provide:
– a list of all users currently online– a list of all active/pending games
• Shows the player(s) currently in the game• Users may create new games or join games with an empty spot available
• Users may play multiple games simultaneously
Gameplay Logic
At initialization: Assign each edge an EdgeID, each box a BoxID. For each box, assign its edges (Top, Bottom, Left, Right) the appropriate EdgeID. For each edge, assign its boxes (max 2) the appropriate BoxID.During Gameplay: For each edge that is drawn on by the players,
1. Flag the edges as ‘exists’.2. Check the edge’s associated BoxID’s (up to 2) and check which edges exist.
If all four edges exist, then draw the box(es).
Network Interface/Infrastructure
Client Server
ClientNetworkInterface – Sets up a TcpClient, given the hostname and port ServerNetworkInterface – Sets up a NetworkStream, given a socket Mechanized Packets to send data across the connection 2 methods using BinaryFormatter:
• Convert serialized byte array to Packet• Convert Packet to serialized byte array
Client sidemodule
Server sidemodule
ClientNetworkInterface ServerNetworkInterface
Packet
Network Interface/Infrastructure
Packet StructureType : byteHeader
Body
ConnectResponseClientIDPlayer1NamePlayer2Name
CreateGameSuccessPortNumberGameNamePlayer1NamePlayer2Name
PlayerTurnPlayerID
GameForm
Lobby Server
System Block Diagram
Thread
Socket
s User
Network Interface
s User
s User
TcpListener
LoginLoginLobbyForm
Client Server
Game ServerTcpListener
LoginLoginLoginForm
s Player2
s Player1
Port 50000
Ports 51000+GameForm
List
GameForm
Lobby Server
Connecting
GetStream
Socket
s User1
Network Interface
s User2
TcpListener
LoginLobbyForm1
Client Server
Game ServerTcpListener
LoginLoginForm1
s Player2
s Player1
Port 50000
Ports 51000+GameForm
List
User1 Thread
User2 Thread
Example
TcpClient
Neutral Thread
LoginForm1 BinaryReader
BinaryWriter
TcpClientGetStream
Disconnect HandlingClient Server
ClientNetworkInterface ServerNetworkInterface
Packet
bytes (b) – The size in bytes of the packet. BinaryWriter (Success) – Write method sends a packet of size b across the connection. BinaryWriter (Failure) – Write method throws a System.IO.IOException exception. BinaryReader (Success) – Read method accepts a packet and returns its size b. BinaryReader (Failure) – Read method returns 0 upon disconnection.
b > 0BinaryWriter
BinaryWriterBinaryReader
BinaryReader
0
Lobby Server
Game Server
SocketException
Attempting to reconnect . . .
0
GameForm
Disconnect Handling
Neutral Thread
Socket
s User1
Network Interface
s User2
Lobby Form
LobbyForm
Client Server
Login Form
LoginForm
s Player1GameForm
User1 Thread
User2 Thread
Login Form
0
LoginForm
s Player2
You win bydefault.
Example
0
Error Checking• Prevent duplicate users• Prevent duplicate game names• Prevent user from joining his own game• Prevent user from joining a full game• Prevent user from joining a game that no longer exists• Prevent multiple servers on the same port• Prevent erroneous user input• Handle disconnects accordingly
Screenshots - ClientClient Without a Server to Connect to will retry to Connect.
Screenshots - ClientOnce the Server is stated, the Client will automatically connect!
Screenshots - LobbyOnce connected a lobby will show Games and Players on the Server.
Currently No Games
There is only currentlyone player
Screenshots - LobbyEntering a GAME name in the box and clicking “Create Game” will add a new game to the lobby and start you in a new game of DotsNBoxes.
One Game is Waiting Players
myNewGame
Screenshots - LobbyWhen more games are created, users wanting to play a game can see the Games in the Lobby. If a User Clicks “Join” they will start a game with the other player
Screenshots - ClientBoth Users will have a game console like the one below.
Moving the mouse aroundWill highlight clickable spots for User selection
Screenshots - ClientThe User can highlightover edges and the boxeswill light up.
Once a User selects a linethe server will register the click and it will be the otherplayer’s turn if it’s nota box creation.
Screenshots - ClientAfter boxes are createdthey light up with the players texture.
The Score is shown to theright.
Screenshots - ClientOnce a user wins the gameThey will see a flashinghappy face..
As for the loser…
Screenshots - ClientThe Loser gets a flashing Sad face.
Both Users now have to click the EXIT button to return back to the lobby.
Screenshots - Client
Users may play multiple games simultaneously by going back to the lobby and creating/joining new games.
Screenshots - ServerThroughout all the connections and game interactions, the server shows information being written to a console output.
Obstacles – Unexpected Game Over
What happens if a player quits in the middle of a game? This will automatically send a message to the user still in game that the user has ended the game and they may click “Exit” to return to the lobby.Sadly... You will not see the happy face for this type of win.
Questions?