|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.ObjectSimModel
A SimModel is a basic simulation framework for simulations of collections of objects. SimThings can be added to the model, and SimViewers can ask to be notified regularly so they can display the world.
The simulation repeats the following cycle as many times as requested:
Birth - anything added to the simulation on the previous cycle
is added to the world.
Action - all SimThings are asked to perform their action() method
in some unpredictable order.
View - all SimViewers are notified
The birth and action operations are separated so new things added to the simulation in the middle of one cycle don't affect other actions on the same cycle (i.e., all actions on one cycle should be carried out with the existing population of things, without newly created things interacting with old ones in unexpected ways).
This particular simulation is unrealistic in that the object coordinates are the same as the display graphics coordinates. In a more realistic system, the object coordinates would be appropriate for the model and would be scaled by the viewer to fit the view.
Originally based on simulation framework developed by Ben Dugan for CSE142/3. CSE143 demo Au01, Sp03, Sp04
Constructor Summary | |
SimModel(int width,
int height)
Constructor for objects of class SimModel |
Method Summary | |
void |
add(SimThing t)
Add the given SimThing to the world after this cycle is complete. |
void |
addView(SimView v)
Add the given SimView to the list of viewers to be notified each cycle. |
int |
getHeight()
Return the vertical size of the simulated world |
List |
getThings()
Return a copy of the list of Things in the simulation at the beginning of the current cycle. |
int |
getWidth()
Return the horizontal size of the simulated world |
void |
go()
Run the simulation indefinitely |
void |
go(int nCycles)
Run the simulation for the requested number of cycles |
void |
pause()
Pause the simulation |
void |
resume()
Resume the simulation |
void |
stop()
Stop the simulation |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
public SimModel(int width, int height)
width
- Width of the simulated worldheight
- Height of the simulated worldMethod Detail |
public void add(SimThing t)
t
- the SimThing to be addedpublic void addView(SimView v)
v
- the new viewerpublic List getThings()
public int getWidth()
public int getHeight()
public void go(int nCycles)
nCycles
- number of cycles to runpublic void go()
public void pause()
public void resume()
public void stop()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |