1 package se
.umu
.cs
.dit06ajnajs
;
3 import java
.awt
.Dimension
;
6 import java
.util
.ArrayList
;
8 import java
.util
.logging
.Logger
;
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
.MapSquare
;
15 import se
.umu
.cs
.dit06ajnajs
.map
.PathSquare
;
16 import se
.umu
.cs
.dit06ajnajs
.map
.TowerSquare
;
17 import se
.umu
.cs
.dit06ajnajs
.map
.StartSquare
;
18 import se
.umu
.cs
.dit06ajnajs
.agent
.Unit
;
20 public class ATDModel
{
21 private static Logger logger
= Logger
.getLogger("AntiTD");
28 public ATDModel(List
<Map
> maps
) {
29 this.agents
= new ArrayList
<Agent
>();
31 this.currentMap
= maps
.get(0); //MapBuilder.createMap();
34 public void addTower(Tower t
) {
35 TowerSquare square
= currentMap
.getRandomFreeTowerSquare();
37 System
.out
.println("Adding tower!");
38 System
.out
.println("Free TowerSquare has point @ (" + square
.getX() + ", " + square
.getY() + ")");
39 System
.out
.println("Free TowerSquare has centerpoint @ (" + square
.getCenterX() + ", " + square
.getCenterY() + ")");
40 // If there is a free square, place tower in the center of square
41 Point tPos
= new Point(square
.getCenterX() - (t
.getWidth()/2)
42 , square
.getCenterY() - (t
.getHeight()/2));
46 System
.out
.println("Tower placed @ (" + tPos
.x
+ ", " + tPos
.y
+ ")");
48 //Register as observer for the neighbours in range
49 int shootRange
= t
.getRange();
51 (int) Math
.ceil((shootRange
- AntiTD
.SQUARE_SIZE
*0.5)
52 / (AntiTD
.SQUARE_SIZE
));
54 List
<MapSquare
> neighbours
55 = this.currentMap
.getNeighbours(square
, squareRange
);
56 logger
.info("There are >" + neighbours
.size()
57 + "< neighbours in range >" + t
.getRange() + "< pixels");
59 for (MapSquare neighbour
: neighbours
) {
60 if (neighbour
instanceof PathSquare
) {
61 logger
.info("Adding tower-observer: " + t
62 + " to: " + neighbour
);
63 neighbour
.addObserver(t
);
68 System
.out
.println("No available towersquares");
74 public void addUnit(Unit unit
) {
75 // TODO Auto-generated method stub
76 StartSquare startSquare
= this.currentMap
.getActiveStartSquare();
77 unit
.setCenterX(startSquare
.getCenterX());
78 unit
.setCenterY(startSquare
.getCenterY());
79 unit
.setMap(this.currentMap
);
80 unit
.setDirection(startSquare
.getStartDirection());
81 // TODO add agent to startSquare set x y map and direction
85 public List
<Agent
> getAgents() {
86 // TODO Auto-generated method stub
91 return this.currentMap
;
94 public Image
getMapImage() {
95 return currentMap
.getMapImage();
98 public Dimension
getMapDimension() {
99 return currentMap
.getDimension();
102 public GoalSquare
[] getGoalSquares() {
103 return this.currentMap
.getGoalSquares();