Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

This is a group project requiring us to make a battleship game (instructions bel

ID: 3862468 • Letter: T

Question

This is a group project requiring us to make a battleship game (instructions below). We have one group member coding a ship object, another coding the UI Board, another coding the AI and I have to code the ocean object/board. The information I have on the ocean board is as follows: Ocean object/board = contains ships - private ship grid (8x8 grid) The methods it should have are: addShip method, fireAtCoordinate method (returns boolean to check if a hit or miss), scanCoord method (returns whatever is in coordinate). Please write the code for the ocean board class. *I am using JGrasp so please make sure it is compatible *Please comment throughout code

9. One-player Battleship Game On an 8 x 8 grid allow a player to choose locations for 3 boat objects (one of length 2, one of length 3, one of length 4) and have the computer randomly do the same thing (make sure they all fit on the grid. Alternate turns between the human player and the computer and when a battleship is sunk print "You Sunk my Battleship! the game is over when all three of one players ships are sunk. The computer could just use the Math rand function to guess a place to attack but you can also make it smarter by keeping an array of points where it scored a hit and then adding to that. More information here: http://en. wikipedia.org/wiki/Battleship (game)

Explanation / Answer

import java.util.Random; import java.util.Scanner; public class battleShip { public static void main(String[] args) { int[][] board = new int[8][8]; int[][] ships = new int[3][2]; int[] shoot = new int[2]; int attempts=0, shotHit=0; initBoard(board); initShips(ships); System.out.println(); do{ showBoard(board); shoot(shoot); attempts++; if(hit(shoot,ships)){ hint(shoot,ships,attempts); shotHit++; } else hint(shoot,ships,attempts); changeboard(shoot,ships,board); }while(shotHit!=3); System.out.println(" Battleship Java game finished! You hit 3 ships in "+attempts+" attempts"); showBoard(board); } public static void initBoard(int[][] board){ for(int row=0 ; row < 5 ; row++ ) for(int column=0 ; column < 5 ; column++ ) board[row][column]=-1; } public static void showBoard(int[][] board){ System.out.println(" 1 2 3 4 5"); System.out.println(); for(int row=0 ; row < 5 ; row++ ){ System.out.print((row+1)+""); for(int column=0 ; column < 5 ; column++ ){ if(board[row][column]==-1){ System.out.print(" "+"~"); }else if(board[row][column]==0){ System.out.print(" "+"*"); }else if(board[row][column]==1){ System.out.print(" "+"X"); } } System.out.println(); } } public static void initShips(int[][] ships){ Random random = new Random(); for(int ship=0 ; ship < 3 ; ship++){ ships[ship][0]=random.nextInt(5); ships[ship][1]=random.nextInt(5); //let's check if that shot was already tried //if it was, just finish the do...while when a new pair was randomly selected for(int last=0 ; last
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote