From ae7b6672bd37126efb7ff64b011ae0e414e274c9 Mon Sep 17 00:00:00 2001 From: Andreas Jakobsson Date: Tue, 16 Dec 2008 21:06:50 +0100 Subject: [PATCH] =?utf8?q?Massor=20sm=C3=A5=20=C3=A4ndringar...?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- src/se/umu/cs/dit06ajnajs/ATDController.java | 5 +++-- src/se/umu/cs/dit06ajnajs/ATDModel.java | 19 +++++++++++++++++++ src/se/umu/cs/dit06ajnajs/agent/Agent.java | 2 +- src/se/umu/cs/dit06ajnajs/agent/BasicTower.java | 2 +- src/se/umu/cs/dit06ajnajs/agent/FootmanUnit.java | 6 ++++-- src/se/umu/cs/dit06ajnajs/agent/Tower.java | 5 ++++- src/se/umu/cs/dit06ajnajs/agent/Unit.java | 14 ++++++++++++-- 7 files changed, 44 insertions(+), 9 deletions(-) diff --git a/src/se/umu/cs/dit06ajnajs/ATDController.java b/src/se/umu/cs/dit06ajnajs/ATDController.java index 68b55ee..56dfeb7 100644 --- a/src/se/umu/cs/dit06ajnajs/ATDController.java +++ b/src/se/umu/cs/dit06ajnajs/ATDController.java @@ -37,7 +37,8 @@ public class ATDController { model.addAgent(new FootmanUnit(-20,100, 20, 20, 4, Direction.RIGHT)); model.addAgent(new FootmanUnit(-20,150, 20, 20, 2, Direction.RIGHT)); - model.addTower(new BasicTower(20, 20, 10, 1)); + model.addTower(new BasicTower(20, 20, 10, (int) (AntiTD.SQUARE_SIZE * 1.5))); + model.addTower(new BasicTower(20, 20, 10, (int) (AntiTD.SQUARE_SIZE * 2.5))); initGame(); running = true; @@ -60,7 +61,7 @@ public class ATDController { // Update all agents List agents = model.getAgents(); for (Agent agent : agents) { - agent.update(); + agent.act(); } // Repaint all agents diff --git a/src/se/umu/cs/dit06ajnajs/ATDModel.java b/src/se/umu/cs/dit06ajnajs/ATDModel.java index 786eb16..f56b989 100644 --- a/src/se/umu/cs/dit06ajnajs/ATDModel.java +++ b/src/se/umu/cs/dit06ajnajs/ATDModel.java @@ -9,6 +9,8 @@ import se.umu.cs.dit06ajnajs.agent.Agent; import se.umu.cs.dit06ajnajs.agent.Tower; import se.umu.cs.dit06ajnajs.map.Map; import se.umu.cs.dit06ajnajs.map.MapBuilder; +import se.umu.cs.dit06ajnajs.map.MapSquare; +import se.umu.cs.dit06ajnajs.map.PathSquare; import se.umu.cs.dit06ajnajs.map.TowerSquare; public class ATDModel { @@ -26,14 +28,31 @@ public class ATDModel { public void addTower(Tower t) { TowerSquare square = currentMap.getRandomFreeTowerSquare(); if (square != null) { + // If there is a free square, place tower Point p = square.getPosition(); t.setPostition(p); square.setTower(t); + + //Register as observer for the neighbours in range + int shootRange = t.getRange(); + int squareRange = + (int) Math.ceil((shootRange - AntiTD.SQUARE_SIZE*0.5) + / (AntiTD.SQUARE_SIZE)); + + List neighbours + = this.currentMap.getNeighbours(square, squareRange); + for (MapSquare neighbour: neighbours) { + if(neighbour instanceof PathSquare) { + neighbour.addObserver(square); + } + } agents.add(t); } else { System.out.println("No available towersquares"); } } + + public void addAgent(Agent agent) { // TODO Auto-generated method stub diff --git a/src/se/umu/cs/dit06ajnajs/agent/Agent.java b/src/se/umu/cs/dit06ajnajs/agent/Agent.java index ca0393f..56aec96 100644 --- a/src/se/umu/cs/dit06ajnajs/agent/Agent.java +++ b/src/se/umu/cs/dit06ajnajs/agent/Agent.java @@ -4,5 +4,5 @@ public interface Agent { /** * Updates this Agent. */ - public void update(); + public void act(); } diff --git a/src/se/umu/cs/dit06ajnajs/agent/BasicTower.java b/src/se/umu/cs/dit06ajnajs/agent/BasicTower.java index 0dba0c6..1f7217a 100644 --- a/src/se/umu/cs/dit06ajnajs/agent/BasicTower.java +++ b/src/se/umu/cs/dit06ajnajs/agent/BasicTower.java @@ -13,7 +13,7 @@ public class BasicTower extends Tower implements Paintable { // TODO super.image = img; } - public void update() { + public void act() { // TODO Auto-generated method stub } diff --git a/src/se/umu/cs/dit06ajnajs/agent/FootmanUnit.java b/src/se/umu/cs/dit06ajnajs/agent/FootmanUnit.java index bce089c..4b00019 100644 --- a/src/se/umu/cs/dit06ajnajs/agent/FootmanUnit.java +++ b/src/se/umu/cs/dit06ajnajs/agent/FootmanUnit.java @@ -4,11 +4,13 @@ import java.awt.Color; import java.awt.Graphics; import java.util.logging.Logger; +import se.umu.cs.dit06ajnajs.map.Map; + public class FootmanUnit extends Unit { - public FootmanUnit(int xPos, int yPos, int height, int width, int speed, Direction direction) { - super(xPos, yPos, height, width, speed, direction); + public FootmanUnit(int xPos, int yPos, int height, int width, int speed, Direction direction, Map map) { + super(xPos, yPos, height, width, speed, direction, map); } diff --git a/src/se/umu/cs/dit06ajnajs/agent/Tower.java b/src/se/umu/cs/dit06ajnajs/agent/Tower.java index 6f699ae..4dd56a1 100644 --- a/src/se/umu/cs/dit06ajnajs/agent/Tower.java +++ b/src/se/umu/cs/dit06ajnajs/agent/Tower.java @@ -28,7 +28,6 @@ public abstract class Tower implements Paintable, Agent { } public void setImage(Image img) { - // TODO Auto-generated method stub // TODO Implement method } @@ -37,4 +36,8 @@ public abstract class Tower implements Paintable, Agent { this.yPos = p.y; } + public int getRange() { + return this.range; + } + } diff --git a/src/se/umu/cs/dit06ajnajs/agent/Unit.java b/src/se/umu/cs/dit06ajnajs/agent/Unit.java index c7ad673..9f6d89e 100644 --- a/src/se/umu/cs/dit06ajnajs/agent/Unit.java +++ b/src/se/umu/cs/dit06ajnajs/agent/Unit.java @@ -1,9 +1,11 @@ package se.umu.cs.dit06ajnajs.agent; import java.awt.Image; +import java.awt.Point; import java.util.logging.Logger; import se.umu.cs.dit06ajnajs.Paintable; +import se.umu.cs.dit06ajnajs.map.Map; public abstract class Unit implements Agent, Paintable{ private static Logger logger = Logger.getLogger("AntiTD"); @@ -17,14 +19,16 @@ public abstract class Unit implements Agent, Paintable{ private int speed; private Direction direction; + private Map map; - public Unit(int xPos, int yPos, int width, int height, int speed, Direction direction) { + public Unit(int xPos, int yPos, int width, int height, int speed, Direction direction, Map map) { this.xPos = xPos; this.yPos = yPos; this.width = width; this.height = height; this.speed = speed; this.direction = direction; + this.map = map; } public void setImage(Image img) { @@ -32,8 +36,14 @@ public abstract class Unit implements Agent, Paintable{ } - public void update() { + public void act() { // TODO Move to Unit? + move(); + } + + public void move() { + //TODO invoke landOn(this) on the square the unit lands on + // Nu måste unit fråga map vilken ruta som finns på detta x,y? switch (direction) { case UP: logger.fine("UP"); -- 2.11.4.GIT