PageRenderTime 2ms CodeModel.GetById 0ms 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
  1. import cui.window;
  2. import cui.label;
  3. import io.console;
  4. import djehuty;
  5. import gamecontrol;
  6. class GameWindow : CuiWindow {
  7. this() {
  8. scoreLabel = new CuiLabel(4, 5, 10, "0");
  9. game = new GameControl();
  10. push(scoreLabel);
  11. push(new CuiLabel(2, 3, 10, "Score", Color.Yellow));
  12. push(game);
  13. }
  14. override bool onSignal(Dispatcher source, uint signal) {
  15. if (source is game) {
  16. if(signal == GameControl.Event.ScoreUpdated) {
  17. scoreLabel.text = toStr(game.getScore());
  18. return true;
  19. }
  20. }
  21. return false;
  22. }
  23. override void onKeyDown(Key key) {
  24. if (key.ctrl && key.code == Key.Q) {
  25. application.exit(0);
  26. return;
  27. }
  28. super.onKeyDown(key);
  29. }
  30. int getScore() {
  31. return game.getScore();
  32. }
  33. protected:
  34. CuiLabel scoreLabel;
  35. GameControl game;
  36. }