Question
Implement a java Battleship game using Object Oriented programming, it should include these different classes and their attributes: Carrier.java - ships of size 5, various
Implement a java Battleship game using Object Oriented programming, it should include these different classes and their attributes: Carrier.java - ships of size 5, various methods (e.g. to move, randomize positions), create 2 new Carrier objects for the 2 players, Battleship.java - ships of size 4, various methods (e.g. to move, randomize positions), create 2 new Battleship objects for the 2 players, Cruiser.java - ships of size 3, various methods (e.g. to move, randomize positions), create 2 new Cruiser objects for the 2 players, Submarine.java - ships of size 3, various methods (e.g. to move, randomize positions), create 2 new Submarine objects for the 2 players, Destroyer.java - ships of size 2, various methods (e.g. to move, randomize positions), create 2 new Destroyer objects for the 2 players, Grid.java - A 10x10 grid represented by a String array (with indexes of 0 - 99), various methods (e.g. to change the String value after player's turn.), by default; all values start with a '~' to represent empty water. A space ' ' represents a miss and 'O' represents a hit (e.g. grid[0] = "~";) the grid is to be read from left to right (see screenshot below) Player.java - create 2 Player objects, various methods (e.g. to keep total total wins, for each player, name. By default, playing against a CPU opponent. The CPU's name will always be 'Computer'), random move methods must be implemented (in case user wants to play with a CPU) BattleshipDemo.java - The main class must contain an option for players to play against a 2nd player or a CPU. Various methods (print methods e.g. print array, error messages when out of bounds, etc) Notes: - Regular battleship rules apply: see https://en.wikipedia.org/wiki/Battleship_(game) - Players alternate turns, deciding on who gets first turn is by random. - When playing against a CPU, CPU's display will always be "Computer" - Ships could be only horizontal and vertical, and should not overlap For a general idea see the sample output:
Battleship!! Type 1 to play against another player Type 2 to play against a computer Type 3 to quit: 4 Errorl Please enter a number from 1-3:9 Error! Please enter number from 1-3: 8 Errorl Please enter a number fron 1-3: 1 2-Player Mode Selected Enter player 1's nane: Test Enter player 2's nane: Dumy //Randonize who gets first turn Ounmy's turnl Test's Grid Type the corresponding number to attack the grid, otherwise type 100, to quit: 11 Missed Test's Grid 01 2 3 4 5 6 7 89 Test's Turnl Dunmy's Grid Type the corresponding number to attack the grid, otherwise type 180 to quit: -9 Error: Please input a valid position ( - 99), otherwise type 180 to quit: 181 Error: Please input a valid position ( 99), otherwise type 180 to quit: 99 Sucessful hit! Dunmy's Grid Dunny's Turn: Test's Grid Type the corresponding number to attack the grid, otherwise type '180 to quit: 11 You have already chosen this value! Error: Please input a valid position ( 99), otherwise type 180 to quit: 8 Missed! Test's Grid 0 1 2 3 4 5 6 7 8 9 Test's turn: Dunmy's Grid Type the corresponding number to attack the grid, otherwise type 180" to quit: 89 Succes ful hit! Dunmy's Destroyer sinks Dummy"s Grid /fa few turns pass by Dunmy's Grid 01 2 3 4 5 6 7 89 00 0 o Test wins Stats: Games won for Test: 1 Ganes won for Dummy: e Type 1 to play another game Type 2 to quit. 5 Invalid input Type 1 to play another game Type 2 to quit. 2 Thank you for playingStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started