1 package se
.umu
.cs
.dit06ajnajs
;
3 import java
.awt
.Dimension
;
6 import java
.util
.ArrayList
;
8 import java
.util
.Observer
;
10 import se
.umu
.cs
.dit06ajnajs
.agent
.Agent
;
11 import se
.umu
.cs
.dit06ajnajs
.agent
.Tower
;
12 import se
.umu
.cs
.dit06ajnajs
.map
.GoalSquare
;
13 import se
.umu
.cs
.dit06ajnajs
.map
.Map
;
14 import se
.umu
.cs
.dit06ajnajs
.map
.MapBuilder
;
15 import se
.umu
.cs
.dit06ajnajs
.map
.MapSquare
;
16 import se
.umu
.cs
.dit06ajnajs
.map
.PathSquare
;
17 import se
.umu
.cs
.dit06ajnajs
.map
.TowerSquare
;
19 public class ATDModel
{
25 public ATDModel(List
<Map
> maps
) {
26 this.agents
= new ArrayList
<Agent
>();
28 this.currentMap
= maps
.get(0); //MapBuilder.createMap();
31 public void addTower(Tower t
) {
32 TowerSquare square
= currentMap
.getRandomFreeTowerSquare();
34 // If there is a free square, place tower
35 Point p
= square
.getPosition();
39 //Register as observer for the neighbours in range
40 int shootRange
= t
.getRange();
42 (int) Math
.ceil((shootRange
- AntiTD
.SQUARE_SIZE
*0.5)
43 / (AntiTD
.SQUARE_SIZE
));
45 List
<MapSquare
> neighbours
46 = this.currentMap
.getNeighbours(square
, squareRange
);
47 for (MapSquare neighbour
: neighbours
) {
48 if(neighbour
instanceof PathSquare
) {
49 neighbour
.addObserver((Observer
) square
);
54 System
.out
.println("No available towersquares");
60 public void addAgent(Agent agent
) {
61 // TODO Auto-generated method stub
65 public List
<Agent
> getAgents() {
66 // TODO Auto-generated method stub
71 return this.currentMap
;
74 public Image
getMapImage() {
75 return currentMap
.getMapImage();
78 public Dimension
getMapDimension() {
79 return currentMap
.getDimension();
82 public GoalSquare
[] getGoalSquares() {
83 return this.currentMap
.getGoalSquares();