Class Facade

java.lang.Object
  extended by java.awt.Component
      extended by Facade
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class Facade
extends java.awt.Component

An interface between the GUI and the kernel classes in a checkers game.

Author:
See Also:
Serialized Form

Field Summary
 Player activePlayer
           
static int CLIENTGAME
           
static int HOSTGAME
           
static java.lang.String ID
           
static int LOCALGAME
           
 Player passivePlayer
           
static java.lang.String playerSwitch
           
 Board theBoard
           
 Driver theDriver
           
 LocalPlayer theLocalPlayer
           
static java.lang.String update
           
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Facade(Board newBoard, Driver newDriver)
          Constructor for the facade.
 
Method Summary
 void addActionListener(java.awt.event.ActionListener a)
          Adds an action listener to the facade
 void createPlayer(int num, int type)
          Create a player with the given type and player number.
 void endGameAccepted()
          Called when both players have clicked OK on the end game dialog box
 void generateActionPerformed()
          Generates an action.
 java.lang.String getPlayerName(int playerNum)
          Given a player number, returns the name associated with that number.
 int getTimer()
          Returns the timer value, how long each player get to take a turn
 int getTimerWarning()
          Returns the amount of time chosen for a warning that a player is near the end of his/her turn.
 void pressAcceptDraw()
          Tell the kernel that the user has accepted a draw.
 void pressDraw()
          Tell the kernel that the user has requested a draw.
 void pressQuit()
          Tell the kernel that the user has quit/resigned the game or quit the program
 void selectSpace(int space)
          This method should be called to select a space on the board, either as the starting point or the ending point for a move.
 void setGameMode(int mode)
          Set the game mode: a local game or a network game
 void setHost(java.net.URL host)
          Tell the kernel to connect to the specified host to start a network game.
 void setPlayerModes(Player active, Player passive)
          Set which players turn it is.
 void setPlayerName(int playerNum, java.lang.String name)
          Tell the kernel to associate the given name with the given player number.
 void setTimer(int time, int warning)
          Tell the kernel to set a time limit for each turn.
 void showEndGame(java.lang.String message)
          Display to local players that the game has ended with the message provided.
 void startGame()
          Call the driver and begin the game.
 Board stateOfBoard()
          Notifies everything of the sta eof the board
 int whosTurn()
          Return an int indicating which player's turn it is.
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, deliverEvent, disable, dispatchEvent, doLayout, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getAccessibleContext, getAlignmentX, getAlignmentY, getBackground, getBounds, getBounds, getColorModel, getComponentAt, getComponentAt, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeys, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMaximumSize, getMinimumSize, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, invalidate, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusCycleRoot, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, layout, list, list, list, list, list, locate, location, lostFocus, minimumSize, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paint, paintAll, postEvent, preferredSize, prepareImage, prepareImage, print, printAll, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocusInWindow, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeys, setFocusTraversalKeysEnabled, setFont, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle, update, validate
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

LOCALGAME

public static int LOCALGAME

HOSTGAME

public static int HOSTGAME

CLIENTGAME

public static int CLIENTGAME

update

public static java.lang.String update

playerSwitch

public static java.lang.String playerSwitch

ID

public static java.lang.String ID

theDriver

public Driver theDriver

theLocalPlayer

public LocalPlayer theLocalPlayer

theBoard

public Board theBoard

passivePlayer

public Player passivePlayer

activePlayer

public Player activePlayer
Constructor Detail

Facade

public Facade(Board newBoard,
              Driver newDriver)
Constructor for the facade. Initializes the data members.

Parameters:
newBoard - Board object Facade will manipulate.
newDriver - Driver object that will communicate with the Facade.
Method Detail

whosTurn

public int whosTurn()
Return an int indicating which player's turn it is. ( e.g. 1 for player 1 )

Returns:
int The number of the player whose turn it is.

setPlayerModes

public void setPlayerModes(Player active,
                           Player passive)
Set which players turn it is.

Parameters:
active - The active player
passive - The passive player

selectSpace

public void selectSpace(int space)
This method should be called to select a space on the board, either as the starting point or the ending point for a move. The Facade will interpret this selection and send a move on to the kernel when two spaces have been selected.

Parameters:
space - an int indicating which space to move to, according to the standard checkers numbering scheme, left to right and top to bottom.

pressQuit

public void pressQuit()
Tell the kernel that the user has quit/resigned the game or quit the program


pressDraw

public void pressDraw()
Tell the kernel that the user has requested a draw.


pressAcceptDraw

public void pressAcceptDraw()
Tell the kernel that the user has accepted a draw.


getPlayerName

public java.lang.String getPlayerName(int playerNum)
Given a player number, returns the name associated with that number.

Parameters:
playerNum - the number of a player
Returns:
string the name associated with playerNum

setPlayerName

public void setPlayerName(int playerNum,
                          java.lang.String name)
Tell the kernel to associate the given name with the given player number.

Parameters:
playerNum - the number of a player
name - the name that player should be given

setTimer

public void setTimer(int time,
                     int warning)
              throws java.lang.Exception
Tell the kernel to set a time limit for each turn. The time limit, i.e. the amount of time a player has during his turn before he is given a time warning, is specified by the parameter called time, in minutes. Tell the kernel to set a time limit for each turn. The warning time, i.e. the amount of time a player has during his turn after he is given a time warning, is specified by the parameter called time, in minutes.

Parameters:
time - the time limit for each turn, in seconds.
Throws:
java.lang.Exception

setHost

public void setHost(java.net.URL host)
Tell the kernel to connect to the specified host to start a network game.

Parameters:
host -

showEndGame

public void showEndGame(java.lang.String message)
Display to local players that the game has ended with the message provided.

Parameters:
message -

setGameMode

public void setGameMode(int mode)
                 throws java.lang.Exception
Set the game mode: a local game or a network game

Parameters:
the - mode of the game
Throws:
java.lang.Exception

getTimer

public int getTimer()
Returns the timer value, how long each player get to take a turn

Returns:
the amount of time each player has for a turn

getTimerWarning

public int getTimerWarning()
Returns the amount of time chosen for a warning that a player is near the end of his/her turn.

Returns:
the amount of warning time a player has

addActionListener

public void addActionListener(java.awt.event.ActionListener a)
Adds an action listener to the facade


endGameAccepted

public void endGameAccepted()
Called when both players have clicked OK on the end game dialog box


stateOfBoard

public Board stateOfBoard()
Notifies everything of the sta eof the board

Returns:
a Board object which is the state of the board

startGame

public void startGame()
Call the driver and begin the game.


generateActionPerformed

public void generateActionPerformed()
Generates an action. This is inhereted from Component


createPlayer

public void createPlayer(int num,
                         int type)
Create a player with the given type and player number.

Parameters:
num - Int for player number (either 1 or 2)
type - Int for type of player (Local, network, etc.)