wyvern.lib.classes.games.sokoban
Class SokobanLevel

java.lang.Object
  extended bywyvern.kernel.properties.PList
      extended bywyvern.kernel.maps.AbstractGameMap
          extended bywyvern.kernel.maps.DenseMap
              extended bywyvern.lib.classes.games.sokoban.SokobanLevel
All Implemented Interfaces:
Command, Container, GameMap, GameMap.UnloadMapConstants, Hookable, HookCallback, MethodHookable, MouseInterest, wyvern.kernel.lighting.Obstructions, PropertyList, SelfExternalizable

public class SokobanLevel
extends DenseMap
implements HookCallback, MouseInterest, Command

This class implements a single Sokoban level.

Version:
1.0, Jun 07, 1998
Author:
Steve Yegge

Nested Class Summary
 
Nested classes inherited from class wyvern.lib.GameMap
GameMap.UnloadMapConstants
 
Field Summary
 
Fields inherited from class wyvern.kernel.maps.DenseMap
addRemoveListeners_, cachedBounds_, count_, lighting_, objects_, outOfBoundsTerrain_, size_
 
Fields inherited from class wyvern.kernel.maps.AbstractGameMap
ambient_, changeList_, commands_, dark_, defaultTerrain_, dense_, dirtyRegions_, lights_, locals_, mapHooks_, monsters_, name_, opaqueMap_, path_, perPlayer_, players_, proxHooks_, roomHooks_, suspended_, suspendTime_, suspendTimer_, teleporters_, unloadImmediately_, unloading_, visUpdates_, vpath_
 
Fields inherited from class wyvern.kernel.properties.PList
readOnly_
 
Fields inherited from interface wyvern.lib.GameMap
MAX_HEIGHT, MAX_SEARCH_RADIUS, MAX_WIDTH
 
Fields inherited from interface wyvern.lib.PropertyList
PROPERTY_PACKAGE
 
Fields inherited from interface wyvern.lib.GameMap.UnloadMapConstants
MAP_CONTAINS_PLAYERS, MAP_NOT_LOADED, SUCCESS
 
Constructor Summary
SokobanLevel(Sokoban parent, int width, int height, int level)
          Constructs a new SokobanLevel.
 
Method Summary
 CommandEvent createEvent(CommandEvent event)
          Creates the event for one of our commands.
 boolean execute(CommandEvent event)
          Executes one of our commands.
 Location getExit()
          Returns the Location to dump the player on exiting the dungeon.
 int getLevel()
          Returns our level number.
 int getPushes()
          Returns the number of times a bag has been pushed successfully.
 java.util.List getSafePoints()
          Returns the safe-points list for the level.
 boolean handleMouse(Commandable agent, Point loc)
          (Try to) run to the location they clicked on.
 void hookEvent(java.lang.String hookname, CommandEvent event)
          Player moved, pushed, or whatever.
 boolean knowsCommand(java.lang.String cmd)
          Says which commands we provide.
 void mouseClicked(MouseCommandEvent event)
          Called when an agent clicks the mouse (any button) over the object.
 void setExit(java.lang.String path, int x, int y)
          Sets the exit map for this level.
 void setSafePoints(java.util.List points)
          Stores the safe-point list for this level.
 boolean undo(Commandable agent)
          Undoes the last push.
 
Methods inherited from class wyvern.kernel.maps.DenseMap
add, add, addIntensityArray, adjustIntensity, checkBounds, checkBounds, createLightMatrix, dismantle, getBounds, getLightLevel, getObjectCount, getOrCreatecell, getOutOfBoundsTerrain, getProperties, getPropertyList, getSize, initialize, initialize, isSparse, iterator, keySet, objectsAt, objectsInRect, registerAddRemoveListener, remove, remove, setOutOfBoundsTerrain, setOutOfBoundsTerrain, setSize, setTerrain, terrainAt, unregisterAddRemoveListener, visitRect
 
Methods inherited from class wyvern.kernel.maps.AbstractGameMap
addHook, addLight, addLocalArchetype, addMapLifecycleListener, addMethodHook, addMonster, addPlayer, addPlayerListener, addPropertyChangeListener, addPropertyChangeListener, addProximityHook, addRoomHook, addTeleporter, broadcast, broadcast, doneLoading, enableVisUpdates, findAt, findAt, findAt, findAt, findByName, findByName, findFreeSpot, findFreeSpot, findInRect, findTop, findTop, findTop, findUnder, fireMapLoaded, fireMapResumed, fireMapSuspended, fireMapUnloaded, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getArea, getClaim, getCommand, getDangerLevel, getDefaultTerrain, getExits, getFavorites, getHookList, getHooks, getLightingLevel, getLocalArchetype, getLocalArchetypes, getMonsterList, getMusic, getName, getObjectsAt, getPath, getPlayerList, getProfilingInfo, getPropertyChangeListeners, getPropertyChangeListeners, getProximityHookList, getResource, getRestartLoc, getRoomHookList, getStartLocation, getSuspendTime, getTerrainInfo, getTerrainRecord, getTerrainRecord, getUnloadDelay, getUpdateList, getVirtualPath, hasListeners, hasObstructions, initCommon, inMapEditor, invalidate, isBag, isEmpty, isEmpty, isInventory, isLit, isMap, isOpaque, isPerPlayer, isSuspended, isUnloaded, notifyPlayerListeners, readData, recomputeLights, registerCommand, removeFirst, removeHook, removeLight, removeLocalArchetype, removeMapLifecycleListener, removeMethodHook, removePlayer, removePlayerListener, removePropertyChangeListener, removePropertyChangeListener, removeProximityHook, removeRoomHook, removeTeleporter, resetOpaqueFlag, resetOpaqueFlag, resume, runFailedPostHook, runMethodHook, runPostHook, runPreHook, setAutoload, setDangerLevel, setDefaultTerrain, setDefaultTerrain, setFavorite, setLightingLevel, setLit, setName, setPath, setPerPlayer, setStartLocation, setTerrain, setUnloadDelay, shouldWrite, startSuspendTimer, startUnloadTimer, startUnloadTimer, suspend, toString, trackSpecialRemoves, unload, unregisterCommand, updateOpaque, updateTerrainCache, visitObjectsAt, visUpdate, wakeAllMonsters, wakeMonsters, wasAutoloaded, writeData
 
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, 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
 

Constructor Detail

SokobanLevel

public SokobanLevel(Sokoban parent,
                    int width,
                    int height,
                    int level)
Constructs a new SokobanLevel.

Method Detail

hookEvent

public void hookEvent(java.lang.String hookname,
                      CommandEvent event)
Player moved, pushed, or whatever.

Specified by:
hookEvent in interface HookCallback
Parameters:
hookname - the name of the hook, such as "movePreHook".
event - the CommandEvent encapsulating the event parameters

setExit

public void setExit(java.lang.String path,
                    int x,
                    int y)
Sets the exit map for this level.

Parameters:
path - the map path
x - map x
y - map y

getExit

public Location getExit()
Returns the Location to dump the player on exiting the dungeon.

Returns:
the "exit-map" location property, which is constructed from a string "exit" property and int "exit-x" and "exit-y" properties expected to be on the Sokoban archetype.

setSafePoints

public void setSafePoints(java.util.List points)
Stores the safe-point list for this level.

Parameters:
points - the list of safe points

getSafePoints

public java.util.List getSafePoints()
Returns the safe-points list for the level.

Returns:
the list of safe points

getLevel

public int getLevel()
Returns our level number.


getPushes

public int getPushes()
Returns the number of times a bag has been pushed successfully.


mouseClicked

public void mouseClicked(MouseCommandEvent event)
Called when an agent clicks the mouse (any button) over the object. Use event.consume() if you don't want the mouse event to continue being processed by other objects.

Specified by:
mouseClicked in interface MouseInterest
Parameters:
event - the command event. event.getAgent() will return the Player who clicked the mouse.

handleMouse

public boolean handleMouse(Commandable agent,
                           Point loc)
(Try to) run to the location they clicked on.


undo

public boolean undo(Commandable agent)
Undoes the last push.


knowsCommand

public boolean knowsCommand(java.lang.String cmd)
Says which commands we provide.

Specified by:
knowsCommand in interface Command
Parameters:
cmd - the entire command string, including arguments
Returns:
true if we want to handle the command

createEvent

public CommandEvent createEvent(CommandEvent event)
Creates the event for one of our commands.

Specified by:
createEvent in interface Command
Parameters:
event - a "blank" CommandEvent containing only the command text and the agent who's performing the command. This initial event is created by the originator of the event (e.g. the AI or player's command preprocessor).
Returns:
a CommandEvent subclass encapsulating this command's execution parameters and state. It should copy in the fields from the passed-in event.

execute

public boolean execute(CommandEvent event)
Executes one of our commands.

Specified by:
execute in interface Command
Parameters:
event - the CommandEvent to execute
Returns:
true if the event completed successfully, else false.