Battleboat is a probability-based boardgame that challenges the user to locate enemy boats hidden
on a rectangular grid. The purpose of the game is to locate and destroy every enemy boat in the
least number of guesses.You will be modelling this game in Java. You must implement every part of the description
below. This means you must follow and specified modifiers and signatures exactly as
they are specified. Examples of changes that could lose you points: changing a variable to public
when it is listed as private, changing the return type of a function, etc.Your code will also be judged based on style. This should not be a stressful requirement – it simply
means that you must create logically organized, well-named and well-commented code so the TAs
can grade it.IMPORTANT: You cannot import anything to help you complete this project. The only
exception is importing Scanner to handle the I/O. Note that you do not have to explicitly
import Math because Java already does it for you. In other words, you can use Math methods
without importing MathNote: Writing useful helper methods for the functions listed above is allowed and encouraged!
Remember part of your grade comes from style and readability of the code you write.Note: You will find it useful to write your own tests to prove to yourself that your code
works. Please include any test classes you write with your submission.The Battleboats game board is composed of many cells. You are required to create a Cell class
that contains the following private attributes:• private int row: indicates the row value of the Cell
• private int col: indicates the column value of the Cell
• private char status: character indicating the status of the Cell. There are four different
possibilities for this field:Character Conditions
’ ’ (space) Has not been guessed, no boat present
’B’ Has not been guessed, boat present
’H’ Has been guessed, boat present
’M’ Has been guessed, no boat present
In addition, you are required to implement the following functions:
• public char get_status(): getter method for status attribute
• public void set_status(char c): setter method for status attribute
• public Cell(int row, int col, char status): Cell class constructorA Battleboat object will have the following attributes:
• private int size: indicates the number of Cell objects a Battleboat spans. Default this
value to 3
• private boolean orientation: indicates the orientation of the Battleboat (horizontal or
vertical, can be randomly decided)• private Cell[] spaces: array of the Cell objects associated with the Battleboat
And the following functions:
• public boolean get_orientation(): getter method for orientation attribute
• public boolean get_size(): setter method for size attribute
• public boolean get_spaces(): setter method for spaces attribute
• public Battleboat(): Battleboat class constructor
Hint: To generate random numbers, the Math.random() method can be used. However, this
method returns a double in the range 0 to 1. We will need to scale this and then round it to
a whole. To do this, use the Math.floor(x) function, which takes a double x and rounds
it down to the nearest integer. For example, Math.floor(2.9) is 2.The computer will simulate a rectangular m × n board. A Board object will contain the following:• private int num_rows: indicates the number of rows a Board has
• private int num_columns: indicates the number of columns a Board has
• private int num_boats: indicates the number of Battleboat objects a Board has
• private Battleboat[] boats: array of all the Battleboat objects associated with a Board
object• private Cell[][] board: 2-dimensional Cell array required to represent the Board
• private boolean debugMode: flag to indicate if Board should be printed in debugMode
The minimum Board size is 3 × 3 and the maximum is 12 × 12. Assume that the points in the
Board range from (0, 0) to (m − 1, n − 1) inclusive.Each boat is represented by a line of consecutive squares on the board. Boats may not overlap
other boats, extend outside the game board, or be placed diagonally. They may be horizontal or
vertical. A boat is considered “sunk” when all the squares of the boat have been “hit” by the user.Examples: Valid coordinates for a boat of size 3 are {(0, 0),(0, 1),(0, 2)} and
{(1, 1),(2, 1),(3, 1)}. Examples of invalid coordinates are {(0, 0),(0, 1)}, which is invalid
because there are not enough points. {(0, 0),(0, 2),(0, 3)} is invalid because the points are
not consecutive. {(−1, 0),(0, 0),(1, 0)} is invalid because the first coordinate is out of bounds.
Finally, two boats cannot contain the same point because they cannot overlap.After the gameboard has been sized, the program should place boats randomly on the
board. This requires randomly generating a coordinate (x, y) where the boat will be placed as well
as randomly choosing whether the boat should be horizontal or vertical. The quantity of boats is
defined by the width and height of the game board. As mentioned prior, all boats should be of
length 3. Recall the smallestBoardis 3 × 3 and the largestBoardis 12 × 12.Smallest Dimension Boat Quantity
width == 3 or height == 3 1
3 < width <= 5 or 3 < height <= 5 2
5 < width <= 7 or 5 < height <= 7 3
7 < width <= 9 or 7 < height <= 9 4
9 < width <= 12 or 9 < height <= 12 6Use the table above to determine how many boats to place. Recall that the Board may be rectangular, so a Board that is 9 × 3 should have just one boat of length 3 (the first case). The user
should be told how many boats are on the Board when the game begins.Hint: To randomly place a boat, consider the coordinate in the upper left. If the upper left
corner was (0, 0), consider how the boat looks if it is horizontal or vertical. What upper left
corner coordinates are invalid? The placing of the boats may be the most challenging aspect
of this project: see what assumptions you can make to simplify it.• public Board(int m , int n, boolean debugMode): constructor for theBoardclass. This
method should assign appropriate number of boats to num_boats variable, initialize theBoard
as a 2-D Cell array, initialize boats as a Battleboat array, place Battleboat objects appropriately on the Board, and add them to the board’s boats• public int guess(int r, int c): returns an int based on the guess for the cell. The
statuses of the Cell must also be changed according reflect the statuses from the table in the
Cell class portion of this writeup• public int unsunkBoats(): calculates the number of unsunk boats on the Board
4 The main method and debug mode
A main method is provided to you in the Game class which will run the game once all the functions
are implemented as specified. If the debugMode flag is set to false, the view of the board will be
obscured during play so that the player only sees the spots they have already guessed. Setting
debugMode to true may be helpful to you while debugging and testing your code.
5
1, 1933, Battleboats, CSCI, Game, Project
[SOLVED] Csci 1933 project 1 battleboats game
$25
File Name: Csci_1933_project_1_battleboats_game.zip
File Size: 339.12 KB
Only logged in customers who have purchased this product may leave a review.
Reviews
There are no reviews yet.