Designing Battlecell

As stated in previous chapters, when designing a program, you need to consider the user interface and all inputs and outputs required by the program. The Battlecell program interface shown in Figure 5.16 is fairly simple, consisting of two 10 by 10 grids in which the user and computer must place their ships. The user will input ship and target selections via mouse clicks on worksheet cells. Clicking the Command Button control will initiate the game and an area of merged cells will serve as a message board to help the user know what to do. Other program inputs and outputs include help messages output to the worksheet and sound files that are played during the course of the game.

The user's ship grid

The Battlecell worksheet interface.

The user's ship grid

The Battlecell worksheet interface.

-The computer's ship grid

Merged cells for help messages

Command Button control for starting the game

-The computer's ship grid

Merged cells for help messages

Command Button control for starting the game

The program will require at least two modules, including the object modules for the Workbook and Worksheet objects containing the game. The object module for the Workbook object is required for its Open(), BeforeClose(), and WindowResize() events that will be used to satisfy the requirements for clearing, resizing, and resaving the workbook. The object module for the Worksheet object is needed for its SelectionChange() event that will satisfy the requirements for the user's selection of ship locations and targets. Standard modules may be used as well in order to better organize the code.

The Battlecell program's design is summarized in the following:

1. Format the worksheet with two 10 by 10 grids, merged cells for help messages, and a Command Button control. Use colors, borders, and large fonts to make the grids, merged cells and Command Button control stand out. Define names for the two grids and the merged cells in order to make the code that references these ranges easier to read.

2. Resize the workbook window via the Zoom property of the Window object (sub procedure). The workbook should automatically resize when the user opens the workbook file or resizes the workbook window (Open() and WindowResize() events of the Workbook object).

3. Clear the user's and computer's grids (sub procedure) of color and values, and save the workbook when the user closes the workbook file (BeforeClose() event of the Workbook object).

4. Initialize the game (sub procedure) when the user clicks the Command Button control (Click() event of the Command Button control).

5. Capture the user's selections for ship placement (SelectionChange() event of the Worksheet object) and color the selection light blue if valid (several custom sub procedures that validate the selection for the following: location within the user's grid, length, one row or one column, overlap with another ship). The validation procedures should return an error message if the user's selection is invalid.

6. Randomly generate locations for the computer's ships and mark them with an X after validation. This will require several sub procedures that generate the row and column indices for the computer's ships. The same sub procedures that validate the user's ship selections should also validate the randomly generated selections used for the computer's ships.

7. Capture the user's selections for targeting the computer's ships (SelectionChange() event of the Worksheet object) and color the validated target blue for a miss and red for a hit. The target must be validated for the following: location within the computer's grid, only one cell selected, and the target has not been previously selected. Use custom sub procedures that return an error message if the target is not validated.

8. Play a sound file if the user's target is valid.

9. Play another sound file (explosion) if the user scores a hit, and test for the end of the game. Play another sound file (specific for the user winning the game) if the game is over.

10. Immediately following the user's target selection, simulate the computer's return fire. Randomly generate a target (sub procedure) and color the validated target green for a miss and red for a hit. Validate the target using the same validation procedures used to validate the user's target.

11. If the computer scores a hit, then test for the end of the game and play another sound file (specific for the computer winning the game) if the game is over.

12. Re-enable the Command Button control and terminate the program when a winner is declared (sub procedure).

Biorhythm Awareness

Biorhythm Awareness

Who else wants to take advantage of biorhythm awareness to avoid premature death, escape life threatening diseases, eliminate most of your life altering mistakes and banish catastrophic events from your life.

Get My Free Ebook


Post a comment