Assignment 4
COMP 106



In this assignment, we will make some more fairly minor additions to Battleship, and finish with the 2-D version.

Mouse Interaction

In the previous assignment, users chose the location of their shot through the use of widgets. For this assignment, have the user choose the location of the shot by clicking on the desired location directly on the game board.

Computer AI

Design the computer to make more intelligent decisions than the hard coded or random ones in the previous assignment. For example, if the computer hits a ship, it shouldn't keep on firing randomly. Instead, it should act like a human - searching for which direction the rest of the ship is, and following that line until the ship is sunk. In addition, the computer should place its ships randomly at the start of each game. Be careful around the edges of the board.

More Features

To earn full credit, you will need to add a couple more features to the game. Here are some ideas, but feel free to be creative and come up with your own additions to gameplay:

In your readme file, be sure to write which features you chose to include . They can be from the above list or your own ideas. If you aren't sure about one, feel free to email us.

UML Diagram

For this assignment, also submit a UML diagram of your classes and the relationships among them. It should show the main classes in your system, inheritance relationships, and aggregation (containment) relationships -- and collaboration (uses) relationships if you can fit them in.

Don't worry about absolutely perfect UML syntax, since it varies.

Please submit your diagram in PDF if possible. It can be a PDF printout from a drawing program or a scan of a handwritten paper document (the copier in the CS department office can scan documents). If not, hardcopy is ok, put it in Ming Chow's mailbox or check with him about other formats.

Program Design and Practices

(The rest of this still applies from previous assignments)

Your program design should exploit the features of object-oriented programming (encapsulation of code and data, support for abstract data types, polymorphism/overloading, inheritance). In particular, object-oriented programming provides us a good way to handle the various data needed in callback routines. You should use objects to encapsulate each interactive widget with the routines and data you need to use it.

You should provide an object for each interactive widget or small group of widgets you create. That object should hold anything you need to remember about the widget from one callback to another, all the data pertinent only to the command for that widget or that you need to operate this control, (including, in most cases, a pointer to the graph or other outside object to perform the actual action the user requested), and the widget's own listener callback routines.

If you have several widgets that share some behavior or properties, you should organize your objects into an appropriate inheritance hierarchy.

You will have other data that must be accessed by several widgets, particularly shared information about the state of the program or global information about the state of the user interface. Provide additional classes and objects for holding this kind of information.

Remember to trigger your drawing to repaint itself explicitly whenever one of your commands causes a change in the state of the graph that should be reflected on the screen. And remember that the way to change the screen is first to change the data stored in the Graph or other classes and then to trigger the repaint.

You should follow these general Java programming practices:

And, finally, for uniformity please name your Java class that has your main program in it Main, in file Main.java

Design Documentation

In addition to your program, submit documentation about the design of your system in these forms:

Submit this documentation electronically in text form. Include it as part of the readme file that you submit with your assignment.

Grading