-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
37 lines (32 loc) · 1.21 KB
/
Copy pathPlayer.java
File metadata and controls
37 lines (32 loc) · 1.21 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
import java.util.*;
public class Player {
public Set<String> totalMove = new TreeSet<>();
private Set<String> moveHistory = new TreeSet<String>();
private String playerName = "";
public Player(){
this.moveHistory = new TreeSet<>();
}
public void create(){
Scanner sc = new Scanner(System.in);
System.out.println("Enter the name of the player: ");
this.playerName = sc.nextLine();
}
public void storeHistory(String move){
moveHistory.add(move.toUpperCase());
totalMove.add(move.toUpperCase());
}
public boolean checkMoveValidity(String move,Character[] letters){
char[] m = move.toCharArray();
if(Arrays.asList(letters).contains(m[0]) && Character.getNumericValue(m[1])<=3 && Character.getNumericValue(m[1])>0 && Character.getNumericValue(m[1]) == (int)Character.getNumericValue(m[1])){
if(totalMove.contains(move) == false){
return false;
}else return true;
}else return true;
}
public boolean checkWin(String[] a) {
return moveHistory.containsAll(List.of(a));
}
public void winner(){
System.out.println(playerName +" won the game !!");
}
}