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.

102 lines
2.2KB

  1. from cli_Context import *
  2. from llm import *
  3. from memory import *
  4. # Greet the user
  5. @llm_by_value
  6. def cli_greetUser(
  7. c: cli_Context
  8. ) -> cli_Context:
  9. c.outputGreeting = "OGS Memory Command Line Interface"
  10. c.recentField = "outputGreeting"
  11. return c
  12. #}
  13. # Select item
  14. #
  15. # Conditions:
  16. # 1. Id is digit, in bounds and not hidden
  17. @llm_by_value
  18. def cli_selectItem(
  19. c: cli_Context
  20. ) -> cli_Context:
  21. if not (
  22. c.input.isdigit()
  23. ):
  24. c.recentField = "none"
  25. return c
  26. #}
  27. int(c.input) >= 1 and
  28. int(c.input) <= c.cMemory.playfieldSize * 2 and
  29. int(c.input) not in c.cMemory.hiddenItems
  30. ):
  31. # User ids start with 1 while memory module has ids starting with 0
  32. # Convert cli item id to memory item id
  33. c.cMemory.selectedId = int(c.input) - 1
  34. c.cMemory = memory_selectItem(c.cMemory)
  35. c.recentField = "cMemory"
  36. return c
  37. #}
  38. c.recentField = "none"
  39. return c
  40. #}
  41. # Ask user to select another item to have a pair of selected items
  42. @llm_by_value
  43. def cli_shouldPromptSelection(
  44. c: cli_Context
  45. ) -> cli_Context:
  46. if (
  47. c.recentField == "cMemory" and
  48. c.cMemory.recentField == "selectedItems" and
  49. len(c.cMemory.selectedItems) == 1
  50. ):
  51. c.outputPromptSelection = "Select the second item now:"
  52. c.recentField = "outputPromptSelection"
  53. return c
  54. #}
  55. c.recentField = "none"
  56. return c
  57. #}
  58. # Report selection of invalid item ids
  59. #
  60. # Conditions:
  61. # 1. Index out of bounds: less than minimum
  62. # 2. Index out of bounds: greater than maximum
  63. # 3. Item is already hidden
  64. #@llm_by_value
  65. #def cli_shouldReportInvalidItemSelection(
  66. # c: cli_Context
  67. #) -> cli_Context:
  68. # if (
  69. # c.recentField == "cMemory" and
  70. # c.cMemory.recentField == "selectedItems" and
  71. # len(c.cMemory.selectedItems) == 1
  72. # ):
  73. # c.outputPromptSelection = "Select the second item now:"
  74. # c.recentField = "outputPromptSelection"
  75. # return c
  76. # #}
  77. # c.recentField = "none"
  78. # return c
  79. ##}
  80. # Show help (aka commands)
  81. @llm_by_value
  82. def cli_showHelp(
  83. c: cli_Context
  84. ) -> cli_Context:
  85. if (
  86. c.input == "h" or
  87. c.input == "help"
  88. ):
  89. c.outputHelp = "Commands:\n\te, exit, q, quit\n\t\tExit\n\th, help\n\t\tList commands\n\t1, 2, 3, ...\n\t\tSelect item\n"
  90. c.recentField = "outputHelp"
  91. return c
  92. #}
  93. c.recentField = "none"
  94. return c
  95. #}