wyvern.lib.classes.games
Class Checkers

java.lang.Object
  extended bywyvern.kernel.properties.PList
      extended bywyvern.kernel.maps.MapObject
          extended bywyvern.lib.classes.games.Checkers
All Implemented Interfaces:
Broadcaster, GameObject, MethodHookable, MouseInterest, PropertyList

public class Checkers
extends MapObject
implements MouseInterest

This class implements a 2-player checkers game with human-sized pieces. When placed in a map at location (x,y), it treats (x,y) as its upper-left corner, creates an 8x8 checkerboard, and populates it with pieces. It also creates 2 "thrones" for players to sit in and begin a game.

Version:
1.0, Sep 21, 1998
Author:
Steve Yegge

Field Summary
static int KING
           
static int PIECE
           
static java.lang.String[] titles
           
 
Fields inherited from class wyvern.kernel.maps.MapObject
IN_MAP_EDITOR, listenerList_
 
Fields inherited from class wyvern.kernel.properties.PList
readOnly_
 
Fields inherited from interface wyvern.lib.PropertyList
PROPERTY_PACKAGE
 
Constructor Summary
Checkers()
           
 
Method Summary
 Point boardToMap(int x, int y)
          Returns a point in board coordinates.
 Point boardToMap(Point p)
          Returns a point in board coordinates.
 void checkKing(Commandable agent, wyvern.lib.classes.games.Checkers.Piece p)
          Possibly turns a piece into a King after a move.
 boolean doMove(Commandable agent, Point dest)
          Attempts the move.
 Rectangle getBounds()
          Returns the bounds of the board object.
 int[] getImageDescriptors()
          Returns the board's appearance.
 wyvern.lib.classes.games.Checkers.Piece getPiece(int x, int y)
          Returns the checkers piece at the specified board location.
 wyvern.lib.classes.games.Checkers.Piece getPiece(Point loc)
          Returns the checkers piece at the specified map location.
 int getTile(int xloc, int yloc)
          Overrides MapObject.getTile().
 void handleMouse(Commandable agent, Point click)
          Moves a piece.
 void initialize()
          Adds checkers-specific properties.
 void initPieces()
          Creates all the pieces and sets them in their starting places.
 boolean isEmpty(int x, int y)
          Returns true if the specified board location is empty.
 boolean isEmpty(Point p)
          Returns true if the specified board location is empty.
 Point mapToBoard(int x, int y)
          Returns a point in board coordinates.
 Point mapToBoard(Point p)
          Returns a point in board coordinates.
 void mouseClicked(MouseCommandEvent event)
          Handles a mouse-click.
 void restart()
          Clears the current game and starts over.
 void setMap(GameMap map, int x, int y)
          Sets the checkers board in the map.
 void trySelection(Commandable agent, Point click)
          Attempts to select a game piece for moving.
 
Methods inherited from class wyvern.kernel.maps.MapObject
addContainerChangeListener, addDefaultProperty, addMapChangeListener, addMapMotionListener, addMethodHook, addMotionTracker, addObjectTracker, addPrefix, addSuffix, addToMap, bless, broadcast, broadcast, broadcast, broadcast, broadcast, canEnter, canEnterBlockedBy, canMove, canMove, canMoveBlockedBy, canMoveBlockedBy, canMoveTo, canMoveToBlockedBy, checkDrop, curse, cycleFrame, destroy, ensureListenerList, ensureWeight, externalize, fireContainerEntered, fireContainerExited, fireEnteredMap, fireExitedMap, fireMovedInMap, getAlpha, getAppearance, getArchetype, getBaseName, getBaseWeight, getBitmap, getCanonicalClassName, getCategory, getContainer, getCreator, getDamagedDescription, getDescription, getDirection, getGenderPossessive, getGenderPronoun, getImage, getImageDescriptor, getLayer, getLocations, getMap, getMapLink, getMaterial, getMaterialDescription, getMover, getOwningPlayer, getParentMap, getPrefixes, getQuantity, getReferenceLoc, getRelativeLocs, getShortDesc, getSuffixes, getTile, getValue, getWeight, groupString, inContainer, initLocs, inMapEditor, invalidate, invalidateImage, invalidateParent, invalidateText, isAnimated, isAttackable, isBlessed, isCommandable, isCursed, isDamned, isGroupable, isIdentified, isMonster, isMonsterOrPlayer, isPlayer, isTerrain, isUncursed, isUnpaid, isWizard, makeClone, markPaid, markUnpaid, move, occupies, positionAt, positionAtMap, remove, removeContainerChangeListener, removeFromMap, removeMapChangeListener, removeMapMotionListener, removeMethodHook, removeMotionTracker, removeObjectTracker, removePrefix, removeSuffix, runMethodHook, setAlpha, setAnimated, setBitmap, setCategory, setContainer, setDefaultBitmap, setDefaultCategory, setDefaultDesc, setDefaultImage, setDefaultIntProperty, setDefaultLayer, setDefaultMaterial, setDefaultProperty, setDefaultShortDesc, setDirection, setImage, setImage, setLayer, setLocations, setMapLink, setQuantity, setShape, setSize, setTransientSize, setWeight, setWeight, teleport, toString, updateMapLocation
 
Methods inherited from class wyvern.kernel.properties.PList
addProperty, addTransientProperty, adjustDoubleProperty, adjustIntProperty, adjustLongProperty, adjustTransientDoubleProperty, adjustTransientIntProperty, adjustTransientLongProperty, countLocalProperties, debugProperties, dismantlePropertyList, getDoubleProperty, getInheritedProperty, getInteger, getIntProperty, getLocalProperties, getLocalProperty, getLongProperty, getParent, getPersistentDoubleProperty, getPersistentIntProperty, getPersistentLocalProperties, getPersistentLongProperty, getPersistentProperty, getProfilingInfo, getProperties, getProperties, getPropertiesIncludingTransients, getPropertiesIncludingTransients, getProperty, getSerializableProperties, getSerializableProperty, getStringProperty, getTransientDoubleProperty, getTransientIntProperty, getTransientLongProperty, getTransientProperties, getTransientProperty, hasLocalProperty, hasPersistentProperty, hasProperty, hasTransientProperty, inheritProperty, isReadOnly, isRemoved, isTransientlyRemoved, printLocalProperties, printProperties, printProperties, printTransientProperties, removeProperty, removeTransientProperty, setDoubleProperty, setIntProperty, setLongProperty, setParent, setProperty, setReadOnly, setTransientDoubleProperty, setTransientIntProperty, setTransientLongProperty, setTransientProperty, toString, transientlyRemoveProperty
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface wyvern.lib.PropertyList
addProperty, addTransientProperty, adjustDoubleProperty, adjustIntProperty, adjustLongProperty, adjustTransientDoubleProperty, adjustTransientIntProperty, adjustTransientLongProperty, countLocalProperties, getDoubleProperty, getInheritedProperty, getIntProperty, getLocalProperties, getLocalProperty, getLongProperty, getParent, getPersistentDoubleProperty, getPersistentIntProperty, getPersistentLocalProperties, getPersistentLongProperty, getPersistentProperty, getProperties, getProperties, getPropertiesIncludingTransients, getPropertiesIncludingTransients, getProperty, getSerializableProperties, getSerializableProperty, getStringProperty, getTransientDoubleProperty, getTransientIntProperty, getTransientLongProperty, getTransientProperties, getTransientProperty, hasLocalProperty, hasPersistentProperty, hasProperty, hasTransientProperty, inheritProperty, isReadOnly, isRemoved, isTransientlyRemoved, printLocalProperties, printProperties, printProperties, printTransientProperties, removeProperty, removeTransientProperty, setDoubleProperty, setIntProperty, setLongProperty, setParent, setProperty, setReadOnly, setTransientDoubleProperty, setTransientIntProperty, setTransientLongProperty, setTransientProperty, toString, transientlyRemoveProperty
 

Field Detail

PIECE

public static final int PIECE
See Also:
Constant Field Values

KING

public static final int KING
See Also:
Constant Field Values

titles

public static final java.lang.String[] titles
Constructor Detail

Checkers

public Checkers()
Method Detail

initialize

public void initialize()
Adds checkers-specific properties.

Specified by:
initialize in interface GameObject
Overrides:
initialize in class MapObject

setMap

public void setMap(GameMap map,
                   int x,
                   int y)
Sets the checkers board in the map.

Specified by:
setMap in interface GameObject
Overrides:
setMap in class MapObject

getImageDescriptors

public int[] getImageDescriptors()
Returns the board's appearance.

Specified by:
getImageDescriptors in interface GameObject
Overrides:
getImageDescriptors in class MapObject
Returns:
an int array of (x, y, database bitmap number) triples.

getTile

public int getTile(int xloc,
                   int yloc)
Overrides MapObject.getTile(). Required for all disjoint objects.

Specified by:
getTile in interface GameObject
Overrides:
getTile in class MapObject

getBounds

public Rectangle getBounds()
Returns the bounds of the board object.

Specified by:
getBounds in interface GameObject
Overrides:
getBounds in class MapObject

initPieces

public void initPieces()
Creates all the pieces and sets them in their starting places.


mapToBoard

public Point mapToBoard(Point p)
Returns a point in board coordinates.


mapToBoard

public Point mapToBoard(int x,
                        int y)
Returns a point in board coordinates.


boardToMap

public Point boardToMap(int x,
                        int y)
Returns a point in board coordinates.


boardToMap

public Point boardToMap(Point p)
Returns a point in board coordinates.


mouseClicked

public void mouseClicked(MouseCommandEvent event)
Handles a mouse-click.

Specified by:
mouseClicked in interface MouseInterest
Parameters:
event - the mouse event

handleMouse

public void handleMouse(Commandable agent,
                        Point click)
Moves a piece.

Parameters:
agent - the player doing the move
click - the point where they clicked, in map coordinates

getPiece

public wyvern.lib.classes.games.Checkers.Piece getPiece(Point loc)
Returns the checkers piece at the specified map location.

Parameters:
loc - the board position (in MAP coordinates, not board coords)
Returns:
the piece there, or null if the position is unoccupied

getPiece

public wyvern.lib.classes.games.Checkers.Piece getPiece(int x,
                                                        int y)
Returns the checkers piece at the specified board location.

Parameters:
x - the board x position in BOARD coordinates
y - the board y position in BOARD coordinates

isEmpty

public boolean isEmpty(int x,
                       int y)
Returns true if the specified board location is empty.

Parameters:
x - the x position in BOARD coordinates, where the upper-left corner (black queen's rook) is (0, 0).
y - the y position in BOARD coordinates

isEmpty

public boolean isEmpty(Point p)
Returns true if the specified board location is empty.

Parameters:
p - the x,y position in BOARD coordinates, where the upper-left corner of the board is (0,0).

trySelection

public void trySelection(Commandable agent,
                         Point click)
Attempts to select a game piece for moving.


doMove

public boolean doMove(Commandable agent,
                      Point dest)
Attempts the move.

Parameters:
agent - the agent doing the move
dest - the proposed destination for the move, in map coords
Returns:
true if we can move there.

checkKing

public void checkKing(Commandable agent,
                      wyvern.lib.classes.games.Checkers.Piece p)
Possibly turns a piece into a King after a move.

Parameters:
agent - the player
p - the piece

restart

public void restart()
Clears the current game and starts over.