-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEnemyGenerator.java
More file actions
53 lines (46 loc) · 1.52 KB
/
EnemyGenerator.java
File metadata and controls
53 lines (46 loc) · 1.52 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
// EnemyGenerator.java
// this class contains a static method for creating enemies randomly
import java.util.Random;
/** This class randomly generates an enemy that is then placed on the map where a * is located. Enemies are generated
* only at the beginning of the map being loaded and the enemies retain the same data while they are alive
*
*/
public class EnemyGenerator {
private static EnemyGenerator theInstance;
/** A singleton that creates an enemy generator
*
* @return the EnemyGenerator instance
*/
public static synchronized EnemyGenerator instance() {
if (theInstance == null) {
theInstance = new EnemyGenerator();
}
return theInstance;
}
private EnemyGenerator() {
}
/** Generates a new Enemy object based on a random number that is generated each time
*
* @param row the row the enemy is in
* @param col the column the enemy is in
* @return an Enemy object
*/
public static Enemy generate(int row, int col) {
Random rng = new Random();
int num = rng.nextInt(4);
Enemy enemy;
if (num == 0) {
enemy = new Enemy("Goblin", row, col, 28, 18, 10);
}
else if (num == 1) {
enemy = new Enemy("Dragon", row, col, 39, 23, 13);
}
else if (num == 2) {
enemy = new Enemy("Zombie", row, col, 26, 20, 8);
}
else {
enemy = new Enemy("Wolf", row, col, 32, 21, 8);
}
return enemy;
}
}