InGameState.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. function OnEnterInGameState() {
  2. ptwUI.showInGameUI();
  3. ptwUI.showCurrentQuestion();
  4. //register key functions
  5. $('.question-key').on(ptwUI.touchEnd,function (e) {
  6. var emptyKeys = $(this).parents(".question").find(".answer-key[data-key='']");
  7. var emptyKeysCount = emptyKeys.length;
  8. if (emptyKeysCount > 0) {
  9. ptwUI.appendCharactor($(emptyKeys[0]), $(this));
  10. emptyKeysCount = emptyKeysCount - 1;
  11. if (emptyKeysCount == 0) {
  12. if (controller.isAnswerCorrect()) {
  13. controller.processToNextQuestion();
  14. ptwUI.showSuccessUI();
  15. }
  16. else {
  17. ptwUI.onFailed();
  18. }
  19. }
  20. }
  21. });
  22. $(".answer-key").on(ptwUI.touchEnd,function (e) {
  23. var data_key = $(this).attr("data-key");
  24. if (data_key != null && data_key != '') {
  25. ptwUI.removeCharactor($(this));
  26. }
  27. if ( $(this).hasClass('error') ) {
  28. $(this).siblings().attr('class','answer-key');
  29. }
  30. });
  31. }
  32. function OnExitInGameState()
  33. {
  34. document.onkeydown = null;
  35. document.onkeyup = null;
  36. controller.stopGame();
  37. }
  38. var InGameState = new State( OnEnterInGameState, OnExitInGameState );