Research portable Memory game | Исследовать портируемую игру Память
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

64 lignes
1.3KB

  1. from entities import *
  2. def memory_generateConstPlayfield(
  3. c: MemoryContext
  4. ) -> str:
  5. idGroups: dict[int, int] = { }
  6. id = 0
  7. for gid in range(0, c.playfieldSize):
  8. idGroups[id] = gid
  9. id += 1
  10. idGroups[id] = gid
  11. id += 1
  12. #}
  13. c.playfieldItems = idGroups
  14. return "playfieldItems"
  15. #}
  16. def memory_selectItem(
  17. c: MemoryContext,
  18. id: int
  19. ) -> str:
  20. c.selectedItems.append(id)
  21. return "selectedItems"
  22. #}
  23. # Test.
  24. def test_memory_generateConstPlayfield(
  25. ) -> str:
  26. c = memory_createEmptyContext()
  27. c.playfieldSize = 2
  28. fieldName = memory_generateConstPlayfield(c)
  29. if (
  30. fieldName == "playfieldItems" and
  31. len(c.playfieldItems) == 4 and
  32. c.playfieldItems[0] == 0 and
  33. c.playfieldItems[1] == 0 and
  34. c.playfieldItems[2] == 1 and
  35. c.playfieldItems[3] == 1
  36. ):
  37. return "OK: memory_generateConstPlayfield"
  38. #}
  39. return "ERR: memory_generateConstPlayfield"
  40. #}
  41. def test_memory_selectItem(
  42. ) -> str:
  43. c = memory_createEmptyContext()
  44. c.playfieldSize = 2
  45. memory_generateConstPlayfield(c)
  46. # Select the item with group 0.
  47. fieldName = memory_selectItem(c, 0)
  48. # See if it's in selectedItems now.
  49. if (
  50. fieldName == "selectedItems" and
  51. len(c.selectedItems) == 1 and
  52. c.selectedItems[0] == 0
  53. ):
  54. return "OK: memory_selectItem"
  55. #}
  56. return "ERR: memory_selectItem"
  57. #}