MaImplemented landOn in PathSquare
[AntiTD.git] / src / se / umu / cs / dit06ajnajs / ATDModel.java
blob3f27c031a33ad34d75d344a5bf74f7ea4e825d6d
1 package se.umu.cs.dit06ajnajs;
3 import java.awt.Dimension;
4 import java.awt.Image;
5 import java.awt.Point;
6 import java.util.ArrayList;
7 import java.util.List;
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 {
20 Player player;
21 List<Agent> agents;
22 List<Map> maps;
23 Map currentMap;
25 public ATDModel(List<Map> maps) {
26 this.agents = new ArrayList<Agent>();
27 this.maps = maps;
28 this.currentMap = maps.get(0); //MapBuilder.createMap();
31 public void addTower(Tower t) {
32 TowerSquare square = currentMap.getRandomFreeTowerSquare();
33 if (square != null) {
34 // If there is a free square, place tower
35 Point p = square.getPosition();
36 t.setPostition(p);
37 square.setTower(t);
39 //Register as observer for the neighbours in range
40 int shootRange = t.getRange();
41 int squareRange =
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);
52 agents.add(t);
53 } else {
54 System.out.println("No available towersquares");
60 public void addAgent(Agent agent) {
61 // TODO Auto-generated method stub
62 agents.add(agent);
65 public List<Agent> getAgents() {
66 // TODO Auto-generated method stub
67 return this.agents;
70 public Map getMap() {
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();