1 package se
.umu
.cs
.dit06ajnajs
.agent
;
6 import java
.util
.ArrayList
;
8 import java
.util
.Observable
;
9 import java
.util
.Observer
;
10 import java
.util
.logging
.Logger
;
12 import se
.umu
.cs
.dit06ajnajs
.Paintable
;
14 public abstract class Tower
implements Paintable
, Agent
, Observer
{
16 private static Logger logger
= Logger
.getLogger("AntiTD");
29 private boolean alive
;
30 private boolean fiering
;
31 private List
<Unit
> fireingList
;
34 public Tower(int width
, int height
, int damage
, int range
) {
44 this.fireingList
= new ArrayList
<Unit
>();
45 // TODO this.image = img;
48 public void setImage(Image img
) {
49 // TODO Implement method
52 public void setPostition(Point p
) {
55 this.centerX
= this.x
+ (this.width
/2);
56 this.centerY
= this.y
+ (this.height
/2);
59 public int getRange() {
63 public Point
getCenterPoint() {
64 return new Point(this.centerX
, this.centerY
);
68 if (!fireingList
.isEmpty()) {
69 Unit unit
= fireingList
.get(0);
71 Point unitPoint
= unit
.getCenterPoint();
73 int unitXPos
= unitPoint
.x
;
74 int unitYPos
= unitPoint
.y
;
75 int distans
= (int) Math
.hypot((this.centerX
- unitXPos
), this.centerY
- unitYPos
);
76 System
.out
.println("Tower range: " + this.range
);
77 System
.out
.println("Distance to unit: " + distans
);
78 if (distans
<this.range
) {
79 logger
.info("UNIT IN RANGE, FIIIIIREEEEEEE!!!");
83 logger
.info("Unit out of reach, removing from fireingList");
84 fireingList
.remove(unit
);
87 fireingList
.remove(unit
);
92 public void update(Observable caller
, Object arg
) {
93 // TODO Auto-generated method stub
94 // Should always be units
95 if (arg
instanceof Unit
) {
96 Unit unit
= (Unit
) arg
;
97 if (!fireingList
.contains(unit
)) {
98 fireingList
.add(unit
);
99 logger
.info("Unit >" + unit
.getClass().getSimpleName() +
100 "< added to tower...");
105 public boolean isAlive() {
109 public void setAlive(boolean state
) {
113 public int getHeight() {
117 public void setHeight(int height
) {
118 this.height
= height
;
121 public int getWidth() {
125 public void setWidth(int width
) {
137 public int getCenterX() {
141 public int getCenterY() {
145 public boolean isFiering() {
149 public void setFiering(boolean fiering
) {
150 this.fiering
= fiering
;
153 public List
<Unit
> getFireingList() {
154 return this.fireingList
;