public class SimpleBoard extends Object implements LevelBoard
LevelBoard implementation that utilizes
individual tile-locking to achieve maximum concurrency.
Internally, the board is represented as a 2D gride of tiles, each
of which are ManagedObject instances. Accesses and updates
only acquire the minimum number of tiles, which results in better
througput for a board with many active players.
This implementation uses a ScalableHashMap of points
instead of a ManagedReference<Tile>[][] to store its tiles
in order to reduce the amount of data that needs to be loaded for
each board access. For large boards, the ManagedReference
array would have imposed a significant data bottleneck.LevelBoard.ActionResult| Constructor and Description |
|---|
SimpleBoard(int width,
int height)
Creates a new instance of
SimpleBoard with an empty
tile set |
| Modifier and Type | Method and Description |
|---|---|
boolean |
addCharacterAt(int x,
int y,
CharacterManager mgr)
Tries to add a character at the given location.
|
boolean |
addItemAt(int x,
int y,
Item item)
Tries to add an item at the given location.
|
int[] |
getAt(int x,
int y)
Returns the stack of identifiers at the given position.
|
int |
getHeight()
Returns the height of this board.
|
LevelBoard.ActionResult |
getItem(int x,
int y,
CharacterManager mgr)
Tries to take an item on this tile.
|
int |
getWidth()
Returns the width of this board.
|
boolean |
isDark()
Returns whether or not this board is dark.
|
LevelBoard.ActionResult |
moveTo(int x,
int y,
CharacterManager mgr)
Moves the given character to the given location.
|
static SimpleBoard |
parse(StreamTokenizer stok,
Set<Integer> impassableSprites)
Creates a new instance of
SimpleBoard from the given
tokenized stream. |
boolean |
removeCharacterAt(int x,
int y,
CharacterManager mgr)
Tries to remove a character from the given location.
|
boolean |
removeItemAt(int x,
int y,
Item item)
Tries to remove an item from the given location.
|
void |
setAsConnector(int x,
int y,
Connector connector)
Sets the given space as a connector.
|
boolean |
testMove(int x,
int y,
CharacterManager mgr)
Tests to see if a move would be possible to the given location for
the given character.
|
public SimpleBoard(int width,
int height)
SimpleBoard with an empty
tile setwidth - the width of the boardheight - the height of the boardIllegalArgumentException - if height or width is
non-positivepublic static SimpleBoard parse(StreamTokenizer stok, Set<Integer> impassableSprites) throws IOException
SimpleBoard from the given
tokenized stream.stok - a StreamTokenizer that provides the boardimpassableSprites - the set of identifiers that are impassableIOException - if the stream isn't formatted correctlypublic void setAsConnector(int x,
int y,
Connector connector)
x - the x-coordinatey - the y-coordinateconnector - the Connectorpublic int getWidth()
public int getHeight()
public int[] getAt(int x,
int y)
public boolean isDark()
public boolean addCharacterAt(int x,
int y,
CharacterManager mgr)
addCharacterAt in interface LevelBoardx - the x-coordinatey - the y-coordinatemgr - the character's managerpublic boolean removeCharacterAt(int x,
int y,
CharacterManager mgr)
removeCharacterAt in interface LevelBoardx - the x-coordinatey - the y-coordinatemgr - the character's managerpublic boolean addItemAt(int x,
int y,
Item item)
addItemAt in interface LevelBoardx - the x-coordinatey - the y-coordinateitem - the item's managerpublic boolean removeItemAt(int x,
int y,
Item item)
removeItemAt in interface LevelBoardx - the x-coordinatey - the y-coordinateitem - the item's managerpublic boolean testMove(int x,
int y,
CharacterManager mgr)
testMove in interface LevelBoardx - the x-coordinatey - the y-coordinatemgr - the character's managerpublic LevelBoard.ActionResult moveTo(int x, int y, CharacterManager mgr)
addCharacterAt.moveTo in interface LevelBoardx - the x-coordinatey - the y-coordinatemgr - the character's managerpublic LevelBoard.ActionResult getItem(int x, int y, CharacterManager mgr)
moveTo,
this actually will remove items from the tile if they are
successfully taken.getItem in interface LevelBoardmgr - the manager for a characterx - the x-coordinatey - the y-coordinateCopyright © 2013. All Rights Reserved.