-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGame.hx
71 lines (57 loc) · 1.45 KB
/
Game.hx
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
// game class
class Game
{
public var ui: UI;
public var map: Map;
public var turns: Int;
public var zombies: Int;
public var zombiesDestroyed: Int;
public var isFinished: Bool;
public function new()
{
ui = new UI(this);
map = new Map(this);
var hasPlayed = ui.getVar('hasPlayed');
if (hasPlayed == null)
ui.alert("Welcome to Black Obelisk.<br><br>" +
"If this is your first time playing, please take the time to read the " +
"<a target=_blank href='http://code.google.com/p/bobelisk/wiki/Manual'>Manual</a> before playing.");
ui.setVar('hasPlayed', '1');
restart();
}
// main function
static var instance: Game;
static function main()
{
instance = new Game();
}
// finish the game
public function finish(isVictory: Bool)
{
isFinished = true;
ui.track((isVictory ? "winGame" : "loseGame"),
"", turns);
ui.finish(isVictory);
}
// check for victory
public function checkFinish()
{
// check if all obelisks are shattered
if (map.obelisksShattered() < map.obelisks.length)
return;
finish(true);
}
// restart game
public function restart()
{
ui.track("startGame");
isFinished = false;
turns = 0;
zombies = 0;
zombiesDestroyed = 0;
map.generate();
map.paint();
ui.paintStatus();
}
public static var version = "v2"; // game version
}