MVC, Lazy Initialization, Factory Methods: Battleship Lab


If you are unfamiliar with the game of Battleship, watch this video:

Lab Description

In this lab, you will construct half of the battleship game. You will get the computer to generate a random pattern of ships on a grid that the user cannot see.
The user will enter coordinate pairs while the computer will respond with one of three responses:
  1. Hit
  2. Miss
  3. You sunk my battleship
The grid of 10 x 10 coordinates need to be displayed as buttons using  a GUI (javafx). When the user presses a button, it should turn red to indicate a hit or  green to indicate a miss. When an entire ship is sunk, the corresponding buttons should turn black. The computer must also inform the player when all ships have been sunk such that the game is over. The computer does NOT need to keep track of the number of user misses as the game always continues until the user wins.

Lab Internals

You must use an MVC architectural model for this lab. Use lazy initialization (static factory methods) and do not create any coordinates until they are first needed. Each coordinate should consist of two integers (x,y) with x and y in the range [0,9]. Each coordinate should have a state and a corresponding color associated with it. The possible states for a coordinate should be (UNKNOWN, HIT, MISS, SUNK). If in state UNKNOWN, the color should be grey. In state HIT, the color should be red. If the state is MISS, the color should be green. If SUNK, the color should be black. Once created, reuse coordinates wherever possible. Even though these objects are mutable (since they have state), we can still cache them since our program has only one thread.