wyvern.lib.classes.games
Class Chess

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

public class Chess
extends MapObject
implements MouseInterest

This class implements a 2-player chess 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 chessboard, 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 BISHOP
           
static int KING
           
static int KNIGHT
           
static int PAWN
           
static int QUEEN
           
static int ROOK
           
 
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
Chess()
           
 
Method Summary
 Rectangle getBounds()
          Returns the bounds of the board object.
 int[] getImageDescriptors()
          Returns the board's appearance.
 wyvern.lib.classes.games.ChessPiece getPiece(int x, int y)
          Returns the chess piece at the specified board location.
 wyvern.lib.classes.games.ChessPiece getPiece(Point loc)
          Returns the chess 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 chess-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.
 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 chess board in the map.
 void trySelection(Commandable agent, Point click)
          Attempts to select a game piece.
 
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

KING

public static final int KING
See Also:
Constant Field Values

QUEEN

public static final int QUEEN
See Also:
Constant Field Values

BISHOP

public static final int BISHOP
See Also:
Constant Field Values

KNIGHT

public static final int KNIGHT
See Also:
Constant Field Values

ROOK

public static final int ROOK
See Also:
Constant Field Values

PAWN

public static final int PAWN
See Also:
Constant Field Values
Constructor Detail

Chess

public Chess()
Method Detail

initialize

public void initialize()
Adds chess-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 chess 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 tile 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
Parameters:
xloc - map x location
yloc - map y location
Returns:
tile number

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.


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

trySelection

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


getPiece

public wyvern.lib.classes.games.ChessPiece getPiece(Point loc)
Returns the chess 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.ChessPiece getPiece(int x,
                                                    int y)
Returns the chess 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

restart

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