1 package se
.umu
.cs
.dit06ajnajs
;
3 import java
.awt
.Dimension
;
6 import java
.util
.ArrayList
;
8 import java
.util
.Observer
;
9 import java
.util
.logging
.Logger
;
11 import se
.umu
.cs
.dit06ajnajs
.agent
.Agent
;
12 import se
.umu
.cs
.dit06ajnajs
.agent
.Tower
;
13 import se
.umu
.cs
.dit06ajnajs
.map
.GoalSquare
;
14 import se
.umu
.cs
.dit06ajnajs
.map
.Map
;
15 import se
.umu
.cs
.dit06ajnajs
.map
.MapBuilder
;
16 import se
.umu
.cs
.dit06ajnajs
.map
.MapSquare
;
17 import se
.umu
.cs
.dit06ajnajs
.map
.PathSquare
;
18 import se
.umu
.cs
.dit06ajnajs
.map
.TowerSquare
;
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 addAgent(Agent agent
) {
75 // TODO Auto-generated method stub
79 public List
<Agent
> getAgents() {
80 // TODO Auto-generated method stub
85 return this.currentMap
;
88 public Image
getMapImage() {
89 return currentMap
.getMapImage();
92 public Dimension
getMapDimension() {
93 return currentMap
.getDimension();
96 public GoalSquare
[] getGoalSquares() {
97 return this.currentMap
.getGoalSquares();