Added temporary laser beeem!
[AntiTD.git] / src / se / umu / cs / dit06ajnajs / ATDModel.java
blobf8e6b04bcb55544a1da27be1d5627e2154cc12af
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;
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");
23 Player player;
24 List<Agent> agents;
25 List<Map> maps;
26 Map currentMap;
28 public ATDModel(List<Map> maps) {
29 this.agents = new ArrayList<Agent>();
30 this.maps = maps;
31 this.currentMap = maps.get(0); //MapBuilder.createMap();
34 public void addTower(Tower t) {
35 TowerSquare square = currentMap.getRandomFreeTowerSquare();
36 if (square != null) {
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));
43 t.setPostition(tPos);
44 square.setTower(t);
46 System.out.println("Tower placed @ (" + tPos.x + ", " + tPos.y + ")");
48 //Register as observer for the neighbours in range
49 int shootRange = t.getRange();
50 int squareRange =
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);
66 agents.add(t);
67 } else {
68 System.out.println("No available towersquares");
74 public void addAgent(Agent agent) {
75 // TODO Auto-generated method stub
76 agents.add(agent);
79 public List<Agent> getAgents() {
80 // TODO Auto-generated method stub
81 return this.agents;
84 public Map getMap() {
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();