-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBattleshipTester.java
51 lines (36 loc) · 1.13 KB
/
BattleshipTester.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
/*
Written by: Maeve Carr
Date:
Desc:
Filename:
*/
/////YOU WILL NOT NEED THIS CODE - BUT HAVE INCLUDED IT FOR TESTING
/////no proper error checking..
import java.util.*;
public class BattleshipTester
{
public static void main(String[] args)
{
Scanner keyIn = new Scanner(System.in);
BattleshipsGame myGame = new BattleshipsGame();
// myGame.setNoOfShips(6);
System.out.println();
//just so I can see where ships are - for testing
myGame.showGrid();
do{
System.out.print("Enter location\n\tRow: ");
int row = keyIn.nextInt(); // should validate input here so value between 0 and 3
System.out.print("\tColumn: ");
int col = keyIn.nextInt();
String message = myGame.shoot(row, col);
System.out.println(message);
// System.out.println("No of ships hit: " +myGame.getHits()); //for testing
}while(myGame.getLives() > 0 && myGame.getHits() < 6);
if(myGame.getLives() == 0)
System.out.print("Sorry - you lose ");
else
System.out.print("WELL DONE - YOU WIN! ");
System.out.println();
myGame.showGrid();
}
}