QuestionQuestion

Battleship
In this assignment you're going to implement the game Battleship according to the according to the 2002 Hasbro rules with one player controlled by you (the human) and the other by the computer (AI).
Traditionally, you would play this game with two human players. The players both place their own ships on a map that the opponent cannot see. The players then take turns guessing where the other player's ships are located, and the goal is to sink all of the opponent's ships by firing at them until all the positions covered by the ships have been hit. You can see an exciting video of the game here, (and laugh at the Dutch language!) or in English here. These days, you can even play Battleship against strangers on the internet here. Note that the rules of this implementation are different from the rules you should use.

You're going to create a program for playing Battleship. You decide yourself how to create the user interface, how to organize the code, what abstractions to use, and what to name classes, interfaces etc. You've received an empty Java project in which you should implement the game. Other than that, it's up to you how to develop the game.
The program
The goal of the assignment is to create a working implementation of Battleship, where a human controls one side and the computer (an AI) controls the other side. The requirements are:
• The game is playable according to the traditional rules for Battleship: 2002 Hasbro rules
• The game has a user interface that displays the necessary information to the user (where the ships are, where the player and AI have fired previously, showing if someone has won) and allows the user to input moves. The user interface can be either text based, using e.g., System.out.println and a Scanner object, or a graphical user interface that can be controlled by clicking.
• You've implemented a computer (AI) player. The AI player doesn't have to be very intelligent. It's sufficient to have it make random valid moves.
• Your code clearly shows how you've used object-oriented programming to create an abstraction of the real physical game using good classnames, interfaces, method names, field variables etc. Please carefully describe how these things fit together in “Progress Report”.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

import java.util.Random;

/*
* ComputerPlayer class
*/
public class ComputerPlayer extends Player {

private Random rand;

/*
* Constructor
* @param name of computer player
*/
public ComputerPlayer(String name) {
super(name);
this.rand = new Random();
}

/*
* Method to place ships
* (non-Javadoc)
* @see Player#placeShips()
*/
public void placeShips() {
System.out.println("\nPlacing " + getName() + " ships automatically...");
for (Ship ship: Ship.values()) {
while (true) {
String columnString = Coordinate.convertColumnToString(this.rand.nextInt(Game.WIDTH));
String rowString = "" + this.rand.nextInt(Game.HEIGHT);
String orientation = "H";
if (this.rand.nextBoolean())
orientation = "V";
Coordinate coordinate = new Coordinate(columnString, rowString);
if (placeShip(ship, coordinate, orientation.equals("H"))) {
//System.out.println(getName() + " places " + ship + " at " + coordinate + ".");
break;
}
}
}
}

/*
* Method to make move on other player
* @param o other player
* (non-Javadoc)
* @see Player#makeMove(Player)
*/
public void makeMove(Player o) {
System.out.println("\n" + getName() + "'s Move...");
while (true) {
String columnString = Coordinate.convertColumnToString(this.rand.nextInt...

By purchasing this solution you'll be able to access the following files:
Solution.pdf and Solution.zip.

$301.50
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available Java Programming Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats