1 package se
.umu
.cs
.dit06ajnajs
;
3 import java
.awt
.Graphics
;
6 import se
.umu
.cs
.dit06ajnajs
.agent
.Agent
;
7 import se
.umu
.cs
.dit06ajnajs
.agent
.Direction
;
8 import se
.umu
.cs
.dit06ajnajs
.agent
.FootmanUnit
;
10 public class ATDController
{
12 private final int FRAMES_PER_SECOND
= 20;
14 private ATDModel model
;
17 private boolean running
;
18 private Thread animationThread
;
20 public ATDController() {
21 // Create model and view
22 model
= new ATDModel();
23 view
= new ATDView(model
);
25 model
.addAgent(new FootmanUnit(100,200, 20, 20, Direction
.UP
));
28 animationThread
= new Thread(new AnimationThread());
29 animationThread
.start();
34 private class AnimationThread
implements Runnable
{
38 // TODO Auto-generated method stub
41 List
<Agent
> agents
= model
.getAgents();
42 for (Agent agent
: agents
) {
48 //Graphics g = view.getGraphics();
49 for (Agent agent
: agents
) {
50 ((Paintable
) agent
).paint(g
);
53 // Try to keep a given number of frames per second.
55 Thread
.sleep(1000 / FRAMES_PER_SECOND
);
56 } catch (InterruptedException e
) {
57 System
.err
.println("Error in thread, exiting.");