-
Notifications
You must be signed in to change notification settings - Fork 0
/
EnemyList.cs
45 lines (41 loc) · 954 Bytes
/
EnemyList.cs
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
using System;
using System.Collections;
namespace Arena {
public class EnemyList {
private string enemiesDatafile;
Random rand = new Random();
ArrayList el = new ArrayList();
public EnemyList() {
el.Clear();
}
public string getRandom(int enemyLevel) {
switch(enemyLevel) {
case 1:
enemiesDatafile = "enemies1.txt";
break;
case 2:
enemiesDatafile = "enemies2.txt";
break;
case 3:
enemiesDatafile = "enemies3.txt";
break;
default:
enemiesDatafile = "enemies1.txt";
break;
}
populateEnemyListFromDatafile();
int randomIndex = rand.Next(1, el.Count);
return (string)el[randomIndex];
}
private void populateEnemyListFromDatafile() {
int counter = 0;
string line;
System.IO.StreamReader file = new System.IO.StreamReader(enemiesDatafile);
while((line = file.ReadLine()) != null) {
el.Add(line);
++counter;
}
file.Close();
}
}
}