CS Department, Fall 1997, Java Programming
Battleship: stage 1
Your first task is to design the overall structure of your program. I advise you to follow the simple methodology I outlined in class, where you will end up with a basic structure, at least. The design should be a number of classes, their members and the names of essential methods. At this point the methods can all have empty bodies. The design is not set in stone. Indeed, it is very common to rethink a design many times during the course of a project. Try to keep track of all your design decisions. I very often will keep a journal in which I record all of these thoughts, the preliminary design, and the changes to it. Your Battleship program should be a standalone program (with a main method), not an applet.
Your first task after basic design is to develop the visual appearance of your game. You will need to show two 10 X 10 squares, one containing your fleet and the other to record the hits and misses on you opponent's fleet. This will be the computer at first, and later another program running on another machine. Some experimentation may be needed to get a good size, and to choose good colors. Your aim should be to display the initial setup of the two fields. You can "hard-code" the positioning of the fleet, but at least you need to think about the appearance of the ships. They need not be bitmaps (Images, in Java terms); instead they could be drawn using basic drawing operations. The classes you need to look at are (at least):
Frame--the window to hold the two fields
Canvas--each field can be a canvas (perhaps a 2-D array of Canvases?)
Image--a ship might be a bitmap, or perhaps a number of "primitive" bitmaps; you will need to create the bitmaps using some graphics program and then load them into your Java program
Graphics--for the drawing functions, fonts and colors
Look at the relevant sections of the textbook as well as the class library documentation. Chapter 18, "Using Components" and chapter 20 "Working with graphics" are the relevant parts of the textbook.
If you feel lost, start by copying code out of the textbook, and modify it to do what you want.