|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectclient.framework.models.AbstractPlayer
public abstract class AbstractPlayer
An AbstractPlayer
object is a representation of
a participant in a framework game. Each player has a Sprite
object, which is his visual repesentation on the game board.
In addition, the player has different attributes such as a name, id,
color, score, and size.
This class also contain support for simple movement
prediction, where future positions are calculated based
on the two last received position updates.
Constructor Summary | |
---|---|
|
AbstractPlayer(java.lang.String id)
Constructor using an empty name and default values for size (10) and speed (1). |
|
AbstractPlayer(java.lang.String id,
java.lang.String name)
Constructor using default values for size (10) and speed (1). |
protected |
AbstractPlayer(java.lang.String id,
java.lang.String name,
int size,
int speed)
Constructor for AbstractPlayer. |
Method Summary | |
---|---|
int |
compareTo(Comparable object)
Method inherited from the Comparable interface. |
boolean |
equals(java.lang.Object object)
Checks whether the input object is the same player object as this. |
java.lang.String[] |
getAttributeValues()
Returns a String containing the most important player attributes. |
int[] |
getColor()
Returns the player's color in an array containing values between [0 and 255] for each of the colors red, green and blue. |
java.lang.String |
getId()
Returns the player's id. |
java.lang.String |
getName()
Returns the player's name. |
int[] |
getPosition()
Returns an array containing the player's x- and y-coordinate in that order. |
java.lang.Integer |
getScore()
Returns the player's score. |
int[] |
getScreenResolution()
Returns an array containing the player's screen resolution. |
int |
getSize()
Returns the size of the player's sprite. |
int |
getSpeed()
Returns the speed in which the player moves on the game board. |
Sprite |
getSprite()
Returns the player's sprite representation. |
int |
getTeam()
Returns the team that the player is member of, if any. |
boolean |
isReady()
Returns the player's ready status. |
void |
move()
Called to move the player a distance detemined by the player's movement vector. |
void |
move(double dx,
double dy)
Moves the player a distance determined by the input parameters. |
protected void |
resetMovement()
Resets the player's movement. |
void |
setAttributeValues(java.lang.String[] values)
Called when a player's attributes has been received. |
void |
setColor(int red,
int green,
int blue)
Sets the player's color. |
void |
setImage()
Creates an image for the player's sprite. |
void |
setName(java.lang.String name)
Sets the player's name. |
void |
setPosition(int x,
int y)
Sets the player's position on the game board to the specified position. |
void |
setReady(boolean ready)
Sets the player's ready status to the specified value. |
void |
setScore(int score)
Sets the player's score to the specified value. |
void |
setScreenResolution(int[] screenResolution)
Sets the screen resolution variable to the screen resolution on the player's phone. |
void |
setSize(int size)
Sets the size of the player's sprite to the specified size, and creates the sprite's image. |
void |
setSpeed(int speed)
Set's the speed in which the player moves in the game board to the specified value. |
void |
setTeam(int team)
Sets the player as member of the specified team. |
void |
setTeamColor(int[] color)
Sets the player's team color. |
void |
setX(int x)
Sets the x-position of the player. |
void |
setY(int y)
Sets the y-position of the player. |
java.lang.String |
toString()
Method for displaying the player's name and score. |
Methods inherited from class java.lang.Object |
---|
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
protected AbstractPlayer(java.lang.String id, java.lang.String name, int size, int speed)
super()
-call. The constructor creates an
AbstractPlayer
-instance, and gives default values
to all attributes not specified as input parameters.
id
- The player's network id.name
- The player's name.size
- The size of the player's Sprite
object.speed
- The speed in which the player is able to move.AbstractGame.newPlayer(String, String)
public AbstractPlayer(java.lang.String id, java.lang.String name)
id
- The player's id.name
- The player's name.public AbstractPlayer(java.lang.String id)
id
- The id of the player.Method Detail |
---|
public java.lang.String getId()
public java.lang.String getName()
public void setName(java.lang.String name)
name
- The player's name.public int[] getColor()
public void setColor(int red, int green, int blue)
red
- The amount of red.green
- The amound of green.blue
- The amount of blue.setImage()
public void setTeamColor(int[] color)
color
- The player's team's colorsetImage()
public void setImage()
public java.lang.String toString()
toString
in class java.lang.Object
Utils#drawPlayerList(javax.microedition.lcdui.Graphics, int, int, AbstractGame, boolean)
public java.lang.Integer getScore()
public void setScore(int score)
score
- The player's score.public boolean isReady()
public void setReady(boolean ready)
ready
- Whether the player is ready or not.public int getTeam()
public void setTeam(int team)
team
- The player's team number.public boolean equals(java.lang.Object object)
AbstractPlayer
object, or if the player names and/or addresses differ, the
method returns false.
equals
in class java.lang.Object
object
- The object to compare this to.
public Sprite getSprite()
public void setScreenResolution(int[] screenResolution)
screenResolution
- The screen resolution retrieved from the phone.public int[] getScreenResolution()
public void setX(int x)
x
- The player's x-position.public void setY(int y)
y
- The player's y-position.public void setPosition(int x, int y)
x
- The player's x-position.y
- The player's y-position.public void move(double dx, double dy)
dx
- The x-movement.dy
- The y-movement.public void move()
public int[] getPosition()
public void setSize(int size)
size
- The player's size.public int getSize()
public int getSpeed()
public void setSpeed(int speed)
speed
- The player's speed.public java.lang.String[] getAttributeValues()
AbstractGame.sendPlayerInfo()
,
setAttributeValues(String[])
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 int compareTo(Comparable object)
Comparable
interface.
Is used to sort player objects according to their score. If the
object passed as input parameter is not a AbstractPlayer
object, 1 is returned. If the input parameter is an
AbstractPlayer
, the method returns the difference between
this player's score and the input parameter's score.
compareTo
in interface Comparable
object
- The object to compare to.
protected void resetMovement()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |