zinger.nibbles
Class Field
java.lang.Object
|
+--zinger.nibbles.Field
- All Implemented Interfaces:
- Timer.Listener
- public class Field
- extends java.lang.Object
- implements Timer.Listener
This is the game's engine. It keeps all the grid information and enforces the rules on which
entities can overtake (eat) which. It does not know anything about the presentation, other than
the fact that it's done by instances of Field.Plotter
.
- See Also:
Field.Plotter
Inner Class Summary |
class |
Field.GridChange
Represents a link in a queue of changes (deltas) to the grid. |
class |
Field.GridMirror
|
class |
Field.Plotter
This class separates data that is stored in its parent class from the presentation of that data. |
Constructor Summary |
Field(int width,
int height)
|
Method Summary |
private void |
add(Entity entity)
|
private void |
addChange(int x,
int y)
Adds a record of grid change to the change queue. |
(package private) void |
addTarget(int value,
SpaceOccupantDrawer drawer)
|
protected boolean |
claimSpace(int x,
int y,
SpaceOccupant s)
Enforces rules on what entity is stronger, which is determined by its level. |
(package private) SpaceOccupant |
createOccupant(int x,
int y,
Entity entity)
|
(package private) Snake |
createSnake(SnakeDriver driver,
SpaceOccupantDrawer drawer,
int reproductionCycle)
|
private Snake |
createSnake(SnakeDriver driver,
SpaceOccupantDrawer drawer,
int reproductionCycle,
int initialLength,
int x,
int y)
|
protected java.awt.Point |
findPosition(Entity entity)
|
protected java.awt.Point |
findPosition(Entity entity,
java.awt.Rectangle range)
|
Field.GridChange |
getAllChanges()
|
int |
getHeight()
|
Field.Plotter |
getInput()
|
Field.GridChange |
getLastChange()
|
int |
getWidth()
|
private void |
markForRemoval(Entity entity)
|
(package private) void |
positionTarget(Target target)
This finds a random position on the grid that is not taken and sticks the target there. |
void |
timeCall(Timer timer)
|
private void |
unmarkForRemoval(Entity entity)
|
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
lastChange
private Field.GridChange lastChange
plotters
protected final java.util.List plotters
- We can have as many presentation listeners hooked up to the same instance as we want.
input
private Field.Plotter input
grid
protected final SpaceOccupant[][] grid
range
protected final java.awt.Rectangle range
snakeDeploymentRange
protected final java.awt.Rectangle snakeDeploymentRange
entities
protected final java.util.Set entities
toRemove
protected final java.util.Set toRemove
Field
public Field(int width,
int height)
getLastChange
public Field.GridChange getLastChange()
getAllChanges
public Field.GridChange getAllChanges()
getWidth
public int getWidth()
getHeight
public int getHeight()
getInput
public Field.Plotter getInput()
timeCall
public void timeCall(Timer timer)
- Specified by:
timeCall
in interface Timer.Listener
claimSpace
protected boolean claimSpace(int x,
int y,
SpaceOccupant s)
- Enforces rules on what entity is stronger, which is determined by its level.
- See Also:
Entity.level
addChange
private void addChange(int x,
int y)
- Adds a record of grid change to the change queue.
- See Also:
lastChange
createOccupant
SpaceOccupant createOccupant(int x,
int y,
Entity entity)
findPosition
protected java.awt.Point findPosition(Entity entity)
findPosition
protected java.awt.Point findPosition(Entity entity,
java.awt.Rectangle range)
createSnake
private Snake createSnake(SnakeDriver driver,
SpaceOccupantDrawer drawer,
int reproductionCycle,
int initialLength,
int x,
int y)
createSnake
Snake createSnake(SnakeDriver driver,
SpaceOccupantDrawer drawer,
int reproductionCycle)
positionTarget
void positionTarget(Target target)
- This finds a random position on the grid that is not taken and sticks the target there.
markForRemoval
private void markForRemoval(Entity entity)
unmarkForRemoval
private void unmarkForRemoval(Entity entity)
add
private void add(Entity entity)
addTarget
void addTarget(int value,
SpaceOccupantDrawer drawer)