| Battleship -- CS 351 Fall 2002 Final Project | ||
|---|---|---|
| Prev | Next | |
Battleship is a two player game. Since it'd be a little hard not to cheat if you played against your friend on the same computer, your Battleship program will be network-enabled, and allow you or your opponent to connect to each other. In order to find and pick an opponent, Battleship will connect to a simple program running on a web server using HTTP, and download a list of online players currently waiting for someone to connect to them. On the other hand, if you'd like to listen for a connection from someone interested in playing you, you need to register with the server yourself. Both the listing and registrations operations are simple and are described in detail here.
This will be the only client-server interaction your program will perform. However, the actual client-client interaction with your opponent will be far more complex, and its details are described here.
When the game is launched, and once all the windows are painted, the only operations the user is able to perform will be a) listing online players, or b) registering with the server. At this point, mouse clicks on any part of the client area should be ignored - no game is in progress, after all. Let's assume the player registers himself or herself with the server first. Battleship will connect to the web server and request a specific URL that will instruct the program running on the web server to perform the registration. If the operation is successfull, Battleship will spawn a new thread and instruct it to wait for connection on a specific port (35102). Once a connection is established - an opponent connected - the thread will inform the main window of the event and exit. In case the player asks for the opponent listing, Battleship will connect to the web server, this time with a different URL, read back the response, and parse it. The response is described here. Once the data is parsed, a dialog box will be created consisting of two elements. A listbox will list all the online opponents, and let the user select one by clicking on their name. A Connect button, once clicked, will establish a connection to the IP address associated with the opponent's name.
As soon as the connection is established and the initial handshake (as described in the network implementation) completed, the player will be prompted to place his or her ships on the battlefield (the player's field is the field on the left). The 5-hitter is placed first, then the 4-hitter, and so on. Once the ships are placed, Battleship will send a message to the opponent informing them the player is ready to play. When both parties sent this message, the game begins. The player who initiated the connection gets to fire first.
At this point, Battleship should process clicks on the opponent's field, but only when it's the player's turn, and only as long as the game is in progress. During game play, the player should also be able to disconnect, or start a new game. In both cases, the opponent is informed that the player is disconnecting, and Battleship reinitializes.
Whoever sinks all of their opponent's ships first wins.
When the program starts, the main window and all its child windows will be painted. The main menu will have appropriate menu options grayed out and disabled, and the log window will display a "Battleship initialized." message.


These grids are all the user (you) are able to see during the course of a game. You will see your ships marked on your grid, as well as all the places where your apponent has tried to hit you. You will also, of course see the hits that your opponent has inflicted on your ships. (see examples below)


| Prev | Home | Next |
| Help | Implementation |