|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectJTP.LevelPlayer
public class LevelPlayer
Handles gameplay mechanics of individual levels. Note: This class only
understands two modes: single and two-player. (The GamePlayer
class deals with game mode specifics.)
Field Summary | |
---|---|
static int |
FINISHED
moveOne return code indicating the level has been completed |
static int |
INVALID_MOVE
moveOne return code indicating the move was invalid |
static int |
LOST
moveOne return code indicating no more moves are available |
static int |
MOVED
moveOne return code indicating succesful move |
static int |
STUCK
moveOne return code indicating the just moved player is stuck |
protected boolean |
teleportDeath
|
Constructor Summary | |
---|---|
LevelPlayer(Level level)
Creates a new LevelPlayer instance with the given level. |
|
LevelPlayer(Level level,
boolean twoPlayer)
Creates a new LevelPlayer instance with the given level and
in either single or two player mode. |
Method Summary | |
---|---|
boolean |
activePlayerDead()
Indicates whether the currently active player is dead or not |
boolean |
automaticMovesLeft(int direction)
Returns whether the active player has automatic moves left given the last direction they moved in |
protected boolean |
canStillMove(boolean playerTwo)
Calculates whether the player can still move or not |
Point |
getActivePosition()
Returns position of currently active player |
protected GameTile[][] |
getGameTiles()
Used by GamePlayer to directly access the game board (for
rendering) |
Point |
getP1Position()
Returns the grid position of player 1 |
Point |
getP2Position()
Returns the grid position of player 2 |
boolean |
hasNotStarted()
Returns whether a level has been started. |
int |
moveOne(int direction)
Moves active player by one in the given direction. |
void |
reset()
Resets currently loaded level back to starting position. |
boolean |
secondPlayerActive()
Indicates whether the second or first player is currently active. |
int |
setActivePlayerDead()
Flags currently active player as dead |
void |
setActivePlayerTo(boolean secondPlayer)
Set the active player. |
void |
setLevel(Level level)
Loads the provided level. |
void |
setLevel(Level level,
boolean twoPlayer)
Loads the provided level in either single or two-player mode. |
void |
setLevel(Level level,
boolean twoPlayer,
boolean swappedStarts)
Loads the provided level in either single or two-player mode. |
int |
tilesClearedByP1()
Returns number of tiles cleared by player 1 |
int |
tilesClearedByP2()
Returns number of tiles cleared by player 2 |
int |
tilesLeft()
Returns how many tiles are left in the level |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int MOVED
moveOne
return code indicating succesful move
public static final int FINISHED
moveOne
return code indicating the level has been completed
public static final int INVALID_MOVE
moveOne
return code indicating the move was invalid
public static final int LOST
moveOne
return code indicating no more moves are available
public static final int STUCK
moveOne
return code indicating the just moved player is stuck
protected boolean teleportDeath
Constructor Detail |
---|
public LevelPlayer(Level level) throws NullPointerException
LevelPlayer
instance with the given level.
level
- the level to load
NullPointerException
- if the parameter is null
public LevelPlayer(Level level, boolean twoPlayer) throws NullPointerException, IllegalArgumentException
LevelPlayer
instance with the given level and
in either single or two player mode.
level
- the level to loadtwoPlayer
- indicate whether this should be a two player level or not
NullPointerException
- if the parameter is null
IllegalArgumentException
- if two player mode has been requested yet
the supplied level is a single player levelMethod Detail |
---|
public void setLevel(Level level) throws NullPointerException
level
- the level to load
NullPointerException
- if the paramter is null
public void setLevel(Level level, boolean twoPlayer) throws NullPointerException, IllegalArgumentException
level
- the level to loadtwoPlayer
- indicate whether this should be a two player level or not
NullPointerException
- if the paramter is null
IllegalArgumentException
- if two player mode has been requested yet
the supplied level is a single player levelpublic void setLevel(Level level, boolean twoPlayer, boolean swappedStarts) throws NullPointerException, IllegalArgumentException
level
- the level to loadtwoPlayer
- indicate whether this should be a two player level or notswappedStarts
- exchanges first and second player starting positions.
Note: This has no effect if the twoPlayer
parameter is not
set to true
NullPointerException
- if the paramter is null
IllegalArgumentException
- if two player mode has been requested yet
the supplied level is a single player levelpublic int moveOne(int direction)
direction
- e.g UP
or GamePlayer.AUTOSTART
which is used to start a level (and perform initial automatic moves if
there are any, one by one)
public boolean automaticMovesLeft(int direction)
direction
- e.g. UP
true
if there are more automatic moves leftpublic void reset()
protected boolean canStillMove(boolean playerTwo)
playerTwo
- indicate whether to calculate for first or second player
true
if there are still moves availablepublic void setActivePlayerTo(boolean secondPlayer)
secondPlayer
- indicate whether Player 2 should be active or notpublic boolean secondPlayerActive()
true
if Player 2 is activeprotected GameTile[][] getGameTiles()
GamePlayer
to directly access the game board (for
rendering)
public int setActivePlayerDead()
LOST
if both players are dead or STUCK
the other player can still movepublic boolean activePlayerDead()
true
if the active player is deadpublic Point getActivePosition()
public Point getP1Position()
public Point getP2Position()
public int tilesLeft()
public int tilesClearedByP1()
public int tilesClearedByP2()
public boolean hasNotStarted()
true
if the level has been started
|
||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |