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
- To gain experience designing, coding, and testing classes
including accessors, mutators, constructors, constants,
and proper declaration of public/private methods and data
- To gain experience using objects in a simple application
- To appreciate the value of writing reusable and easily modifiable code
- To become familiar with standard Java documentation
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
- You should try as much as possible to complete the project by yourself.
- You may get assistance from anyone -- TAs, instructors, fellow students, relatives, friends, etc.
- You must document all outside help you get as part of your file header comment.
This DOES NOT mean
- that you may copy anyone else's code
- have someone else write your code for you
- 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
- Ship( String name, int orientation, int size, int row, int column) -- the Ship
class constructor where
- name is a string such as "Battleship", "Submarine", etc.
- orientation is either VERTICAL or HORIZONTAL, which are constants defined by the
Ship class
- size is the length of the ship (number of squares it occupies in the "ocean")
- row and column are the coordinates of the "top" end of a vertically oriented Ship, or the "left" end of a horizontally oriented ship
- int attack( int row, int column ) where
- 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.
- 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
- GameStats( int nrShips ) where nrShips is the
initial number of ships in the ocean.
- 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.
- 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
- Follow course coding standards
- 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
- For each class, your must write your own main which tests each method of your class.
Hints and Tips
- Develop your classes slowly. As you write new methods, write code in your class' main to test them.
- Add about 5 lines of code in each iteration. Save, compile, run, test.
- Write the toString method for each class. If it's not required
it can be used as a debugging tool to print the values of instance variables or other important information.
- Add precondition checking to each of your methods last. Save, compile.
- DO NOT try and implement an ENTIRE class at once - you will spend more
time debugging and correcting your errors than if you develop testing
applications and test each method as you develop it.
- TEST your program thoroughly
- Use incremental development, develop one method at a time, write code
that will thoroughly test it, run and test it, then move on to another method.
- This project is approximately 100 - 150 lines of code... don't procrastinate.
- Mr. Frey's public directory for this project is
/afs/umbc.edu/users/f/r/frey/CMSC202/Proj2.
Project2.java will eventually
be placed there so that you may import it into Eclipse.
- Do not cheat, you will be caught. Do not look at another student's code -
it is very tempting to "borrow" an algorithm. Do not show your code to
another student. Use the Tutors, TA's, and Instructors.
- This is a GUI-based project. Therefore to test your code once you've moved it
to your GL account, you must use a Linux machine in one of the labs to run it.
You will not be able to run your program on GL from home.
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.
- Your project produces all required output.
- The output produced is correct.
- The output is in an acceptable format.
- All project requirements are met.
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.
- Your file header comments
- Your method header comments (particularly pre- and post-conditions)
- Method and variable names
- In-line comments
- Code readability
- Limiting variable scope
- Class method names
- Class instance variable names
Project Submission
- submit Ship.java, GameStats.java, and p2design.txt
- submitls to verify they are in the remote directory
- 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!