Internal Code : 1ABBJF
Battleship Game Assignment Help
Task:
Game rules
The Battleship game rules are quite well established. But it is expected that there are many variations that have been published. As such, the rules for the assignment are given here, and where there is a difference to any external rules, the assignment rules must be followed.
The aim of the game is to be the first player to sink your opponent’s fleet of ships. Each player’s fleet comprises of an Aircraft Carrier (length 5), a Battleship (length 4), a Cruiser (length 3), a Submarine (length 3), and a Destroyer (length 2). So, the fleet would amount to a length of 17 spaces if they were hypothetically placed in a straight line.
Each player secretly places their ships on their 10x10 grid in any positions they like. As pictured below, this is the flat grid, which we will refer to as the ocean
. There is a second upright grid for tracking the opponent. As also pictured below, this is the vertical grid, which we will refer to as the target
. The implementation of your Battleship Game will avoid some redundancy and have you manage two grids in memory rather than four.
The human player goes first, and each player takes turns to nominate a coordinate to “fire upon” the opponent’s fleet. The opponent must inform whether it was a hit or a miss. The location is marked as a hit
(red, we will use ‘x’) or a miss
(white, we will use ‘-’).
The game continues until the first player hits all spaces on all ships of the opponent. Both players always receive the same number of turns, so it is possible to have a draw.
Implementation in Java
The game will be implemented with text prompts, standard output, and an ASCII-art drawing to represent the game progress for the human
player. No such representation is needed for the artificial
player, as they are the opponent.
Initially when the game starts, there is a welcome message, an empty target
grid and automatically populated ocean grid for the human
player, and a prompt for the human
player to make their first guess. This is shown below:
The game proceeds with the human and artificial players making their guesses in an alternating fashion, until either player has hit all positions of all ships of the opponent. For example, the sample game shown below (after 7 turns have passed) suggests that the human
player might have made 3 hits against a length-3 ship, and the artificial
player has made one hit against a cruiser.
At the end, there will a message to either say “Player 1 won!”, “Player 2 won!”, or “It’s a draw!”. Then a final message will say “Thanks for playing!” before the program terminates.
Solution design
The solution will comprise of six classes spread across two packages as follows:
The “battleship model” package comprises of data classes (such as ships and coordinates) and lower-level logic (such as managing the ocean
of both players), whilst the “battleship game” package comprises of the driver class to execute the higher-level logic (such as placing ships and taking turns).
Note that the starter code
archive provided to you already has implementation for the solution structure and the Ship class above.
The following sections describe the classes in turn, generally from least to most significant
Ship class
Instance variables:

Constructors and methods:
Coordinate class
Instance variables:

Constructors and methods:
Player class
Instance variables:

Enumerations:

Constructors and methods:
HumanPlayer class
This class is an extension of the Player class. As such, all existing functionality is automatically inherited. This documentation lists additions and differences only.
Constructors and methods:
Artificial Player class
This class is an extension of the Player class. As such, all existing functionality is automatically inherited. This documentation lists additions and differences only.
Constructors and methods:
Battleship Game class
This class imports the “battleship model” package so that all those classes can be used by a single main() method to act as the driver for the whole program.
The main method performs the following steps:
- Create a new Human Player object called player 1.
- Create a new Artificial Player object called player 2.
- Print a welcome message “Welcome to the Battleship game.”.
- Print “Target grid (opponent):” then call the print Ocean(true) method of player 2.
- Print “Ocean grid (you):” then call the print Ocean(false) method of player 1.
- Create a loop to perform the following steps until the game ends: a. Print “Turn 1...” or equivalent for the turn number. b. Call the takeGuess() methods of both players. c. Perform steps 4 and 5 again. d. Determine if a player (or both players) has won or not and display an appropriate message.
- Print “Thanks for playing!”.
Implementation tips
So, what is the best way to get started? In general, you should focus on implementing, testing and running small sections at a time. Do not write a large amount of code, then expect it to all run on your first try!
In general, also be aware that some of the “junior” classes are there to help do the work of the “senior” classes. For example, the Player class is more “senior” than the Coordinate and Ship classes, because it relies on those to do some of its smaller jobs.
The below list is a suggested order for implementing the functionality of the assignment.
- Open the starter code bundle provided (see “Solution Design” above). It comprises of two packages, implementation of the Ship class and a placeholder for the remaining classes.
- Study the Ship class and the requirements for the Coordinate class first. These are the lowest-level classes, and the implementation for each component is mostly small. Consider which parts are needed for step (C) and implement those including the constructors first.
- Implement the Player constructor (omitting the place Fleet method initially until step E),the Player.printOcean() method and dependencies.
- Create a Player object in the Battleship Game class to test step (C). Check that the output is in the same format as the examples in this assignment specification.
- Partially implement the Player.placeFleet() method for one ship and test your work.
- Complete step (E) for all five of the ships and test your work again.
- Complete the HumanPlayer class next and test.
- Complete the Artificial Player class last and test.
- Test your final solution thoroughly.
If you find that any of the methods are particularly long, you are welcome to introduce additional “helper” methods.
Lodge a support request if you would like some guidance.
Tasks 1-4: UML
Create a complete UML class diagram in Visio 2016 for the Battleship Game. Marks will be awarded for the packages (Task 1), classes (Task 2), enumeration (Task 3) and relationships (Task 4). The marking rubric below gives more details about the components we are expecting.
Tasks 5-6: Pseudocode
Write a complete pseudocode for the contents of the Coordinate.printCoordinate() method (Task 5) and the contents of the Artificial Player.take Guess() method.
Task 7: Test data table
Pretend you are working with a different version of the Player.placeFleet() method that receives the details of any number of ships as input parameters, rather than generates them at random. The following data sets are provided comprising of the following fleets:
Note that the ships assume their normal lengths as per the game rules.
Create a test data table for the above data sets. Use the appropriate template from the “Documentation and testing templates” resource on the LMS. The “expected output” will always be a message with values such as “Fleet placed successfully” or “Fleet could not be placed: [problem description]”.
An example is given below for the first data set to get you started.
Task 8: Desk check table
Create a desk check table for the contents of the Player.place Fleet() method (from Task 10) under the following assumptions:
- The FLEET_SIZE is modified to 1.
- The fleet comprises of the Aircraft Carrier only (length = 5).
- The row for the ship is 4.
- The column for the ship is 2.
- The orientation for the ship is HORIZONTAL.
Use the appropriate template from the “Documentation and testing templates” resource on the LMS. The final column for “Input or output” may be omitted since this method is non-interactive. Consider using a landscape page orientation if you need more space.
Tasks 9-14: Implementation
Implement the Battleship Game program as a NetBeans 8.2 project using Java 8.
Your solution must also include the following general features:
- Error handling for user input.
- Consistent code indentation with one level of indentation per block.
- Code commenting for each class, all methods, and some inline comments.
This CSE1OFX: Battleship Game Assignment has been solved by our Java experts at My Uni Papers. Our Assignment Writing Experts are efficient to provide a fresh solution to this question. We are serving more than 10000+ Students in Australia, UK & US by helping them to score HD in their academics. Our Experts are well trained to follow all marking rubrics & referencing style.