PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/examples/CuiTetris/gamewindow.d

http://github.com/wilkie/djehuty
D | 46 lines | 36 code | 10 blank | 0 comment | 6 complexity | ffa34d7fbf35625efaa3c1a736082ba6 MD5 | raw file
 1import cui.window;
 2import cui.label;
 3
 4import io.console;
 5
 6import djehuty;
 7
 8import gamecontrol;
 9
10class GameWindow : CuiWindow {
11	this() {
12		scoreLabel = new CuiLabel(4, 5, 10, "0");
13		game = new GameControl();
14
15		push(scoreLabel);
16		push(new CuiLabel(2, 3, 10, "Score", Color.Yellow));
17		push(game);
18	}
19
20	override bool onSignal(Dispatcher source, uint signal) {
21		if (source is game) {
22			if(signal == GameControl.Event.ScoreUpdated) {
23				scoreLabel.text = toStr(game.getScore());
24				return true;
25			}
26		}
27
28		return false;
29	}
30
31	override void onKeyDown(Key key) {
32		if (key.ctrl && key.code == Key.Q) {
33			application.exit(0);
34			return;
35		}
36		super.onKeyDown(key);
37	}
38
39	int getScore() {
40		return game.getScore();
41	}
42
43protected:
44	CuiLabel scoreLabel;
45	GameControl game;
46}