|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--client.UserDefinedClient
A class that may be subclassed to create robot clients, or clients that extend the player's capabilities.
The class provides several kinds of methods, some of which must be overridden to have any effect:
super
method, as it's empty.
super
method.
objects
package.
Field Summary | |
static int |
MAX_BOMB_SPEED
Maximum bomb speed in pixels per second. |
static int |
MAX_PHASER_SPEED
Maximum phaser shot speed in pixels per second. |
static int |
MAX_SHIP_SPEED
Maximum player/ship speed in pixels per second. |
static int |
TURN_LEFT
getBestTurn advices you to turn left. |
static int |
TURN_NONE
getBestTurn advices you to not turn. |
static int |
TURN_RIGHT
getBestTurn advices you to turn right. |
Constructor Summary | |
UserDefinedClient()
NOTE: Your constructor should not call any of the methods in this class, as things have not been set up yet. |
Method Summary | |
protected void |
annotateBoardImage(java.awt.Graphics g)
Lets you draw on the game board. |
void |
fireBomb()
Fires a targeting bomb. |
void |
firePhaser()
Fires a phaser shot. |
double |
getAbsDeltaAngle(double angle1,
double angle2)
Calculates the smallest angle between two given angles, without taking care of direction. |
double |
getAngle(DrawableGameObject o)
Calculates the angle in radians of a vector from our ship to the given object. |
double |
getAngle(int fromX,
int fromY,
int toX,
int toY)
Calculates the angle in radians from one point to another. |
int |
getBestTurn(double oldAngle,
double newAngle)
Finds the best way to turn to move from one direction to another. |
BombPack[] |
getBombPacks()
Gets all currently available bomb packs. |
Bomb[] |
getBombs()
Gets all currently moving bombs, including our own. |
BombPack |
getClosestBombPack()
Finds the closest bomb pack. |
BombPack |
getClosestBombPack(int myX,
int myY)
Finds the closest bomb pack. |
Player |
getClosestEnemy()
Finds the closest enemy player that is alive. |
Player |
getClosestEnemy(int myX,
int myY)
Finds the closest enemy player that is alive. |
Bomb |
getClosestEnemyBomb()
Finds the closest enemy bomb. |
Bomb |
getClosestEnemyBomb(int myX,
int myY)
Finds the closest enemy bomb. |
Phaser |
getClosestEnemyPhaser()
Finds the closest enemy phaser. |
Phaser |
getClosestEnemyPhaser(int myX,
int myY)
Finds the closest enemy phaser shot. |
double |
getDeltaAngle(double fromAngle,
double toAngle)
Calculates the smallest angle from one angle to another. |
int |
getDistanceBetween(DrawableGameObject o1,
DrawableGameObject o2)
Calculates the pixel distance between two objects. |
int |
getDistanceBetween(DrawableGameObject o,
int x,
int y)
Calculates the pixel distance between an objects and a given location. |
int |
getDistanceBetween(int x0,
int y0,
int x1,
int y1)
Calculates the pixel distance between two points. |
java.awt.Component |
getGameComponent()
Returns the AWT Component that functions as the game are of the window. |
Player |
getMyPlayer()
Returns the player controlled by this client. |
double |
getNormalizedAngle(double angle)
Makes sure an angle is within the interval 0.0 to 2PI. |
Phaser[] |
getPhasers()
Gets all currently moving phasers, including our own. |
Player[] |
getPlayers()
Gets all available players, including our own, and including dead ones. |
int |
getSquareDistanceBetween(DrawableGameObject o1,
DrawableGameObject o2)
Calculates the squared pixel distance between two objects. |
int |
getSquareDistanceBetween(DrawableGameObject o,
int x,
int y)
Calculates the squared pixel distance between an object and a given location. |
int |
getSquareDistanceBetween(int x0,
int y0,
int x1,
int y1)
Calculates the squared pixel distance between two points. |
int |
getUpdateFrequency()
Returns the number of times per second that the update method is called. |
int |
getVisibleHeight()
Returns the height of the current visible display are. |
int |
getVisibleOffsetX()
Gets the horizontal offset into the world of the area currently visible in the game window. |
int |
getVisibleOffsetY()
Gets the vertical offset into the world of the area currently visible in the game window. |
int |
getVisibleWidth()
Returns the width of the current visible display are. |
int |
getWorldHeight()
Returns the height of the entire playing area. |
int |
getWorldWidth()
Returns the width of the entire playing area. |
protected void |
infoBombCreated(Bomb bomb)
Informs that a new targetting bomb has been created. |
protected void |
infoBombDestroyed(Bomb bomb)
Informs that a targetting bomb has been removed, either because it ran out of fuel, or because it hit something. |
protected void |
infoBombMoved(Bomb bomb)
Informs that a targetting bomb has moved to a new location. |
protected void |
infoBombPackCreated(BombPack bombPack)
Informs that someone has lost their weapons somewhere. |
protected void |
infoBombPackDestroyed(BombPack bombPack)
Informs that a bomb pack has been removed, probably because it was picked up by someone. |
protected void |
infoBombPackMoved(BombPack bombPack)
Informs that a bomb pack has moved. |
protected void |
infoLoggedIntoServer()
Informs that the client has successfully logged into the server. |
protected void |
infoManualFireBomb()
Informs that the user has fired the bomb. |
protected void |
infoManualFirePhaser()
Informs that the user has fired the phaser. |
protected void |
infoManualStartMovingBack()
Informs that the user started to move backward. |
protected void |
infoManualStartMovingForeward()
Informs that the user started to move foreward. |
protected void |
infoManualStartTurningLeft()
Informs that the user started to turn left. |
protected void |
infoManualStartTurningRight()
Informs that the user started to turn right. |
protected void |
infoManualStopMovingBack()
Informs that the user stopped moving backward. |
protected void |
infoManualStopMovingForeward()
Informs that the user stopped moving foreward. |
protected void |
infoManualStopTurningLeft()
Informs that the user stopped turning left. |
protected void |
infoManualStopTurningRight()
Informs that the user stopped turning right. |
protected void |
infoPhaserCreated(Phaser phaser)
Informs that a new phaser shot has been created. |
protected void |
infoPhaserDestroyed(Phaser phaser)
Informs that a phaser has been removed. |
protected void |
infoPhaserMoved(Phaser phaser)
Informs that a phaser has moved a small distance. |
protected void |
infoPlayerDied(Player player,
Player killer,
byte weapon)
Informs that a player has been killed. |
protected void |
infoPlayerEntered(Player player)
Informs that a new player has entered the game. |
protected void |
infoPlayerHit(Player player,
Player hitter,
byte weapon)
Informs that a player has been hit by some weapon, without necessarily being killed. |
protected void |
infoPlayerLeft(Player player)
Informs that a player has left the game. |
protected void |
infoPlayerMoved(Player player)
Informs that a player has moved or changed direction. |
protected void |
infoPlayerResurrected(Player player)
Informs that a player has resurrected from the dead. |
protected void |
infoPlayerSaidSomething(Player player,
java.lang.String message)
Informs that a player has sent a global chat message. |
protected void |
infoUnhandeledKeyPressed(int code)
Informs that the user has pressed a key that has no normal function in the game. |
protected void |
infoUnhandeledKeyReleased(int code)
Informs that the user has released a key that has no normal function in the game. |
boolean |
isBehind(DrawableGameObject o)
Checks if the given object is behind our ship. |
boolean |
isInFront(DrawableGameObject o)
Checks if the given object is in front of our ship. |
boolean |
isToTheLeft(DrawableGameObject o)
Checks if the given object is to the left of our ship. |
boolean |
isToTheRight(DrawableGameObject o)
Checks if the given object is to the right of our ship. |
void |
say(java.lang.String message)
Sends a message to all the players. |
void |
setAutoResurrect(boolean status)
Instructs the main client code to autimatically resurrect (bring back to life) after being killed. |
void |
setName(java.lang.String name)
Sets new name for our player. |
void |
showMessage(java.lang.String message)
Displays a message on the game board. |
void |
startMovingBack()
Starts moving the ship backward. |
void |
startMovingForeward()
Starts moving the ship foreward. |
void |
startTurningLeft()
Starts turning the ship to the left. |
void |
startTurningRight()
Starts turning the ship to the right. |
void |
stopMoving()
Stops all foreward/backward movement of the ship. |
void |
stopMovingBack()
Stops backward movement of the ship. |
void |
stopMovingForeward()
Stops foreward movement of the ship. |
void |
stopTurning()
Stops any turning of the ship. |
void |
stopTurningLeft()
Stops leftward movement of the ship. |
void |
stopTurningRight()
Stops rightward movement of the ship. |
protected void |
update()
Updates the client logic at regular intervals. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int TURN_NONE
getBestTurn
advices you to not turn.
public static final int TURN_LEFT
getBestTurn
advices you to turn left.
public static final int TURN_RIGHT
getBestTurn
advices you to turn right.
public static final int MAX_PHASER_SPEED
public static final int MAX_BOMB_SPEED
public static final int MAX_SHIP_SPEED
Constructor Detail |
public UserDefinedClient()
Method Detail |
protected void update()
If you override this, there's no need to call the
super
method.
protected void annotateBoardImage(java.awt.Graphics g)
If you override this, there's no need to call the
super
method.
g
- the graphic context.protected void infoLoggedIntoServer()
If you override this, there's no need to call the
super
method.
protected void infoPlayerEntered(Player player)
If you override this, there's no need to call the
super
method.
player
- the player, which may include the client's
own player.Player
protected void infoPlayerLeft(Player player)
If you override this, there's no need to call the
super
method.
player
- the player, which may include the client's
own player.Player
protected void infoPlayerMoved(Player player)
If you override this, there's no need to call the
super
method.
player
- the player, which may include the client's
own player.Player
protected void infoPlayerHit(Player player, Player hitter, byte weapon)
infoPlayerDied
.
If you override this, there's no need to call the
super
method.
player
- the player, which may include the client's
own player.hitter
- the player who's weapon hit the first player.weapon
- the weapon type, as found in
objects.WeaponType
.Player
,
WeaponType
protected void infoPlayerDied(Player player, Player killer, byte weapon)
If you override this, there's no need to call the
super
method.
player
- the player, which may include the client's
own player.weapon
- the weapon type, as found in
objects.WeaponType
.Player
,
WeaponType
protected void infoPlayerResurrected(Player player)
If you override this, there's no need to call the
super
method.
player
- the player, which may include the client's
own player.Player
protected void infoPlayerSaidSomething(Player player, java.lang.String message)
If you override this, there's no need to call the
super
method.
player
- the player, which may include the client's
own player.message
- the message sent by the player.Player
protected void infoPhaserCreated(Phaser phaser)
If you override this, there's no need to call the
super
method.
phaser
- the phaser shot.Phaser
protected void infoPhaserMoved(Phaser phaser)
If you override this, there's no need to call the
super
method.
phaser
- the phaser shot.Phaser
protected void infoPhaserDestroyed(Phaser phaser)
If you override this, there's no need to call the
super
method.
phaser
- the phaser shot.Phaser
protected void infoBombCreated(Bomb bomb)
If you override this, there's no need to call the
super
method.
bomb
- the bomb.Bomb
protected void infoBombMoved(Bomb bomb)
If you override this, there's no need to call the
super
method.
bomb
- the bomb.Bomb
protected void infoBombDestroyed(Bomb bomb)
If you override this, there's no need to call the
super
method.
bomb
- the bomb.Bomb
protected void infoBombPackCreated(BombPack bombPack)
If you override this, there's no need to call the
super
method.
bombPack
- the bomb pack.BombPack
protected void infoBombPackMoved(BombPack bombPack)
If you override this, there's no need to call the
super
method.
bombPack
- the bomb pack.BombPack
protected void infoBombPackDestroyed(BombPack bombPack)
If you override this, there's no need to call the
super
method.
bombPack
- the bomb pack.BombPack
protected void infoUnhandeledKeyPressed(int code)
If you override this, there's no need to call the
super
method.
code
- the result from
java.awt.event.KeyEvent.getKeyCode()
.KeyEvent
protected void infoUnhandeledKeyReleased(int code)
If you override this, there's no need to call the
super
method.
code
- the result from
java.awt.event.KeyEvent.getKeyCode()
.KeyEvent
protected void infoManualStartTurningLeft()
If you override this, there's no need to call the
super
method.
protected void infoManualStopTurningLeft()
If you override this, there's no need to call the
super
method.
protected void infoManualStartTurningRight()
If you override this, there's no need to call the
super
method.
protected void infoManualStopTurningRight()
If you override this, there's no need to call the
super
method.
protected void infoManualStartMovingForeward()
If you override this, there's no need to call the
super
method.
protected void infoManualStopMovingForeward()
If you override this, there's no need to call the
super
method.
protected void infoManualStartMovingBack()
If you override this, there's no need to call the
super
method.
protected void infoManualStopMovingBack()
If you override this, there's no need to call the
super
method.
protected void infoManualFirePhaser()
If you override this, there's no need to call the
super
method.
protected void infoManualFireBomb()
If you override this, there's no need to call the
super
method.
public final void startTurningLeft()
public final void stopTurningLeft()
public final void startTurningRight()
public final void stopTurningRight()
public final void stopTurning()
public final void startMovingForeward()
public final void stopMovingForeward()
public final void startMovingBack()
public final void stopMovingBack()
public final void stopMoving()
public final void firePhaser()
public final void fireBomb()
public final void say(java.lang.String message)
message
- the message to send.public final void setName(java.lang.String name)
name
- the new name.public final void setAutoResurrect(boolean status)
status
- true
to turn on,
false
to turn off.public final void showMessage(java.lang.String message)
message
- the message to display.public final java.awt.Component getGameComponent()
public final int getVisibleOffsetX()
public final int getVisibleOffsetY()
public final int getWorldWidth()
public final int getWorldHeight()
public final int getVisibleWidth()
public final int getVisibleHeight()
public final Player getClosestEnemy(int myX, int myY)
myX
- x-coordinate to compare to.myY
- y-coordinate to compare to.
null
if no
other players are present.Player
public final Player getClosestEnemy()
null
if no other players are present.Player
public final Bomb getClosestEnemyBomb(int myX, int myY)
myX
- x-coordinate to compare to.myY
- y-coordinate to compare to.
null
if no
bombs owned by other players are present.Bomb
public final Bomb getClosestEnemyBomb()
null
if no
bombs owned by other players are present.Bomb
public final Phaser getClosestEnemyPhaser(int myX, int myY)
myX
- x-coordinate to compare to.myY
- y-coordinate to compare to.
null
if no
phasers owned by other players are present.Phaser
public final Phaser getClosestEnemyPhaser()
null
if no
phasers owned by other players are present.Phaser
public final BombPack getClosestBombPack(int myX, int myY)
myX
- x-coordinate to compare to.myY
- y-coordinate to compare to.
null
if no
bomb packs are present.BombPack
public final BombPack getClosestBombPack()
null
if no
bomb packs are present.BombPack
public final Player getMyPlayer()
Player
-object.Player
public final Player[] getPlayers()
Player
-objects.Player
public final Phaser[] getPhasers()
Phaser
-objects.Phaser
public final Bomb[] getBombs()
Bomb
-objects.Bomb
public final BombPack[] getBombPacks()
BombPack
-objects.BombPack
public final int getSquareDistanceBetween(DrawableGameObject o1, DrawableGameObject o2)
o1
- one object.o2
- another object.
DrawableGameObject
public final int getDistanceBetween(DrawableGameObject o1, DrawableGameObject o2)
o1
- one object.o2
- another object.
DrawableGameObject
public final int getSquareDistanceBetween(DrawableGameObject o, int x, int y)
x
- an x-coordinate.y
- a y-coordinate.
DrawableGameObject
public final int getDistanceBetween(DrawableGameObject o, int x, int y)
x
- an x-coordinate.y
- a y-coordinate.
DrawableGameObject
public final int getSquareDistanceBetween(int x0, int y0, int x1, int y1)
x0
- an x-coordinate.y0
- a y-coordinate.x1
- another x-coordinate.y1
- another y-coordinate.
public final int getDistanceBetween(int x0, int y0, int x1, int y1)
x0
- an x-coordinate.y0
- a y-coordinate.x1
- another x-coordinate.y1
- another y-coordinate.
public final double getAngle(int fromX, int fromY, int toX, int toY)
fromX
- start point x-coordinate.fromY
- start point y-coordinate.toX
- end point x-coordinate.toY
- end point y-coordinate.
public final double getAngle(DrawableGameObject o)
o
- the object to find the direction to.
public final double getNormalizedAngle(double angle)
angle
- the angle to normalize.
public final double getDeltaAngle(double fromAngle, double toAngle)
fromAngle
to reach the toAngle
,
without moving more than half way through the circle.
The input angles must be between 0 and 2PI. The output is between -PI and PI.
fromAngle
- the angle to start from.toAngle
- the angle to end up with.
public final double getAbsDeltaAngle(double angle1, double angle2)
The input angles must be between 0 and 2PI. The output is between 0 and PI.
angle1
- one angle.angle2
- another angle.
public final int getBestTurn(double oldAngle, double newAngle)
oldAngle
- the current angle of direction.newAngle
- the wanted angle of direction.
TURN_NONE
,
TURN_LEFT
, or TURN_RIGHT
.public final boolean isInFront(DrawableGameObject o)
o
- the object to check.
true
if the object is in front,
false
otherwise.public final boolean isBehind(DrawableGameObject o)
o
- the object to check.
true
if the object is behind,
false
otherwise.public final boolean isToTheLeft(DrawableGameObject o)
o
- the object to check.
true
if the object is to the left,
false
otherwise.public final boolean isToTheRight(DrawableGameObject o)
o
- the object to check.
true
if the object is to the right,
false
otherwise.public final int getUpdateFrequency()
update
method is called.
update()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |