Research portable Memory game | Исследовать портируемую игру Память
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

143 行
3.3KB

  1. from memory_api import *
  2. from memory_api_Context import *
  3. def memory_api_test_deselectMismatchedItems(
  4. ) -> str:
  5. c = memory_api_createContext()
  6. c.playfieldSize = 2
  7. c = memory_api_generateConstPlayfield(c)
  8. # Select two items of different groups.
  9. c.selectedId = 0
  10. c.recentField = "selectedId"
  11. c = memory_api_selectItem(c)
  12. c.selectedId = 2
  13. c.recentField = "selectedId"
  14. c = memory_api_selectItem(c)
  15. # Detect mismatching.
  16. c = memory_api_deselectMismatchedItems(c)
  17. # See if the two selected items do not match.
  18. if (
  19. c.recentField == "mismatchedItems" and
  20. len(c.mismatchedItems) == 2 and
  21. c.mismatchedItems[0] == 0 and
  22. c.mismatchedItems[1] == 2
  23. ):
  24. return "OK: memory_api_deselectMismatchedItems"
  25. #}
  26. return "ERR: memory_api_deselectMismatchedItems"
  27. #}
  28. def memory_api_test_detectVictory(
  29. ) -> str:
  30. c = memory_api_createContext()
  31. c.playfieldSize = 2
  32. c = memory_api_generateConstPlayfield(c)
  33. # Select the first two items of the same group.
  34. c.selectedId = 0
  35. c.recentField = "selectedId"
  36. c = memory_api_selectItem(c)
  37. c.selectedId = 1
  38. c.recentField = "selectedId"
  39. c = memory_api_selectItem(c)
  40. # Hide the first pair.
  41. c = memory_api_hideMatchingItems(c)
  42. # Select the last two items of the same group.
  43. c.selectedId = 2
  44. c.recentField = "selectedId"
  45. c = memory_api_selectItem(c)
  46. c.selectedId = 3
  47. c.recentField = "selectedId"
  48. c = memory_api_selectItem(c)
  49. # Hide the second pair.
  50. c = memory_api_hideMatchingItems(c)
  51. # Detect victory.
  52. c = memory_api_detectVictory(c)
  53. # See if victory has been detected.
  54. if (
  55. c.recentField == "victory" and
  56. c.victory == True
  57. ):
  58. return "OK: memory_api_detectVictory"
  59. #}
  60. return "ERR: memory_api_detectVictory"
  61. #}
  62. def memory_api_test_generateConstPlayfield(
  63. ) -> str:
  64. c = memory_api_createContext()
  65. c.playfieldSize = 2
  66. c = memory_api_generateConstPlayfield(c)
  67. if (
  68. c.recentField == "playfieldItems" and
  69. len(c.playfieldItems) == 4 and
  70. c.playfieldItems[0] == 0 and
  71. c.playfieldItems[1] == 0 and
  72. c.playfieldItems[2] == 1 and
  73. c.playfieldItems[3] == 1
  74. ):
  75. return "OK: memory_api_generateConstPlayfield"
  76. #}
  77. return "ERR: memory_api_generateConstPlayfield"
  78. #}
  79. def memory_api_test_hideMatchingItems(
  80. ) -> str:
  81. c = memory_api_createContext()
  82. c.playfieldSize = 2
  83. c = memory_api_generateConstPlayfield(c)
  84. # Select two items of the same group.
  85. c.selectedId = 0
  86. c.recentField = "selectedId"
  87. c = memory_api_selectItem(c)
  88. c.selectedId = 1
  89. c.recentField = "selectedId"
  90. c = memory_api_selectItem(c)
  91. # Hide matching items.
  92. c = memory_api_hideMatchingItems(c)
  93. # See if the two selected items match.
  94. if (
  95. c.recentField == "hiddenItems" and
  96. len(c.hiddenItems) == 2 and
  97. c.hiddenItems[0] == 0 and
  98. c.hiddenItems[1] == 1
  99. ):
  100. return "OK: memory_api_hideMatchingItems"
  101. #}
  102. return "ERR: memory_api_hideMatchingItems"
  103. #}
  104. def memory_api_test_selectItem(
  105. ) -> str:
  106. c = memory_api_createContext()
  107. c.playfieldSize = 2
  108. c = memory_api_generateConstPlayfield(c)
  109. # Select the first item.
  110. c.selectedId = 0
  111. c.recentField = "selectedId"
  112. c = memory_api_selectItem(c)
  113. # See if it's in selectedItems now.
  114. if (
  115. c.recentField == "selectedItems" and
  116. len(c.selectedItems) == 1 and
  117. c.selectedItems[0] == 0
  118. ):
  119. return "OK: memory_api_selectItem"
  120. #}
  121. return "ERR: memory_api_selectItem"
  122. #}