-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPlayer.java
100 lines (89 loc) · 1.65 KB
/
Player.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* @author Samuel Boulanger
* @author Cindy Ho
* @author Aldo Barrientos
* enum helps determine current player and tracks undos
*
*/
public enum Player
{
PLAYERA(0), PLAYERB(0);
/**
*
* helps track player undos in same turns
*
*/
enum TURNCHECK
{
JUSTWENT, FIRSTTURN,
};
private int undos;
private Player p;
private TURNCHECK turn;
private Player(int n){
undos = n;
}
/**
* prints the player
* @return string representation of enum
*/
public String toString(){ if (this == PLAYERA) {return "Player A";} else {return "Player B";}}
/**
* adds to the total undid count
*/
public void undid(){
this.undos++;
}
/**
* determines whether the current player can undo
* @return true if player can undo, false if can't
*/
public boolean canUndo(){
if (this.getOtherPlayer().undos < 3 && checkFirstTurn()) {
return true;
}
return false;
}
/**
* gets instance of other player
* @return the other player
*/
public Player getOtherPlayer(){
if (this == PLAYERA){
return PLAYERB;
}
return PLAYERA;
}
/**
* checks if this is the first move in same turn
* @return true if first, false if second
*/
public boolean checkFirstTurn()
{
if(turn == TURNCHECK.JUSTWENT)
return false;
return true;
}
/**
* sets turn to just went if player already
* moved in same turns
*/
public void setJustWent()
{
turn = TURNCHECK.JUSTWENT;
}
/**
* sets first turn if other player has moved
*/
public void setFirstTurn()
{
turn = TURNCHECK.FIRSTTURN;
}
/**
* gets the total undo count
* @return undos the total undo count
*/
public int getUndos(){
return undos;
}
}