From c91f0b9f7d556535fb545bd33176486682fba93b Mon Sep 17 00:00:00 2001 From: Andreas Jakobsson Date: Tue, 16 Dec 2008 21:37:16 +0100 Subject: [PATCH] MaImplemented landOn in PathSquare --- src/se/umu/cs/dit06ajnajs/ATDModel.java | 4 +++- src/se/umu/cs/dit06ajnajs/agent/Unit.java | 10 +++++++++- src/se/umu/cs/dit06ajnajs/map/PathSquare.java | 15 +++++++++++---- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/src/se/umu/cs/dit06ajnajs/ATDModel.java b/src/se/umu/cs/dit06ajnajs/ATDModel.java index f56b989..5174c68 100644 --- a/src/se/umu/cs/dit06ajnajs/ATDModel.java +++ b/src/se/umu/cs/dit06ajnajs/ATDModel.java @@ -5,6 +5,8 @@ import java.awt.Image; import java.awt.Point; import java.util.ArrayList; import java.util.List; +import java.util.Observer; + import se.umu.cs.dit06ajnajs.agent.Agent; import se.umu.cs.dit06ajnajs.agent.Tower; import se.umu.cs.dit06ajnajs.map.Map; @@ -43,7 +45,7 @@ public class ATDModel { = this.currentMap.getNeighbours(square, squareRange); for (MapSquare neighbour: neighbours) { if(neighbour instanceof PathSquare) { - neighbour.addObserver(square); + neighbour.addObserver((Observer) square); } } agents.add(t); diff --git a/src/se/umu/cs/dit06ajnajs/agent/Unit.java b/src/se/umu/cs/dit06ajnajs/agent/Unit.java index 9f6d89e..141def3 100644 --- a/src/se/umu/cs/dit06ajnajs/agent/Unit.java +++ b/src/se/umu/cs/dit06ajnajs/agent/Unit.java @@ -6,6 +6,8 @@ import java.util.logging.Logger; import se.umu.cs.dit06ajnajs.Paintable; import se.umu.cs.dit06ajnajs.map.Map; +import se.umu.cs.dit06ajnajs.map.MapSquare; +import se.umu.cs.dit06ajnajs.map.PathSquare; public abstract class Unit implements Agent, Paintable{ private static Logger logger = Logger.getLogger("AntiTD"); @@ -37,8 +39,14 @@ public abstract class Unit implements Agent, Paintable{ } public void act() { - // TODO Move to Unit? + // TODO check for collision on next position move(); + + // Land on current square + MapSquare currentSquare= map.getMapSquareAtPoint(xPos, yPos); + if (currentSquare instanceof PathSquare) { + ((PathSquare) currentSquare).landOn(this); + } } public void move() { diff --git a/src/se/umu/cs/dit06ajnajs/map/PathSquare.java b/src/se/umu/cs/dit06ajnajs/map/PathSquare.java index 15e3654..fb1f2c0 100644 --- a/src/se/umu/cs/dit06ajnajs/map/PathSquare.java +++ b/src/se/umu/cs/dit06ajnajs/map/PathSquare.java @@ -1,17 +1,24 @@ package se.umu.cs.dit06ajnajs.map; import java.awt.Image; +import java.util.logging.Logger; import se.umu.cs.dit06ajnajs.agent.Unit; public class PathSquare extends MapSquare implements Traversable { + private static Logger logger = Logger.getLogger("AntiTD"); + public PathSquare(int x, int y, Image img) { super(x, y, img); + } - public void landOn(Unit unit) { - // TODO: Woha a unit is here, I should tell all my towers! - - } + public void landOn(Unit unit) { + // DONE: Woha a unit is here, I should tell all my towers! + logger.info("Unit >" + unit.getClass().getName() + + "< landed on pathsquare. Notifying observers..."); + setChanged(); + notifyObservers(unit); + } } \ No newline at end of file -- 2.11.4.GIT