-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnemyComponent
168 lines (142 loc) · 3.09 KB
/
EnemyComponent
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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/*
*The Enemy class creates enemy objects for the players to destroy
*@author Haiming Gao, Patrick Kwon, Allen Wu
*Date: 05-25-15
*Period: 3
*/
import java.awt.Rectangle;
public class Enemy {
private int health;
private int dmg;
private int money;
private int speed;
private Rectangle en;
private int initx;
private int inity;
private int x;
private int y;
/**Creates a new Enemy object with the given health, damage, speed, and money
*@param health the given health for the enemy
*@param dmg the given damage enemy can give to player
*@param speed the given speed of the enemy's movement
*@param money the given money value of the enemy
*/
public Enemy(int health, int dmg, int speed, int money)
{
this.health = health;
this.dmg = dmg;
this.money = money;
this.speed = speed;
createLocation();
en = new Rectangle(initx,inity, 30, 30);
}
/**Returns the money value of the enemy
*@return the money value of the enemy
*/
public int getMoney()
{
return money;
}
/**Checks to see if the enemy is dead
*@return whether the enemy is dead
*/
public boolean isDead()
{
if(health <= 0)
{
return true;
}
else
{
return false;
}
}
/**Returns the damage amount that the enemy can give to the player
*@return the damage amount that the enemy can give to the player
*/
public int getDmg()
{
return dmg;
}
/**Returns the enemy's health
*@return the health value of the enemy
*/
public int getHealth()
{
return health;
}
/**Updates the enemy's health after the enemy is clicked and damaged
*/
public void changeHealth(int dmg)
{
health = health - dmg;
}
/**Creates a random location for the enemy to be created in
*/
public void createLocation()
{
int num = (int) (Math.random() * 2) + 1;
int num2 = (int) (Math.random() * 2) + 1;
if(num == 1)
{
if(num2 == 1)
{
initx = 0;
}
else
{
initx = 600;
}
inity = (int)(Math.random() * 600);
}
else if(num == 2)
{
if(num2 == 1)
{
inity = 0;
}
else
{
inity = 600;
}
initx = (int)(Math.random() * 600);
}
x = initx;
y = inity;
}
/**Returns the x coordinate of the enemy
*@return enemy's x coordinate
*/
public int getInitX()
{
return initx;
}
/**Returns the y coordinate of the enemy
*@return enemy's y coordinate
*/
public int getInitY()
{
return inity;
}
/**sets location of enemy as it moves towards the center
*Calculates positions needed to place in center
*/
public void moveToCenter()
{
int center = 300;
int diffX = center - initx;
int diffY = center - inity;
int increX = diffX/80;
int increY = diffY/80;
x = x + increX;
y = y + increY;
en.setLocation(x,y);
}
/**Return the rectangle of the enemy
*@return Rectangle of the enemy
*/
public Rectangle getRect()
{
return en;
}
}