From 95325ed42c3260e3babf29593c08348530692966 Mon Sep 17 00:00:00 2001 From: Andreas Jakobsson Date: Mon, 15 Dec 2008 17:55:08 +0100 Subject: [PATCH] Add a tower on a random towersquare --- src/se/umu/cs/dit06ajnajs/ATDController.java | 2 +- src/se/umu/cs/dit06ajnajs/ATDModel.java | 3 +++ src/se/umu/cs/dit06ajnajs/MapBuilder.java | 2 +- src/se/umu/cs/dit06ajnajs/MapSquare.java | 6 ++++++ src/se/umu/cs/dit06ajnajs/agent/BasicTower.java | 12 ++++++++++-- src/se/umu/cs/dit06ajnajs/agent/Tower.java | 23 ++++++++++++++++------- 6 files changed, 37 insertions(+), 11 deletions(-) diff --git a/src/se/umu/cs/dit06ajnajs/ATDController.java b/src/se/umu/cs/dit06ajnajs/ATDController.java index 0330484..6c64e81 100644 --- a/src/se/umu/cs/dit06ajnajs/ATDController.java +++ b/src/se/umu/cs/dit06ajnajs/ATDController.java @@ -33,7 +33,7 @@ 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(10, 1)); + model.addTower(new BasicTower(20, 20, 10, 1)); initGame(); running = true; diff --git a/src/se/umu/cs/dit06ajnajs/ATDModel.java b/src/se/umu/cs/dit06ajnajs/ATDModel.java index f33b8c3..5f318e1 100644 --- a/src/se/umu/cs/dit06ajnajs/ATDModel.java +++ b/src/se/umu/cs/dit06ajnajs/ATDModel.java @@ -3,6 +3,7 @@ package se.umu.cs.dit06ajnajs; import java.awt.Dimension; import java.awt.Image; +import java.awt.Point; import java.util.ArrayList; import java.util.List; import se.umu.cs.dit06ajnajs.agent.Agent; @@ -22,6 +23,8 @@ public class ATDModel { public void addTower(Tower t) { TowerSquare square = map.getRandomFreeTowerSquare(); if (square != null) { + Point p = square.getPosition(); + t.setPostition(p); square.setTower(t); agents.add(t); } else { diff --git a/src/se/umu/cs/dit06ajnajs/MapBuilder.java b/src/se/umu/cs/dit06ajnajs/MapBuilder.java index 4dc011d..3ac0e03 100644 --- a/src/se/umu/cs/dit06ajnajs/MapBuilder.java +++ b/src/se/umu/cs/dit06ajnajs/MapBuilder.java @@ -24,7 +24,7 @@ public final class MapBuilder { for (int x = 0; x < xsize; x++) { int xPos = squareWidth * x; int yPos = squareWidth * y; - mapArray[x][y] = new PathSquare(xPos, yPos, grassImage); + mapArray[x][y] = new TowerSquare(xPos, yPos, grassImage); logger.info(mapArray[x][y].toString()); } } diff --git a/src/se/umu/cs/dit06ajnajs/MapSquare.java b/src/se/umu/cs/dit06ajnajs/MapSquare.java index 2e5ae74..a928b66 100644 --- a/src/se/umu/cs/dit06ajnajs/MapSquare.java +++ b/src/se/umu/cs/dit06ajnajs/MapSquare.java @@ -2,6 +2,7 @@ package se.umu.cs.dit06ajnajs; import java.awt.Graphics; import java.awt.Image; +import java.awt.Point; public abstract class MapSquare implements Paintable { @@ -28,4 +29,9 @@ public abstract class MapSquare implements Paintable { return "MapSquare: " + this.getClass().getName() + " @("+ x +", " + y +")"; } + + public Point getPosition() { + Point p = new Point(x, y); + return p; + } } \ No newline at end of file diff --git a/src/se/umu/cs/dit06ajnajs/agent/BasicTower.java b/src/se/umu/cs/dit06ajnajs/agent/BasicTower.java index 89a08c7..0dba0c6 100644 --- a/src/se/umu/cs/dit06ajnajs/agent/BasicTower.java +++ b/src/se/umu/cs/dit06ajnajs/agent/BasicTower.java @@ -1,13 +1,15 @@ package se.umu.cs.dit06ajnajs.agent; +import java.awt.Color; +import java.awt.Graphics; import java.awt.Image; import se.umu.cs.dit06ajnajs.Paintable; public class BasicTower extends Tower implements Paintable { - public BasicTower(int damage, int range) { - super(damage, range); + public BasicTower(int width, int height, int damage, int range) { + super(width, height, damage, range); // TODO super.image = img; } @@ -15,4 +17,10 @@ public class BasicTower extends Tower implements Paintable { // TODO Auto-generated method stub } + + public void paint(Graphics g) { + // TODO Auto-generated method stub + g.setColor(Color.RED); + g.drawRect(super.xPos, super.yPos, super.width, super.height); + } } diff --git a/src/se/umu/cs/dit06ajnajs/agent/Tower.java b/src/se/umu/cs/dit06ajnajs/agent/Tower.java index ea48a4d..6f699ae 100644 --- a/src/se/umu/cs/dit06ajnajs/agent/Tower.java +++ b/src/se/umu/cs/dit06ajnajs/agent/Tower.java @@ -2,30 +2,39 @@ package se.umu.cs.dit06ajnajs.agent; import java.awt.Graphics; import java.awt.Image; +import java.awt.Point; import se.umu.cs.dit06ajnajs.Paintable; public abstract class Tower implements Paintable, Agent { + protected int xPos; + protected int yPos; + + protected int width; + protected int height; + protected int damage; protected int range; protected Image image; - public Tower(int damage, int range) { + public Tower(int width, int height, int damage, int range) { + this.width = width; + this.height = height; + this.damage = damage; this.range = range; // TODO this.image = img; } - - public void paint(Graphics g) { - // TODO Auto-generated method stub - // TODO Implement method - - } public void setImage(Image img) { // TODO Auto-generated method stub // TODO Implement method } + + public void setPostition(Point p) { + this.xPos = p.x; + this.yPos = p.y; + } } -- 2.11.4.GIT