de.htwdd.rosenkoenig.gui
Class GameLogger

java.lang.Object
  extended by de.htwdd.rosenkoenig.gui.GameLogger
All Implemented Interfaces:
GameObserver, GUI

public class GameLogger
extends java.lang.Object
implements GUI, GameObserver

"GUI" that logs all actions (log4j level: INFO). Use this class to


Field Summary
private static int guiIndex
          An index to distinguish different GameLoggers.
private  org.apache.log4j.Logger log
          log4j logger
 
Constructor Summary
GameLogger()
          Default constructor: initializes log4j and generates an index for the current GUI
 
Method Summary
 void activatePlayer(Color color, boolean activate)
          Activate or deactivate the player's name string.
 void cardSelected()
          This function is called whenever the player selected a card.
 void disablePlayer(Color color)
          Disables all controls of a single player.
 void drawDeckSelected()
          This function is called whenever the player drew a card.
 void enableDrawDeck(ImageState state)
          Enables / disables the draw deck.
 void enableEndTurn(ImageState state)
          Enables / disables the GUI element that ends a player's turn
 void gameEnded()
          This function is called after the game has ended.
 void gameStarted()
          This function is called upon startup of the game.
 void hideScoreChange(Color player)
          This method tells the GUI to hide a player's score increase.
 void initGUI(Game game, java.lang.String nameRed, java.lang.String nameWhite)
          Use this method to perform initialization.
 void knightsToggled()
          This function is called whenever the player's knights have been toggled.
 void redrawGUI()
          forces the GUI to show all changes taken since the last call of redrawGUI.
 void setBoard(Color[][] color)
          setBoard is called to replace the complete board.
 void setCards(Color color, java.util.List<Card> cards)
          This method is called whenever a player's card deck has changed and sets a player's card deck.
 void setCardState(Color color, ImageState state, int card, boolean knightable)
          setCardState is called whenever a card's state has changed.
 void setCrown(Position position)
          This method is called to specify the position of the crown on the board.
 void setDrawDeck(int number)
          Sets the number of cards left in the draw deck.
 void setKnights(Color color, int number)
          Sets the number of knights a player has left.
 void setKnightState(Color color, ImageState state)
          This method is called whenever a player's knights are enabled or disabled.
 void setPlayedDeck(int number, Card playedCard)
          Sets the number of cards left in the played cards deck.
 void setScore(Color color, int score)
          Updates a player's score.
 void setScoreChange(Color color, int score)
          After the player selects the card he wants to play, the GUI shows the possible score increase.
 void setStone(Color color, Position position, boolean perhaps)
          Sets a stone on the board.
 void turnEnded()
          This function is called whenever a player's turn has ended i.e. the user clicked the OK button.
 void turnStarted()
          This function is called whenever a player's turn has started.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

guiIndex

private static int guiIndex
An index to distinguish different GameLoggers.


log

private org.apache.log4j.Logger log
log4j logger

Constructor Detail

GameLogger

public GameLogger()
Default constructor: initializes log4j and generates an index for the current GUI

Method Detail

redrawGUI

public void redrawGUI()
forces the GUI to show all changes taken since the last call of redrawGUI.

Specified by:
redrawGUI in interface GUI

setCards

public void setCards(Color color,
                     java.util.List<Card> cards)
This method is called whenever a player's card deck has changed and sets a player's card deck.

Specified by:
setCards in interface GUI
Parameters:
color - player
cards - card deck (up to five cards)

setCardState

public void setCardState(Color color,
                         ImageState state,
                         int card,
                         boolean knightable)
setCardState is called whenever a card's state has changed.

Specified by:
setCardState in interface GUI
Parameters:
color - player
state - enabled, disabled, selected
card - index of the card that will be changed
knightable - if set to true, the selected card is marked knightable

setStone

public void setStone(Color color,
                     Position position,
                     boolean perhaps)
Sets a stone on the board. This method is also called if a stone has changed its color.

Specified by:
setStone in interface GUI
Parameters:
color - color of the stone or null to remove the stone
position - the stone's position
perhaps - if set to true, the stone is drawn "misty"

setBoard

public void setBoard(Color[][] color)
setBoard is called to replace the complete board.

Specified by:
setBoard in interface GUI
Parameters:
color - array (dimensions habe to be 9x9) of stones. A color represents a stone, null represents an empty field

setKnights

public void setKnights(Color color,
                       int number)
Sets the number of knights a player has left.

Specified by:
setKnights in interface GUI
Parameters:
color - player
number - number of knights left

setKnightState

public void setKnightState(Color color,
                           ImageState state)
This method is called whenever a player's knights are enabled or disabled.

Specified by:
setKnightState in interface GUI
Parameters:
color - player
state - enabled, disabled

setScore

public void setScore(Color color,
                     int score)
Updates a player's score.

Specified by:
setScore in interface GUI
Parameters:
color - player
score - new score

disablePlayer

public void disablePlayer(Color color)
Disables all controls of a single player.

Specified by:
disablePlayer in interface GUI
Parameters:
color - player

activatePlayer

public void activatePlayer(Color color,
                           boolean activate)
Activate or deactivate the player's name string. This method is called at the beginning and at the end of each turn.

Specified by:
activatePlayer in interface GUI
Parameters:
color - the player's color
activate - whether to activate the player or not

setScoreChange

public void setScoreChange(Color color,
                           int score)
After the player selects the card he wants to play, the GUI shows the possible score increase.

Specified by:
setScoreChange in interface GUI
Parameters:
color - player
score - score increase

setDrawDeck

public void setDrawDeck(int number)
Sets the number of cards left in the draw deck.

Specified by:
setDrawDeck in interface GUI
Parameters:
number - number of cards left

setPlayedDeck

public void setPlayedDeck(int number,
                          Card playedCard)
Sets the number of cards left in the played cards deck.

Specified by:
setPlayedDeck in interface GUI
Parameters:
number - number of cards left
playedCard - the card that was played last

enableDrawDeck

public void enableDrawDeck(ImageState state)
Enables / disables the draw deck.

Specified by:
enableDrawDeck in interface GUI
Parameters:
state - enabled or disabled

enableEndTurn

public void enableEndTurn(ImageState state)
Enables / disables the GUI element that ends a player's turn

Specified by:
enableEndTurn in interface GUI
Parameters:
state - enabled or disabled

hideScoreChange

public void hideScoreChange(Color player)
This method tells the GUI to hide a player's score increase.

Specified by:
hideScoreChange in interface GUI
Parameters:
player - the player whose score increase is to be hidden

initGUI

public void initGUI(Game game,
                    java.lang.String nameRed,
                    java.lang.String nameWhite)
Use this method to perform initialization.

Specified by:
initGUI in interface GUI
Parameters:
game - the game this GUI belongs to
nameRed - the red player's name
nameWhite - the white player's name
See Also:
Game

setCrown

public void setCrown(Position position)
This method is called to specify the position of the crown on the board.

Specified by:
setCrown in interface GUI
Parameters:
position - the crown's position

drawDeckSelected

public void drawDeckSelected()
This function is called whenever the player drew a card. The drawn card is the last card in the user's card set (the ArrayList cards).

Specified by:
drawDeckSelected in interface GameObserver

cardSelected

public void cardSelected()
This function is called whenever the player selected a card. You can use Game.getNextCard() to obtain the card selected by the user. Use this function to persist the information about the player's played card.

Specified by:
cardSelected in interface GameObserver

gameEnded

public void gameEnded()
This function is called after the game has ended. You can use this function for example to store a user's high score.

Specified by:
gameEnded in interface GameObserver

gameStarted

public void gameStarted()
This function is called upon startup of the game.

Specified by:
gameStarted in interface GameObserver

knightsToggled

public void knightsToggled()
This function is called whenever the player's knights have been toggled. It does not imply that the user played a card using the knight. It just informs that the knights were (de)selected.

Specified by:
knightsToggled in interface GameObserver

turnEnded

public void turnEnded()
This function is called whenever a player's turn has ended i.e. the user clicked the OK button. The Player's getter can then be used to retreive the required information about the game and the players. Information about the card played by the user (if he/she played or drew) cannot be obtained at this point. These information must be persisted in functions like knightsToggled or cardSelected.

Specified by:
turnEnded in interface GameObserver

turnStarted

public void turnStarted()
This function is called whenever a player's turn has started.

Specified by:
turnStarted in interface GameObserver