-
Notifications
You must be signed in to change notification settings - Fork 0
/
Player.java
140 lines (123 loc) · 2.68 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
import java.util.*;
import java.awt.*;
public class Player
{
/**
* String name of player
*/
private String playerName;
/**
* Color of player's game playing piece
*/
private Color pieceColor;
/**
* Number of moves the player has taken
*/
private int moves;
/**
* Number of games the player has won
*/
private int gamesWon;
/**
* Constructor for player
*
* @param String name the name of the player
* @param Color the color of the player's playing piece
*/
public Player(String name, Color color) {
this.playerName = name;
this.pieceColor = color;
}
/**
* Default constructor for Player class
*/
public Player(){}
/**
* Adding to the number of moves
*/
public void addMove()
{
this.moves += 1;
}
/**
* Returns the number of moves
*
* @return int number of moves
*/
public int getMoves() {
return this.moves;
}
/**
* Adding to the number of games won
*/
public void addWin()
{
this.gamesWon += 1;
}
/**
* Returns the number of moves
*
* @return int number of moves
*/
public int getWins() {
return this.gamesWon;
}
/**
* Setter for the name of the player
*
* @param String playerName the name of the player
*/
public void setName(String playerName)
{
this.playerName = playerName;
}
/**
* Gets the name of the player
*
* @return String name the name of the player
*/
public String getName() {
return this.playerName;
}
/**
* Gets the color of the player's piece
*
* @return Color the color of the piece
*/
public Color getColor() {
return this.pieceColor;
}
/**
* Returns the player's information in string format
*
* @return String with player information
*/
public String toString()
{
String colorPrint = "";
if (this.pieceColor == Color.BLUE) {
colorPrint = "Blue";
}
else {
colorPrint = "Red";
}
return ("Name: " + this.playerName + "\n Color: " + colorPrint);
}
/**
* Checks if two players are equal to each other
*
* @return boolean whether two players are equal
*/
public boolean equals(Object other)
{
if (other instanceof Player)
{
Player otherPlayer = (Player)other;
return this.playerName == otherPlayer.playerName && this.pieceColor == otherPlayer.pieceColor;
}
else
{
return false;
}
}
}