-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstateMachine
More file actions
66 lines (54 loc) · 1.78 KB
/
stateMachine
File metadata and controls
66 lines (54 loc) · 1.78 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
54
55
56
57
58
59
60
61
62
63
64
65
66
class MyGame {
static public var game : Game;
static function main() {
game = new Game();
for (i in 0...10) {
game.update();
game.render();
}
game.switchState(new PlayState());
for (i in 0...10) {
game.update();
game.render();
}
}
}
class Game {
public var state : State;
public function new() {
state = new MenuState();
state.create();
}
public function update() {
state.update();
}
public function render() {
state.render();
}
public function switchState(state : State) {
this.state.destroy();
this.state = state;
this.state.create();
}
}
class State {
public function new() {}
public function create() {}
public function destroy() {}
public function update() {}
public function render() {}
}
class MenuState extends State {
public function new() { super(); }
override public function create() { super.create(); trace("Creating Menu State"); }
override public function destroy() { super.destroy(); trace("Destroying Menu State"); }
override public function update() { super.update(); trace("Updating Menu State"); }
override public function render() { super.render(); trace("Rendering Menu State"); }
}
class PlayState extends State {
public function new() { super(); }
override public function create() { super.create(); trace("Creating Play State"); }
override public function destroy() { super.destroy(); trace("Destroying Play State"); }
override public function update() { super.update(); trace("Updating Play State"); }
override public function render() { super.render(); trace("Rendering Play State"); }
}