Research portable Memory game | Исследовать портируемую игру Память
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

89 lines
2.1KB

  1. from cli import *
  2. from cli_test import *
  3. from memory_test import *
  4. from Controller import *
  5. #from shell import *
  6. #import sys
  7. print(memory_test_deselectMismatchedItems())
  8. print(memory_test_deselectMismatchedItems_itemTwice())
  9. print(memory_test_detectVictory())
  10. print(memory_test_generateConstPlayfield())
  11. print(memory_test_hideMatchingItems())
  12. print(memory_test_selectItem_1x())
  13. print(memory_test_selectItem_2x())
  14. print(memory_test_selectItem_3x())
  15. print(cli_test_greetUser())
  16. #print(cli_test_selectItem())
  17. #print(cli_test_shouldPromptSelection())
  18. ##print(cli_test_shouldReportIvalidItemSelection_outOfBoundsMin())
  19. #print(cli_test_showHelp_h())
  20. #print(cli_test_showHelp_help())
  21. ctrl = Controller(memory_createContext())
  22. ctrl.registerFunction(cli_greetUser)
  23. ctrl.registerFunction(cli_showHelp)
  24. ctrl.registerCallback(lambda c: print(f"ИГР App.dbg ctx: '{c}'"))
  25. def printOutput(c):
  26. if c.recentField.startswith("output"):
  27. print(getattr(c, c.recentField))
  28. ctrl.registerCallback(printOutput)
  29. #
  30. #c = shell_createContext()
  31. #c.cCLI = cli_createContext()
  32. #c.cCLI.cMemory = memory_createContext()
  33. #c.cCLI.cMemory.playfieldSize = 2
  34. #c.cCLI.cMemory = memory_generateConstPlayfield(c.cCLI.cMemory)
  35. #
  36. #c = shell_launch(c)
  37. #print(c.output)
  38. #
  39. ctrl.set("didLaunch", True)
  40. #for line in sys.stdin:
  41. # c.input = line.rstrip()
  42. # c = shell_processInput(c)
  43. # if c.exit:
  44. # break
  45. # print(c.output)
  46. import threading
  47. import time
  48. class KeyboardThread(threading.Thread):
  49. def __init__(self, input_cbk = None, name='keyboard-input-thread'):
  50. self.input_cbk = input_cbk
  51. super(KeyboardThread, self).__init__(name=name, daemon=True)
  52. self.start()
  53. def run(self):
  54. while True:
  55. self.input_cbk(input()) #waits to get input + Return
  56. showcounter = 0 #something to demonstrate the change
  57. def my_callback(inp):
  58. #evaluate the keyboard input
  59. print('You Entered:', inp, ' Counter is at:', showcounter)
  60. #start the Keyboard thread
  61. kthread = KeyboardThread(my_callback)
  62. while True:
  63. #the normal program executes without blocking. here just counting up
  64. showcounter += 1
  65. time.sleep(0.5)