Seal! 'n' stuff
[AntiTD.git] / src / se / umu / cs / dit06ajnajs / map / StartSquare.java
blob5e0ac8ecffccda27b986576f3357ca1c24734fa3
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;
12 import java.util.ArrayList;
13 import java.util.List;
15 public class StartSquare extends MapSquare implements Traversable, Observer {
16 private static Logger logger = Logger.getLogger("AntiTD");
17 private boolean active;
18 private List<Unit> unitsToStart;
20 // TODO, set startDirection dynamicly
21 private Direction startDirection = Direction.UP;
23 public StartSquare(int x, int y, Image image) {
24 super(x, y, image);
25 this.active = false;
28 /**
29 * Used to initialize fields that should be individually set for every
30 * StartSquare, since clone() is shallow.
32 @Override
33 public void init() {
34 this.unitsToStart = new ArrayList<Unit>();
37 public boolean isActive() {
38 return active;
41 public void setActive(boolean active) {
42 this.active = active;
45 public void setStartDirection(Direction directioin) {
46 this.startDirection = directioin;
49 public Direction getStartDirection() {
50 return this.startDirection;
53 public Unit getUnitToStart() {
54 if (!unitsToStart.isEmpty()) {
55 return unitsToStart.get(0);
56 } else {
57 return null;
61 public void addUnit(Unit unit) {
62 unitsToStart.add(unit);
63 unit.setCenterX(getCenterX());
64 unit.setCenterY(getCenterY());
65 unit.setDirection(getStartDirection(), this);
68 public void removeUnit(Unit unit) {
69 unitsToStart.remove(unit);
72 public void landOn(Unit unit) {
73 // TODO copied from GoalSquare, how do we implement a starting Unit?
74 // Set direction...
75 unit.setDirection(startDirection, this);
78 /**
79 * Sets this StartSquare as active.
81 @Override
82 public void click() {
83 if (!active) {
84 setChanged();
85 notifyObservers();
86 clearChanged();
87 this.active = true;
91 @Override
92 public void paint(Graphics g) {
93 super.paint(g);
94 if (active) {
95 g.setColor(Color.GREEN);
96 g.drawRect(getX(), getY(),
97 AntiTD.SQUARE_SIZE, AntiTD.SQUARE_SIZE);
98 g.drawRect(getX() + 1, getY() + 1,
99 AntiTD.SQUARE_SIZE - 2, AntiTD.SQUARE_SIZE - 2);
104 * Called when another StartSquare is activated, which means that this
105 * StartSquare should not be active.
107 * @param observer an <code>Observable</code> value
108 * @param obj an <code>Object</code> value
110 public void update(Observable observer, Object obj) {
111 logger.info("Update in StartSquare: active is set to false");
112 this.active = false;