Program 1

Battleship

due Thursday, February 2nd by the start of lab

Lab Partners

Everyone is encouraged to work with one lab partner (who is in the same lab section as yourself) on this assignment. If you do work with a partner, submit one solution with both of your names on it. Also, please look at the class collaboration policy so that you know what is and what isn't allowed.

General Overview

We are going to implement a simplified version of the classic game of Battleship. The game will be played on a graphical Java application.

Objectives

The goal of this assignment is to give you experience designing a graphical user interface with Java. Furthermore, you will learn about event-oriented programming.

Game Requirements

  1. The game is played on an 8 by 8 grid.
  2. A minesweeper is a boat that occupies two consecutive horizontal or vertical squares.
  3. A frigate occupies three consecutive horizontal or vertical squares.
  4. A cruiser occupies four consecutive horizontal or vertical squares.
  5. A battleship occupies five consecutive horizontal or vertical squares.
  6. The computer randomly places one minesweeper, one frigate, one cruiser and one battleship on the grid at the beginning of the game.
  7. The ships may not overlap at all.
  8. The game displays how many guesses the player has made.
  9. The game visually distinguishes among unguessed squares, guessed squares that were misses, guessed squares that were part of a minesweeper, guessed squares that were part of a frigate, guessed squares that were part of a cruiser and guessed squares that were part of a battleship.
  10. The game is over, when the user has identified all parts of all ships.
  11. At the end of the game, the user is asked whether he or she would like to play again. If the answer is no, the application should end and the display should disappear. If the answer is yes, a new random placement of ships should be generated and an empty board (with 0 guesses) should be displayed.

Note: You are welcome to go beyond this minimal set of requirements if you would like to produce a more professional version of Battleship.

Grading

What to Submit

E-mail your code to your lab TA in one message. The subject of the message should be: CS221-xx program1 your-names. The xx is the number of your lab section. Your lab TA must receive your e-mail by the start of your lab period on the date on which the assignment is due. Otherwise there will be a 25 point per day late penalty.