Changed the way to add new units. Important settings are now done in addUnit in ATDModel.
[AntiTD.git] / src / se / umu / cs / dit06ajnajs / map / StartSquare.java
blob49a37b53d5e456f27d611e945bd0f35054b6f6c0
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 setStartDirection(Direction directioin) {
33 this.startDirection = directioin;
36 public Direction getStartDirection() {
37 return this.startDirection;
40 public void landOn(Unit unit) {
41 // TODO copied from GoalSquare, how do we implement a starting Unit?
42 // Set direction...
43 unit.setDirection(startDirection);
46 /**
47 * Sets this StartSquare as active.
49 @Override
50 public void click() {
51 if (!active) {
52 setChanged();
53 notifyObservers();
54 clearChanged();
55 this.active = true;
59 @Override
60 public void paint(Graphics g) {
61 super.paint(g);
62 if (active) {
63 g.setColor(Color.GREEN);
64 g.drawRect(getX(), getY(),
65 AntiTD.SQUARE_SIZE - 1, AntiTD.SQUARE_SIZE - 1);
66 g.drawRect(getX() - 1, getY() - 1,
67 AntiTD.SQUARE_SIZE - 2, AntiTD.SQUARE_SIZE - 2);
71 /**
72 * Called when another StartSquare is activated, which means that this
73 * StartSquare should not be active.
75 * @param observer an <code>Observable</code> value
76 * @param obj an <code>Object</code> value
78 public void update(Observable observer, Object obj) {
79 logger.info("Update in StartSquare: active is set to false");
80 this.active = false;