Battleship ~ Mohammad Daraghmeh (Java)

Welcome, this is a two week Java based project with the purpose of creating a Graphical User Interface (GUI) for the single player game of classical battleship

Overview of Battleship

This is a simplified single player version of the popular board game, Battleship. Battleship is in two words is a guessing game. Even though it is a game of simple rules (fire/miss) it was surprisingly a great learning experience. In a nutshell, the object of the game is to sink all of the ships on the board.

In-Depth view of Battleship

As mentioned the objective of Battleship is to sink all of the ships on the board. With each click (turn), a player is given a grid and must decide where to fire on the grid. The result of this decision can either be that the spot fired on was a hit or miss. A hit being that part of a ship on the grid was hit or a miss being that water was at that spot. The standard setup of the game is for one player with unlimited turns and ammunition. When all ships on the board are sunk then the game is over and the player has won.

Language/Program Used

This project was written in Java using the Eclipse platform of course from stretch. What was to be learned from creating this project was the following:

  • To apply the Model-View-Control (MVC) design pattern to a specific application.

Note on MVC : I believe MVC is the perfect harmony between the user interface and the model. For in this project my GUI and Model were differently separated yet worked hand in hand to accomplish a fully functional battleship game. However, it does not stop there for the same method of MVC is applied in the world of engineering in form of Model,User Interface, and Controller. Luckily for me I learned MVC in two courses at the same time (Object-Oriented Design and Digital System Design 2).

  • Greater knowledge of object-oriented design and inheritance/interface design skills.
  • Gain experience using Java's "Swing" GUI classes
  • Gain experience with event driven programming

Project Design Approach

A separation of the model (game functionality) from the view and controller (GUI) as much as possible following the design pattern of MVC. When exploring my source code you will be able to see this clear separation (BattleShipGUI/BattleShipModel).

Line Break

Game Setup/Rules

~ One board with "X" of squares. Ex: (4 by 4)

~ At least one ship on the board.

Ship Rules ### Program performs a check for all rules below.

~ All orientation of the ships must be either horizontal or vertical (no diagonals).

~ Ship locations must be completely within the boundaries of the specified board.

~ No ships can overlap.

Input File Format

~ File must be in the format of a text file.

Breakdown of Format

Input Format

This example is a 6x6 board with the first ship a 2-section horizontal ship in the second row starting in the second position from the left. The second ship a 6-section ship that completely occupies the rightmost column of the board.

End Game

Player has successfully sunk all ships on the board and GUI has produced the message "XXX" (Fig. 7)

Time of Game

From 1 to 5 minutes.

Line Break