|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectserver.framework.models.AbstractPlayer
public abstract class AbstractPlayer
An AbstractPlayer
object is a representation of
a participant in a framework game.
The player has different attributes such as a name, id,
color, score, and size.
In addition, each AbstractPlayer
object connected to the
server has a uniquely assigned SocketWrapper
object, that
is used for communication with the assosiated client.
Constructor Summary | |
---|---|
AbstractPlayer(SocketWrapper socket,
AbstractServer server,
TestModule.TestType testtype)
Constructor for AbstractPlayer. |
Method Summary | |
---|---|
int |
compareTo(AbstractPlayer p2)
Compares two player objects. |
java.net.SocketAddress |
getAddress()
Returns the address of the client that is represented by this AbstractPlayer object. |
java.lang.String[] |
getAttributeValues()
Returns a String containing the most important player attributes. |
int[] |
getColor()
|
int |
getId()
|
java.lang.String |
getName()
|
int[] |
getPosition()
|
java.lang.Object[] |
getPositionArray()
Returns an array containing the player's id and position. |
int |
getScore()
|
int[] |
getScreenResolution()
|
int |
getSessionId()
|
int |
getSize()
|
SocketWrapper |
getSocket()
|
int |
getSpeed()
|
int |
getTeam()
|
void |
increaseScore(int inc)
Increases the player's score with the provided value. |
int |
lastAliveConfirmation()
|
void |
notifyAboutAlive(int aliveConfirmationId)
Sets the value of the last received alive confirmation when this is received. |
void |
notifyAboutPlayerDisconnected()
Called whenever the player has disconnected from the server. |
void |
runTest()
Runs the test specified by the player's test type parameter. |
void |
sendMessage(java.lang.Object message,
boolean confirm)
Sends a message using the player's assigned SocketWrapper . |
void |
setAttributeValues(java.lang.String[] values)
Called when a player's attributes has been received. |
void |
setName(java.lang.String name)
Sets the name of the player. |
void |
setPosition(int[] position)
Sets the player's position. |
void |
setPosition(java.lang.String[] position)
Sets the player's position. |
void |
setReady(boolean ready)
Sets the player's ready status to the given value. |
void |
setReady(java.lang.String ready)
Sets the player's ready status to the given value, converted to a boolean value. |
void |
setScore(int score)
Sets the player's score to the specified value. |
void |
setSessionId(int sessionId)
Sets the id of the session to which the player is connected. |
void |
setSize(int size)
Sets the player's size to the given value. |
void |
setSpeed(int speed)
Sets the player's speed to the given value. |
void |
setTeam(int team)
Sets the player's team to the specified value. |
java.lang.String |
toString()
Returns a string representation of the player, consisting of the player's name and id. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public AbstractPlayer(SocketWrapper socket, AbstractServer server, TestModule.TestType testtype)
super()
-call. The constructor creates an
AbstractPlayer
-instance, and gives default values
to all attributes not specified as input parameters.
server
- The server to which the player is connected.socket
- The SocketWrapper
used for communication.testtype
- The test type, if any.Method Detail |
---|
public int getId()
public void setName(java.lang.String name)
name
- The player's name.public java.lang.String getName()
public void increaseScore(int inc)
inc
- The score increase.public int getScore()
public java.lang.String toString()
toString
in class java.lang.Object
public java.net.SocketAddress getAddress()
AbstractPlayer
object.
public void setAttributeValues(java.lang.String[] values)
getAttributeValues()
method, and so the rules from that
method are used for parsing.
values
- The player's attributesgetAttributeValues()
public java.lang.String[] getAttributeValues()
public void sendMessage(java.lang.Object message, boolean confirm)
SocketWrapper
.
message
- The message to send.confirm
- Whether the receiver should confirm that the message has been received.public SocketWrapper getSocket()
SocketWrapper
object.public void notifyAboutPlayerDisconnected()
public void setReady(boolean ready)
ready
- Whether the player is ready or not.public void setReady(java.lang.String ready)
ready
- Whether the player is ready or not.public void setSize(int size)
size
- The player's size.public int getSize()
public void setSpeed(int speed)
speed
- The player's speed.public int getSpeed()
public int[] getScreenResolution()
public int[] getColor()
public void runTest()
public int getSessionId()
public void setSessionId(int sessionId)
sessionId
- The id of the session to which the player is connected.public void setPosition(java.lang.String[] position)
position
- The player's position represented as a String array.public void setPosition(int[] position)
position
- The player's position.public java.lang.Object[] getPositionArray()
GameThread
to create
the bundled position messages.
public int[] getPosition()
public void setScore(int score)
score
- The player's score.public void setTeam(int team)
team
- The player's team.public int getTeam()
public int compareTo(AbstractPlayer p2)
compareTo
in interface java.lang.Comparable<AbstractPlayer>
p2
- The player with which to compare the score.
public void notifyAboutAlive(int aliveConfirmationId)
aliveConfirmationId
- The received alive confirmation.public int lastAliveConfirmation()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |