JTP
Class GamePlayer

java.lang.Object
  extended by JTP.GamePlayer

public class GamePlayer
extends Object

Defines function and rendering of the gameplay component.

Author:
V.Termanis

Field Summary
static int AUTOSTART
           
static int COOP
          Cooperative two player mode
static int CUSTOM_DEATH_MESSAGE_LEVEL
           
static int DOWN
           
static int FINISHED_LEVEL
           
static int FINISHED_SET
           
static int GAMEOVER
           
static int INVALID_MOVE
           
static int LEFT
           
static int LIFE_LOST
           
static int LOAD_CANCELLED
          loadLevelSet method return value
static int LOAD_NOT2P
          loadLevelSet method return value
static int LOAD_OK
          loadLevelSet method return value
static int MEDIAMERGE_LEVEL
           
static int MOVED
           
static int NONE
           
static int NUMBERED_LEVEL
           
static int P1
          ID of first player
static int P2
          ID of second player
static int QUIT
           
static int RESET
           
static int RIGHT
           
static int SINGLE
          Single player mode
static int SKIPPED_LEVEL
           
static int UP
           
static int VS
          Versus two player mode
static int VS_CHOOSE
          Versus mode with choice between simulatenous and alternate modes
static int VS_TURN_BASED
          Versus alternate two player mode
 
Constructor Summary
GamePlayer(Images imgData, ScreenFrames frames, TilePainter tPainter, Color txtColor, Font txtFont, int stringSpacing, int numSpacing, Graphics2D g, String lvlSetFilename, String beepSoundName, SplashMessage message, Screen screen)
          Creates a new GamePlayer instance with the given attributes
 
Method Summary
 void activateMediaMerge()
          Indicate that the MediaMerge tile should be shown in this levelset.
 void activateTestMode()
          Indicate that the editor originating test mode is active Note: This is reset each time a new levelset is loaded
 boolean automaticMovesLeft()
          Returns true if there are any automatic moves left
 int clickResult(int button)
          Indicate a mouse button has been pressed.
 int currentFrameMode()
          Returns what borders (frames) are being rendered
 void draw(Graphics2D g)
          Depending on situation this will either render only the timer (i.e.
 void drawAll(Graphics2D g)
           
 void enableUnlocking()
          Indicate that this levelset's levels have to be unlocked Note: Unlock status is reset each time a new levelset is loaded
 int gameMode()
          Returns the currently set game mode
 int getGameMode()
          Returns the current game mode
protected  LevelSet getLevelSet()
          Returns the active levelset
 int getScore()
          Returns total score up to now Note: Scoring status is reset each time a new levelset is loaded
 int getState()
          Returns the current game state (e.g.
 boolean levelHasNotStarted()
          Checks whether the level has been started
 void loadLevelSet(String filename, Graphics2D g)
          Loads a levelset from a file.
 int loadLevelSet(String filename, int gameMode, Component c, Graphics2D g)
          Loads a levelset from a file with the specified game mode.
 int loadLevelSet(URL fileURL, Graphics2D g)
          Loads a levelset from the given location
 int loadLevelSet(URL fileURL, int gameMode, Component c, Graphics2D g)
          Loads a levelset from a location with the specified game mode.
 int performMoves(int keyP1, int keyP2)
          Moves one or both players (or executes control command, e.g.
 void revokeMediaMergeTile()
          Indicate that the MediaMerge tile should not be used anymore
 boolean scoringEnabled()
          Indicates whether scoring is turned on Note: Scoring status is reset each time a new levelset is loaded
 void setLevel(int index)
          Choose which level to play
 void setLevelSet(LevelSet ls, int gameMode, boolean score, Graphics2D g)
          Loads a levelset straight from its native format.
 void setLives(int amount, Graphics2D g)
          Sets number of lives player has at beginning of levelset.
 void stopAndToggleTimer()
          Like in chess - stops one timer and activates it for the other player
 boolean testModeActive()
          Checks whether the (editor) test mode is on
 void unpauseTimer()
           
 void updateState(boolean requestMessages)
           
 boolean updateUI(Point mouseLocation)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

SINGLE

public static final int SINGLE
Single player mode

See Also:
Constant Field Values

COOP

public static final int COOP
Cooperative two player mode

See Also:
Constant Field Values

VS

public static final int VS
Versus two player mode

See Also:
Constant Field Values

VS_TURN_BASED

public static final int VS_TURN_BASED
Versus alternate two player mode

See Also:
Constant Field Values

VS_CHOOSE

public static final int VS_CHOOSE
Versus mode with choice between simulatenous and alternate modes

See Also:
Constant Field Values

LOAD_OK

public static final int LOAD_OK
loadLevelSet method return value

See Also:
Constant Field Values

LOAD_NOT2P

public static final int LOAD_NOT2P
loadLevelSet method return value

See Also:
Constant Field Values

LOAD_CANCELLED

public static final int LOAD_CANCELLED
loadLevelSet method return value

See Also:
Constant Field Values

NONE

public static final int NONE
See Also:
Constant Field Values

UP

public static final int UP
See Also:
Constant Field Values

DOWN

public static final int DOWN
See Also:
Constant Field Values

LEFT

public static final int LEFT
See Also:
Constant Field Values

RIGHT

public static final int RIGHT
See Also:
Constant Field Values

AUTOSTART

public static final int AUTOSTART
See Also:
Constant Field Values

MOVED

public static final int MOVED
See Also:
Constant Field Values

GAMEOVER

public static final int GAMEOVER
See Also:
Constant Field Values

FINISHED_SET

public static final int FINISHED_SET
See Also:
Constant Field Values

FINISHED_LEVEL

public static final int FINISHED_LEVEL
See Also:
Constant Field Values

INVALID_MOVE

public static final int INVALID_MOVE
See Also:
Constant Field Values

LIFE_LOST

public static final int LIFE_LOST
See Also:
Constant Field Values

RESET

public static final int RESET
See Also:
Constant Field Values

QUIT

public static final int QUIT
See Also:
Constant Field Values

SKIPPED_LEVEL

public static final int SKIPPED_LEVEL
See Also:
Constant Field Values

MEDIAMERGE_LEVEL

public static final int MEDIAMERGE_LEVEL
See Also:
Constant Field Values

NUMBERED_LEVEL

public static final int NUMBERED_LEVEL
See Also:
Constant Field Values

CUSTOM_DEATH_MESSAGE_LEVEL

public static final int CUSTOM_DEATH_MESSAGE_LEVEL
See Also:
Constant Field Values

P1

public static final int P1
ID of first player

See Also:
Constant Field Values

P2

public static final int P2
ID of second player

See Also:
Constant Field Values
Constructor Detail

GamePlayer

public GamePlayer(Images imgData,
                  ScreenFrames frames,
                  TilePainter tPainter,
                  Color txtColor,
                  Font txtFont,
                  int stringSpacing,
                  int numSpacing,
                  Graphics2D g,
                  String lvlSetFilename,
                  String beepSoundName,
                  SplashMessage message,
                  Screen screen)
           throws NullPointerException,
                  IllegalArgumentException,
                  IOException
Creates a new GamePlayer instance with the given attributes

Parameters:
imgData - global image resources
frames - for drawing borders and background
tPainter - for drawing tiles
txtColor - colour of all text (except tile numbers)
txtFont - style used for all text (except tile numbers)
stringSpacing - vertical spacing (in pixels) between text elements
numSpacing - horizontal spacing (in pixels from left) for status numbers (e.g. lives left)
g - graphics context for drawing
lvlSetFilename - levelset to initially load (in single player mode), can also be set to null if a levelset is to be loaded later
beepSoundName - full path to countdown "beep" sound
message - popup message handler
screen - parent component
Throws:
NullPointerException
IllegalArgumentException
IOException
Method Detail

loadLevelSet

public void loadLevelSet(String filename,
                         Graphics2D g)
                  throws IOException
Loads a levelset from a file.

Parameters:
filename - absolute path to levelset file
g - graphics context for drawing
Throws:
IOException

loadLevelSet

public int loadLevelSet(String filename,
                        int gameMode,
                        Component c,
                        Graphics2D g)
                 throws IOException,
                        IllegalArgumentException
Loads a levelset from a file with the specified game mode.

Parameters:
filename - absolute path to levelset file
gameMode - e.g. SINGLE
c - parent component for drawing dialogs
g - graphics context for drawing
Returns:
e.g. LOAD_OK
Throws:
IOException
IllegalArgumentException

loadLevelSet

public int loadLevelSet(URL fileURL,
                        Graphics2D g)
                 throws IOException
Loads a levelset from the given location

Parameters:
fileURL - absolute location of levelset file
g - graphics context for drawing
Returns:
e.g. LOAD_OK
Throws:
IOException

loadLevelSet

public int loadLevelSet(URL fileURL,
                        int gameMode,
                        Component c,
                        Graphics2D g)
                 throws IOException,
                        IllegalArgumentException,
                        NullPointerException
Loads a levelset from a location with the specified game mode.

Parameters:
fileURL - absolute path to levelset file
gameMode - e.g. SINGLE
c - parent component for drawing dialogs
g - graphics context for drawing
Returns:
e.g. LOAD_OK
Throws:
IOException
IllegalArgumentException
NullPointerException

getLevelSet

protected LevelSet getLevelSet()
Returns the active levelset

Returns:
the loaded levelset

enableUnlocking

public void enableUnlocking()
Indicate that this levelset's levels have to be unlocked Note: Unlock status is reset each time a new levelset is loaded


scoringEnabled

public boolean scoringEnabled()
Indicates whether scoring is turned on Note: Scoring status is reset each time a new levelset is loaded

Returns:
true is scoring system it turned on

gameMode

public int gameMode()
Returns the currently set game mode

Returns:
e.g. SINGLE

getScore

public int getScore()
Returns total score up to now Note: Scoring status is reset each time a new levelset is loaded

Returns:
the current score. Note: If scoring is off this will return 0

setLevel

public void setLevel(int index)
Choose which level to play

Parameters:
index - the level number

setLevelSet

public void setLevelSet(LevelSet ls,
                        int gameMode,
                        boolean score,
                        Graphics2D g)
                 throws NullPointerException,
                        IllegalArgumentException
Loads a levelset straight from its native format.

Parameters:
ls - the levelset to load
gameMode - e.g. SINGLE
score - whether to enable scoring or not
g - graphics context to use for drawing
Throws:
NullPointerException
IllegalArgumentException

performMoves

public int performMoves(int keyP1,
                        int keyP2)
Moves one or both players (or executes control command, e.g. F9 key)


automaticMovesLeft

public boolean automaticMovesLeft()
Returns true if there are any automatic moves left


stopAndToggleTimer

public void stopAndToggleTimer()
Like in chess - stops one timer and activates it for the other player


unpauseTimer

public void unpauseTimer()

updateState

public void updateState(boolean requestMessages)

updateUI

public boolean updateUI(Point mouseLocation)

clickResult

public int clickResult(int button)
Indicate a mouse button has been pressed. Note: Use a call to updateUIb first to set the correct mouse location.

Parameters:
button - the mouse button
Returns:
QUIT if the close button has been pressed

getState

public int getState()
Returns the current game state (e.g. GAMEOVER)


levelHasNotStarted

public boolean levelHasNotStarted()
Checks whether the level has been started

Returns:
true if the level has been started

activateMediaMerge

public void activateMediaMerge()
Indicate that the MediaMerge tile should be shown in this levelset. Note: This is reset each time a new levelset is loaded


revokeMediaMergeTile

public void revokeMediaMergeTile()
Indicate that the MediaMerge tile should not be used anymore


activateTestMode

public void activateTestMode()
Indicate that the editor originating test mode is active Note: This is reset each time a new levelset is loaded


testModeActive

public boolean testModeActive()
Checks whether the (editor) test mode is on

Returns:
true if test mode is active

getGameMode

public int getGameMode()
Returns the current game mode

Returns:
e.g. SINGLE

setLives

public void setLives(int amount,
                     Graphics2D g)
              throws IllegalArgumentException
Sets number of lives player has at beginning of levelset. This also affects lives player currently has also accepts zero for infinite lives Note: number of lives is reset when a new level is loaded

Parameters:
amount - number of lives to give one or both players
g - graphics context to use for rendering
Throws:
IllegalArgumentException

draw

public void draw(Graphics2D g)
Depending on situation this will either render only the timer (i.e. if the GameTimer instance has requested a refresh) or everything


drawAll

public void drawAll(Graphics2D g)

currentFrameMode

public int currentFrameMode()
Returns what borders (frames) are being rendered

Returns:
see ScreenFrames class for possible return values