StartSquare selection, distanceCalc changed in TowerSquare, new level with two StartS...
[AntiTD.git] / src / se / umu / cs / dit06ajnajs / map / StartSquare.java
blobe5c7f6b4c92aee7d19db9a7da5a1e49ca23956b3
1 package se.umu.cs.dit06ajnajs.map;
3 import java.awt.Image;
4 import se.umu.cs.dit06ajnajs.agent.Unit;
5 import java.util.logging.Logger;
6 import se.umu.cs.dit06ajnajs.agent.Direction;
7 import java.awt.Graphics;
8 import java.awt.Color;
9 import se.umu.cs.dit06ajnajs.AntiTD;
10 import java.util.Observer;
11 import java.util.Observable;
13 public class StartSquare extends MapSquare implements Traversable, Observer {
14 private static Logger logger = Logger.getLogger("AntiTD");
15 private boolean active = false;
17 // TODO, set startDirection dynamicly
18 private Direction startDirection = Direction.UP;
20 public StartSquare(int x, int y, Image image) {
21 super(x, y, image);
24 public boolean isActive() {
25 return active;
28 public void setActive(boolean active) {
29 this.active = active;
32 public void landOn(Unit unit) {
33 // TODO copied from GoalSquare, how do we implement a starting Unit?
34 // Set direction...
35 unit.setDirection(startDirection);
38 /**
39 * Sets this StartSquare as active.
41 @Override
42 public void click() {
43 if (!active) {
44 setChanged();
45 notifyObservers();
46 clearChanged();
47 this.active = true;
51 @Override
52 public void paint(Graphics g) {
53 super.paint(g);
54 if (active) {
55 g.setColor(Color.GREEN);
56 g.drawRect(getX(), getY(),
57 AntiTD.SQUARE_SIZE - 1, AntiTD.SQUARE_SIZE - 1);
58 g.drawRect(getX() - 1, getY() - 1,
59 AntiTD.SQUARE_SIZE - 2, AntiTD.SQUARE_SIZE - 2);
63 /**
64 * Called when another StartSquare is activated, which means that this
65 * StartSquare should not be active.
67 * @param observer an <code>Observable</code> value
68 * @param obj an <code>Object</code> value
70 public void update(Observable observer, Object obj) {
71 logger.info("Update in StartSquare: active is set to false");
72 this.active = false;