-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
40 lines (40 loc) · 1.18 KB
/
Copy pathPlayer.java
File metadata and controls
40 lines (40 loc) · 1.18 KB
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
import java.util.Scanner;
public class Player {
String name;
int score;
public Player(String name){
this.name= name;
}
public boolean play(MineField minefield){
Scanner scanner = new Scanner(System.in);
System.out.println("Enter row");
int row = scanner.nextInt();
System.out.println("Enter column");
int col = scanner.nextInt();
Cell cell =minefield.getCell(row,col);
while(cell.is_Open()){
System.out.println("Invalid input please enter a closed cell coordinates");
System.out.println(" Enter row");
row = scanner.nextInt();
System.out.println("Enter column");
col = scanner.nextInt();
cell =minefield.getCell(row,col);
}
cell.open();
if(cell.has_mine()){
System.out.println(this.name+" has found a mine");
this.score+=1;
return true;
}
return false;
}
public void printStatus(){
System.out.println(this.name+" score:"+this.score);
}
public String getName(){
return this.name;
}
public int getScore(){
return this.score;
}
}