CMSC 202 Project 2
Assigned Monday, Sept 24
Program Due 10:00AM Wed Oct 3
Design Due 10:00AM Sunday, Sept 30
Updates 29 Sept
  • The path for Mr. Frey's public directory was not correct in the original description. The correct path is /afs/umbc.edu/users/f/r/frey/pub/CMSC202/Proj2.
    The original path was missing "pub"
27 Sept
  • So that there is absolutely no issue with Ships being hit in the same square more than once, the GUI ignores multiple attacks on the same square, so your Ship will never have to deal with this situation.
25 Sept
  • All classes for Project 2 should be included in a package named proj2
  • Question #3 from the p2design.txt file has been removed.
    Since the attack method is limited to returning HIT, MISS, or SUNK there really is no design decision. A hit is a hit even if it's on a previous square. Similarly, if a ship is sunk and then hit again, the attack method really has no choice but to return SUNK.
    This is a "protoype" so we're looking much more to see that things work properly when the game is played correctly.
Weight 7%

Objectives


Project Description
As an employee of the F & R Game Company you have been assigned to the programming team which is developing a prototype of an electronic version of the board game "BattleShip". The board game is played by two players who try to sink each other's battleships, destroyers, and submarines. The player who sinks his opponent's ships first wins. The game begins with each player secretly placing their ships on a rectangular "ocean" that only he can see. The players then take turns attacking their opponent by specifying grid coordinates. The player being attacked announces whether the attack was a "miss", a "hit", or that their ship was "sunk".

The electronic version of the game is for one player who attacks ships placed in the "ocean" by your program. The "ocean" is actually a 2-dimensional grid of squares, identified by row and column coordinates (numbered from zero). The game determines whether each attack by the player was a miss, hit, or sunk a ship. Statistics are also kept and reported to the player on demand. Different players may take turns playing against your program to determine who uses the fewest number of attacks to sink the ships.

Since the F & R Game Company uses object-oriented designa and programming, it's possible to divide the game development work among several programmers. Once the programmers agree on the objects which make up the game and decided upon the methods each object will provide (along with the method signatures), the programmers can develop and test their classes separately. When all classes have been tested, they can be integrated into the final program. To keep your game development under wraps, F & R have given it the codename "Project 2".

After careful deliberation, you and your colleagues have decided on the following classes and methods for those classes. You have been assigned to design, implement, and test the Ship class and GameStats class. Someone else will implement the "Project 2" class which will contain main that executes and controls the game.


Project Policy
This project is considered an OPEN project. This means
  1. You should try as much as possible to complete the project by yourself.
  2. You may get assistance from anyone -- TAs, instructors, fellow students, relatives, friends, etc.
  3. You must document all outside help you get as part of your file header comment.
This DOES NOT mean
  1. that you may copy anyone else's code
  2. have someone else write your code for you
  3. submit someone else's code as your own
Such offenses are violations of the student code of academic conduct.
Class Descriptions
The descriptions of the Ship and GameStats class are given below, and also in JavaDoc format. Be sure to read the JavaDoc as well as the description below. Future class descriptions may be provided only in JavaDoc format. In the unlikely event that there is a discrepancy between this description and the JavaDoc pages this description should be considered correct.
Ship class
The Ship class models one of the ships that the player is trying to sink. The operations defined for the Ship class are
  1. Ship( String name, int orientation, int size, int row, int column) -- the Ship class constructor where
    1. name is a string such as "Battleship", "Submarine", etc.
    2. orientation is either VERTICAL or HORIZONTAL, which are constants defined by the Ship class
    3. size is the length of the ship (number of squares it occupies in the "ocean")
    4. row and column are the coordinates of the "top" end of a vertically oriented Ship, or the "left" end of a horizontally oriented ship
  2. int attack( int row, int column ) where
    1. row and column represent the coordinates being attacked
    This method returns one of HIT, MISS, or SUNK, which are constants defined in the Ship class.
  3. String getName( ) which returns the string representing the name of ship.
GameStats Class
This class collects are reports meaningful game statistics. This class keeps track of the number of attacks, the number of misses, the number of hits, the number of ships sunk, the percentage of attacks that hit (or sink) a ship, and the number of ships left to sink. The operations defined for the GameStats class are
  1. GameStats( int nrShips ) where nrShips is the initial number of ships in the ocean.
  2. void update( int attackResult ) where attackResult is one of HIT, MISS, or SUNK which are constants defined in the Ship class. This method updates the appropriate statistics for the specifed result of the an attack.
  3. String toString( ) - this method returns a multi-line String that is the report of all game statistics. Use the new-line character (\n) to create a multiple lines.
Project 2 class
The GUI framework and the project's main are being written by someone else. When complete, you will be given the Project2.java file to complete your program. To integrate this file into your projects, see the Importing Files into Eclipse resource page.

This class comes with three ships (1 BattleShip, 1 Destroyer, and 1 Submarine ) already in the ocean to allow you to test your code. The Project 2 method createShips creates and places ships on the playing grid. Feel free to modify this method to change the location and/or orientation of the ships, or to add or remove ships per the method comments to further test your code.

Note that different versions of createShips will be used to grade your project, so it is not necessary to submit Project2.java and if submitted it will be removed prior to grading.

Implementation Requirements
Your class implementation must adhere to the following requirements
  1. Follow course coding standards
  2. Per the Java compiler requirements, your source files must be named after your class names. E.g. the Ship class must be found in the file Ship.java
  3. For each class, your must write your own main which tests each method of your class.

Hints and Tips

Project Design Assignment
For this project design assignment, copy the file p2design.txt from Mr. Frey's public directory, then edit the file to answer the questions. Submit p2design.txt in the usual way: submit cs202 Proj2 p2design.txt Remember - the design is due before the project. See the design due date at the top of this page. Late designs will not be accepted.
Grading

The grade for this project will be broken down as follows. A more detailed breakdown will be provided in the grade form you receive with your project grade.

10% - Project Design
Copy p2design.txt from Mr. Frey's public directory and edit the file to answer the questions. Be sure to submit this file by its due date.
80% - Correctness
This list may not be comprehensive, but everything on this list will be verified by the graders.
10% - Coding Standards
Your code adheres to the CMSC 202 coding standards as discussed and reviewed in class.
In particular, pay particular attention to the list below. Graders will check all applicable items in the coding standards.
  1. Your file header comments
  2. Your method header comments (particularly pre- and post-conditions)
  3. Method and variable names
  4. In-line comments
  5. Code readability
  6. Limiting variable scope
  7. Class method names
  8. Class instance variable names

Project Submission
  1. submit Ship.java, GameStats.java, and p2design.txt
  2. submitls to verify they are in the remote directory
  3. DO NOT submit Project2.java
Assuming you've used the recommended file names, then to submit your project, type the command submit cs202 Proj2 Ship.java GameStats.java The order in which the files are listed doesn't matter. However, you must make sure that all files necessary to compile and run your project are submitted. You need not submit all files at the same time. You may resubmit your files as often as you like, but only the last submittal will be graded and will be used to determine if your project is late. For more information, see the projects page on the course website.

You can check to see what files you have submitted by typing

submitls cs202 Proj2 More complete documentation for submit and related commands can be found here.

Remember -- if you make any change to your program, no matter how insignificant it may seem, you should recompile and retest your program before submitting it. Even the smallest typo can cause compiler errors and a reduction in your grade.

Avoid unpleasant surprises!