Program 2
Battleship, Continued
due Thursday, February 23rd by the start of lab
Lab Partners
Everyone is encouraged to work with one lab partner (who is in
the same lab section as yourself) on this assignment.
If you do work with a partner, submit one solution with both of your
names on it. Also, please look at the
class
collaboration policy so that you know what is and what isn't
allowed.
General Overview
In industry, a very common scenario is to take an existing piece
of code and then to modify it based on some requirements set forth
by your project group manager. In order to do this,
you must be able to look at and understand someone else's
code and documentation. For this assignment, we are going
to build upon Spencer DeBuf's Battleship code from the first
CS 221 programming assignment.
Starting Code Base
Requirements and Grading
Note: 105 points are available, so 5 points of extra credit
are possible.
Functionality Changes
- 10 points. Once a square has been clicked on, clicking on it again
should not result in the number of guesses being incremented.
- 10 points. At the start of the game, the InfoPanel allows the user
to choose whether the game of Battleship should take place on an 8 by 8
grid or a 10 by 10 grid.
- 15 points. In the provided code, a separate JFrame pops up
at the end of the game that asks if the user would like to play
another game. Incorporate this
functionality into the InfoPanel instead.
Class Design Change
- 20 points. In the current design, the logic of the battleship game
and how it is displayed is all incorporated into the BattleshipFrame class.
Divide up the solution so that the display information appears in one
or more classes and the Battleship game appears in one or more
separate classes.
This has the advantage of making the Battleship game reusable in
a different context (such as a text-based interface).
Code Changes
- 5 points. In the main method of the PlayGame class, the only
statement that should appear is the call to the BattleshipFrame
constructor.
- 10 points. Through all of the files, make sure that instance
variables (1) include an access modifier (such as private),
(2) include a one line comment starting with // that appears to
the right of the declaration,
(3) do not include the modifier static, if this is unnecessary and
(4) are necessary as instance variables and not local variables.
- 5 points. The paintComponent method in the
InfoPanel class is generalized.
- 5 points. Through all of the files, constants are used where
appropriate.
- 5 points. The constructor in the BattleshipFrame class appears
directly after the instance variable declarations.
- 5 points. In the BattleshipFrame class, all initializations
of instance variables are done in methods and not when the instance
variable is declared.
- 5 points. In the BattleshipFrame class, generalize the actionPerformed
method that appears in the ButtonPressed inner class.
- 5 points. In the BattleshipFrame class, the checkForGameOver
method is not very efficient. Make it more efficient.
- 5 points. In the BattleshipFrame class, the populateBoard method
contains lots of redundancy. Eliminate this redundancy.
What to Submit
E-mail your code to your lab TA in one message.
The subject of the message
should be: CS221-xx program2 your-names.
The xx is the number of your lab section.
Your lab TA must receive your e-mail by the start of your lab period
on the date on which the assignment is due. Otherwise there
will be a 25 point per day late penalty.