1 package se
.umu
.cs
.dit06ajnajs
.map
;
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
;
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
) {
29 * Used to initialize fields that should be individually set for every
30 * StartSquare, since clone() is shallow.
34 this.unitsToStart
= new ArrayList
<Unit
>();
37 public boolean isActive() {
41 public void setActive(boolean 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);
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?
75 unit
.setDirection(startDirection
, this);
79 * Sets this StartSquare as active.
92 public void paint(Graphics g
) {
94 //g.drawString("" + unitsToStart.size(), getX(), getY());
97 g
.setColor(Color
.GREEN
);
98 g
.drawRect(getX(), getY(),
99 AntiTD
.SQUARE_SIZE
, AntiTD
.SQUARE_SIZE
);
100 g
.drawRect(getX() + 1, getY() + 1,
101 AntiTD
.SQUARE_SIZE
- 2, AntiTD
.SQUARE_SIZE
- 2);
106 * Called when another StartSquare is activated, which means that this
107 * StartSquare should not be active.
109 * @param observer an <code>Observable</code> value
110 * @param obj an <code>Object</code> value
112 public void update(Observable observer
, Object obj
) {
113 logger
.info("Update in StartSquare: active is set to false");