hey guys i got this new project for my java class and got the overall idea but my code still does not seem to work ...here are the directions:
- make a 5X5 boolean array assign 5 random elements for 5 ships
- user can have 15 guesses to find all 5 spots
- at end display remaining ships (if any) by location (ex. 2 1)
heres my code can u guys fix please i made the effort....
thanks
public static void battle()
{
EasyReader enter = new EasyReader();
boolean [][] grid = new boolean [5][5];
int guessRow, guessColumn, row, column, ships = 0, turns = 0;
do{
ships ++;
row = (int)Math.random() * grid.length;
column = (int)Math.random() * grid[0].length;
grid[row][column] = true;
}while (ships < 5);
do{
turns ++;
System.out.print("Enter the row ");
guessRow = enter.readInt();
System.out.print("Enter the column ");
guessColumn = enter.readInt();
if (grid[guessRow][guessColumn] == false)
System.out.println("miss");
else
{
ships --;
System.out.println("hit" + ships + " more left !");
}
}while(!(turns == 15 || ships == 0));
if (turns == 15)
{
for(int i = 0; true;i++) {
for(int j = 0; true;j++){
if (grid[row][column] == true)
System.out.print("You lost the remaning ships are at " + row + column);
} }
}
else if (ships == 0);
System.out.print("You won!");
}