-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuildTowers.java
More file actions
152 lines (143 loc) · 4.14 KB
/
BuildTowers.java
File metadata and controls
152 lines (143 loc) · 4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
import greenfoot.*; // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)
/**
* The buttons that you click to build towers <br>
* Each button builds a new Tower
*
* @author (James Lu)
* @version (1.0)
*/
public class BuildTowers extends Button implements HoverInfo
{
private int id;
private Tower tower;
private int cost;
private int counter;
private int hoverCounter;
public BuildTowers (int id){
this.id = id;
String element = "";
int ID = (id-1) / 3;
if (ID == 0){ //air
tower = new AirTower();
if (id == 1){
}else if (id == 2){
tower.upgrade(true);
}else if (id == 3){
tower.upgrade(true);
tower.upgrade(true);
}
element = "a";
}else if (ID == 1){ //water
tower = new WaterTower();
if (id == 4){
}else if (id == 5){
tower.upgrade(true);
}else if (id == 6){
tower.upgrade(true);
tower.upgrade(true);
}
id = (id-1)%3 + 1;
element = "w";
}else if (ID == 2){ //Fire
tower = new FireTower();
if (id == 7){
}else if (id == 8){
tower.upgrade(true);
}else if (id == 9){
tower.upgrade(true);
tower.upgrade(true);
}
id = (id-1)%3 + 1;
element = "f";
}else if (ID == 3){ //Earth
tower = new EarthTower();
if (id == 10){
}else if (id == 11){
tower.upgrade(true);
}else if (id == 12){
tower.upgrade(true);
tower.upgrade(true);
}
id = (id-1)%3 + 1;
element = "e";
}
counter = 0;
hoverCounter = 0;
bg[0] = new GreenfootImage ("Buttons/BuildTowers/"+element + "" +id+"1.png");
bg[1] = new GreenfootImage ("Buttons/BuildTowers/"+element + "" +id+"2.png");
bg[2] = new GreenfootImage ("Buttons/BuildTowers/"+element + "" +id+"3.png");
cost = tower.getCost();
this.setImage (bg[0]);
}
public void act(){
if (clicked){
if (counter >= 10){
counter = 0;
clicked = false;
}
else{
counter++;
hoverCounter = 0;
this.setImage (bg[2]);
}
}
else if (selected){
selected = false;
this.setImage (bg[1]);
if (hoverCounter >= 50){
map.hm.setData (this);
int[] co = setCo();
map.addObject (map.hm, co[0], co[1]);
}
}
else{
this.setImage (bg[0]);
}
}
/**
* Returns the tower this button builds
*/
public Tower getTower(){
int ID = (id-1) / 3;
int level = (id-1) % 3 + 1;
Tower t;
if (ID == 0){ //air
t = new AirTower();
}else if (ID == 1){ //water
t = new WaterTower();
}else if (ID == 2){ //fire
t = new FireTower();
}else{ //earth
t = new EarthTower();
}
for (int i = 1; i < level; i++){
t.upgrade (true);
}
return t;
}
/**
* Returns the cost of building the tower
*/
public int getCost(){
return cost;
}
/** interface methods*/
/**
* Increases the hover counter when the mouse hovers over this object
*/
public void hoverOver(){
hoverCounter++;
}
/**
* Changes the image to be selected or not Pass true if the button is selected
*/
public void changeImg(boolean s){
selected = s;
}
/**
* Resets the hover counter when the mouse is no longer hovering over it
*/
public void resetCounter(){
hoverCounter = 0;
}
}