-
Notifications
You must be signed in to change notification settings - Fork 0
/
Game.cs
77 lines (66 loc) · 2.45 KB
/
Game.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
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
namespace TowerDefenseGame
{
class Game
{
public static void Main()
{
// Instatiation - an instance of a class. creates a new variable tower with the type Tower, assigning tower to a new Tower() object.
/// Tower tower = new Tower();
Map map = new Map(8, 5);
try
{
Path path = new Path(
new [] {
// passing in map to verify points
new MapLocation(0, 2, map),
new MapLocation(1, 2, map),
new MapLocation(2, 2, map),
new MapLocation(3, 2, map),
new MapLocation(4, 2, map),
new MapLocation(5, 2, map),
new MapLocation(6, 2, map),
new MapLocation(7, 2, map),
}
);
Invader[] invaders =
{
new Invader(path),
new Invader(path),
new Invader(path),
new Invader(path)
};
Tower[] towers =
{
new Tower(new MapLocation(1,3, map)),
new Tower(new MapLocation(3,3, map)),
new Tower(new MapLocation(5,3, map)),
};
Level level = new Level(invaders)
{
// we can only do this with properties, notice there is no semicolon, set on construction
Towers = towers
};
bool playerWon = level.Play();
Console.WriteLine("player " + (playerWon? "Wone!": "lost"));
MapLocation location = new MapLocation(0,0, map);
// using property
// invader.Location = location;
}
catch(OutOfBoundsException ex)
{
Console.WriteLine(ex.Message);
}
catch(TowerDefenseException ex)
{
Console.WriteLine("Unhandled towerdefense exception ", ex.Message);
}
catch(Exception ex)
{
// throw new System.Exception(ex.Message);
Console.WriteLine("Unhandled Exception: ", ex.Message);
}
int area = map.Width * map.Height;
Console.WriteLine(area);
}
}
}