8: Battleship II
Fall 2007, David Matuszek
In Assignment 5 you created a text-only version
of the Battleship game. In that assignment, the
Ocean class did all the computational
Battleship class managed input and output.
In this assignment you will start with an already written
yours or your new partners, whichever you prefer, but not the
one I posted--and replace the
with one that uses GUIs. You can use
OceanTest class, or one of your own. You will need two
GUIs, one to create a new game, and one to play the game.
The "ocean" will be displayed as a 10 by 10 grid in a
and will look somewhat like the following.
As before, your
Battleship class will be in charge of input/output.
This time, however, the input/output will be graphical.
We will assume two players, the "creator" and the "destroyer." The creator sets up a game by placing all the ships; the destroyer tries to sink them.
When the program starts, the creator should see an empty ocean. The creator can place ships wherever he/she wants, and can also remove them.
JFrame. Eclipse can help with the details, or you can read the API.)
Randombutton, to place all ships randomly. If this button is clicked, this will create an entirely new arrangement; any previous ship placements are discarded. However, the creator may then modify this random placement by removing and replacing ships.
Playbutton. When the creator is satisified with the ship placement, clicking this button will cause the creator's GUI to be closed, and the player's GUI (with all ships hidden) to open. (Do not automatically move on to game play when all ships are placed; the creator may still want to move them around.)
Playbutton is clicked, or some of each.
Most of the details of the interface are left up to you. Make the GUI as obvious and intuitive as you can--we will test the program by using it, and you will lose points if it's difficult to figure out what to do.
When the creator is done, the player is presented with an ocean that looks empty, but contains hidden ships.
The player should be able to "shoot at" locations
in the ocean by clicking on individual squares with the mouse. (Hint: Add a
Eclipse can help with the details, or you can read the API.
You may need to remove a previous
Keep the player informed about what is going on.
Play Againbutton that can be clicked to start a new game. If this is clicked before the current game has been won, use a dialog box to ask the user to confirm (or cancel) the request.
Most of the details of the interface are left up to you.
Thursday, November 8, before midnight. Turn in your program electronically, using Blackboard. (See my Instructions for Using Zip Files and Blackboard). Only assignments submitted via Blackboard will be accepted--do not send your program by email. The usual late penalty of 5 points per day (out of 100 points) will apply.