-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLevel.cs
48 lines (40 loc) · 1.16 KB
/
Level.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
46
47
48
namespace TowerDefenseGame
{
class Level
{
private readonly Invader[] _invaders;
public Tower[] Towers { get; set; }
public Level(Invader[] invaders)
{
_invaders = invaders;
}
//returns true if the player wins : false
public bool Play()
{
// run until all invaders are neutralized or invader reaches the end of the path
int remainingInvaders = _invaders.Length;
while(remainingInvaders > 0)
{
foreach(Tower tower in Towers)
{
tower.FireOnInvaders(_invaders);
}
remainingInvaders = 0;
foreach(Invader invader in _invaders)
{
if(invader.IsActive)
{
invader.Move();
if(invader.HasScored)
{
return false;
}
remainingInvaders++;
}
}
}
return true;
// each tower
}
}
}