public class WorldModel
extends java.lang.Object
The WorldModel is also responsible for "stepping" the simulation. Each step fo the simulation consists of several phases:
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_CELL_SIZE
The default cell size.
|
static Offset |
EAST
Often used offset representing the neighboring cell to the east.
|
static Offset |
NORTH
Often used offset representing the neighboring cell to the north.
|
static Offset |
NORTHEAST
Often used offset representing the neighboring cell to the northeast.
|
static Offset |
NORTHWEST
Often used offset representing the neighboring cell to the northwest.
|
static Offset |
SOUTH
Often used offset representing the neighboring cell to the south.
|
static Offset |
SOUTHEAST
Often used offset representing the neighboring cell to the southeast.
|
static Offset |
SOUTHWEST
Often used offset representing the neighboring cell to the southwest.
|
static Offset |
WEST
Often used offset representing the neighboring cell to the west.
|
Constructor and Description |
---|
WorldModel()
Create a new, empty world model of default cell size.
|
WorldModel(int cellSize)
Create a new, empty world model of the given cell size.
|
Modifier and Type | Method and Description |
---|---|
void |
add(Thing t)
Add the given thing to the world.
|
void |
addView(WorldView v)
Add the given view.
|
void |
birth()
Add all items in the nursery to the world.
|
void |
doTurn()
The basic turn of the simulation consists of calling birth(),
action(), reap(), and notifyViews().
|
java.util.Iterator |
getThings()
Get all the things in the world.
|
java.util.List |
getThings(Thing t)
Get the neighbors of this thing, that is, those Things that
inhabit the same cell.
|
java.util.List |
getThings(Thing t,
java.util.List offSets)
Get the things that inhabit the cells that are in the given
list of directions from the cell inhabited by the given thing.
|
java.util.List |
getThings(Thing t,
Offset dir)
Get the things that inhabit the cell that is in the given
direction from the cell inhabited by the given thing.
|
void |
go()
Call init(), and then loop forever, calling doTurn() and sleeping
for the sleepTime.
|
void |
go(int cycles)
Call init(), and then loop for the given number of cycles.
|
void |
init()
Initialize the world.
|
void |
map(uwcse.sim.WorldModel.CallBack cb)
Map this call back over the world.
|
void |
notifyViews()
Notify the views to let them do their thing.
|
void |
remove(Thing t)
Remove a thing from the world map.
|
void |
setSleepTime(int newTime) |
int |
size()
Answer the number of things in the world.
|
java.lang.String |
toString() |
public static final Offset NORTH
public static final Offset SOUTH
public static final Offset EAST
public static final Offset WEST
public static final Offset NORTHEAST
public static final Offset NORTHWEST
public static final Offset SOUTHEAST
public static final Offset SOUTHWEST
public static final int DEFAULT_CELL_SIZE
public WorldModel()
public WorldModel(int cellSize)
public void setSleepTime(int newTime)
public java.lang.String toString()
toString
in class java.lang.Object
public java.util.List getThings(Thing t)
public java.util.List getThings(Thing t, Offset dir)
public java.util.List getThings(Thing t, java.util.List offSets)
public java.util.Iterator getThings()
public void remove(Thing t)
public void map(uwcse.sim.WorldModel.CallBack cb)
public int size()
public void add(Thing t)
public void addView(WorldView v)
public void init()
public void birth()
public void notifyViews()
public void go()
public void go(int cycles)
public void doTurn()