StartSquare selection, distanceCalc changed in TowerSquare, new level with two StartS...
[AntiTD.git] / src / se / umu / cs / dit06ajnajs / map / MapSquare.java
blob337b6df5af52efe61025b815965fc67f15213e05
1 package se.umu.cs.dit06ajnajs.map;
3 import java.awt.Graphics;
4 import java.awt.Image;
5 import java.awt.Point;
6 import java.util.Observable;
8 import se.umu.cs.dit06ajnajs.Paintable;
9 import se.umu.cs.dit06ajnajs.AntiTD;
11 public abstract class MapSquare extends Observable implements Paintable,
12 Cloneable,
13 Clickable {
14 private int x;
15 private int y;
16 private int centerX;
17 private int centerY;
19 private Image image;
21 public MapSquare(int x, int y, Image image) {
22 setX(x);
23 setY(y);
24 this.image = image;
27 public void paint(Graphics g) {
28 g.drawImage(image, x, y, null);
31 public Point getPosition() {
32 Point p = new Point(x, y);
33 return p;
36 public Point getCenterPoint() {
37 return new Point(this.centerX, this.centerY);
40 public int getCenterX() {
41 return this.centerX;
44 public int getCenterY() {
45 return this.centerY;
48 public int getX() {
49 return x;
52 public void setX(int x) {
53 this.x = x;
54 this.centerX = this.x + (AntiTD.SQUARE_SIZE/2);
57 public int getY() {
58 return y;
61 public void setY(int y) {
62 this.y = y;
63 this.centerY = this.y + (AntiTD.SQUARE_SIZE/2);
66 public void setImage(Image img) {
67 image = img;
70 /**
71 * Empty method, ovveridden by subclass to implement behaviour.
73 public void click() {
76 /**
77 * Attemts to clone this MapSquare.
79 * @return A new instance of the same type as the instantiated MapSquare.
81 @Override
82 public Object clone() {
83 try {
84 return super.clone();
85 } catch (CloneNotSupportedException e) {
86 e.printStackTrace();
87 throw new Error("Object " + this.getClass().getName()
88 + " is not Cloneable");
92 @Override
93 public String toString() {
94 return "MapSquare: " + this.getClass().getName()
95 + " @("+ x +", " + y +")";