public class Player
extends java.lang.Object
You do not need to modify this class (except to fix one checkstyle error). But you are encouraged to study it since it does some of the things that you need to do to complete ConnectN.
Constructor | Description |
---|---|
Player(java.lang.String setName) |
Create a new player with the given name.
|
Player(java.lang.String setName,
int setScore,
int setID) |
Create a new player from a full set of fields.
|
Player(Player other) |
Create a copy of an existing player.
|
Modifier and Type | Method | Description |
---|---|---|
void |
addScore() |
Add one to this player's score.
|
boolean |
equals(java.lang.Object obj) |
Define equality for the Player class.
|
int |
getID() |
Get the current player's id.
|
java.lang.String |
getName() |
Get the player's name.
|
int |
getScore() |
Get this player's score.
|
int |
hashCode() |
Define the hash code for the Player class.
|
void |
setName(java.lang.String setName) |
Set the player's name.
|
public Player(java.lang.String setName)
Each player's score begins at zero, and each receives a monotonically increasing unique ID.
setName
- the name for the new playerpublic Player(Player other)
This copy constructor creates a copy of an existing player, so that player information can be exposed without allowing the copy to modify the state of the original player.
The id is copied, meaning that the copy will initially be equal to the original. However, future modifications to the score field will not change the copy and will result in it being considered non-equal to the original.
other
- the otherpublic Player(java.lang.String setName, int setScore, int setID)
This is entirely for deserialization by the web frontend. Unlike the other constructors, it does not increment the player count, since the assumption is that you are recovering an existing player.
setName
- the name for the new playersetScore
- the score for the new playersetID
- the ID for the new playerpublic java.lang.String getName()
public void setName(java.lang.String setName)
setName
- the player's new namepublic int getScore()
public void addScore()
public int getID()
public int hashCode()
This method should only use the id field of the instance. This implements what is known as
entity semantics. Two players with the same name and same score may not be equal if
they were created at different times. Note that Eclipse can auto-generate this and
equals
.
hashCode
in class java.lang.Object
Object.hashCode()
public final boolean equals(java.lang.Object obj)
This method should only use the id field of the instance. This implements what is known as
entity semantics. Two players with the same name and same score may not be equal if
they were created at different times. Note that Eclipse can auto-generate this and
hashCode()
.
equals
in class java.lang.Object
Object.equals(java.lang.Object)