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.

43 lines
909B

  1. #include <map>
  2. #include <string>
  3. #include "entities.h"
  4. // L4: Function.
  5. std::string memory_generateConstPlayfield(
  6. MemoryContext& c
  7. ) {
  8. std::map<int, int> idGroups = { };
  9. auto id = 0;
  10. for (auto gid = 0; gid < c.playfieldSize; ++gid) {
  11. idGroups[id] = gid;
  12. id += 1;
  13. idGroups[id] = gid;
  14. id += 1;
  15. }
  16. c.playfieldItems = idGroups;
  17. return "MemoryContext.playfieldItems";
  18. }
  19. // L20: Test.
  20. std::string test_memory_generateConstPlayfield(
  21. ) {
  22. auto c = memory_createEmptyContext();
  23. c.playfieldSize = 2;
  24. auto fieldName = memory_generateConstPlayfield(c);
  25. if (
  26. fieldName == "MemoryContext.playfieldItems" &&
  27. c.playfieldItems.size() == 4 &&
  28. c.playfieldItems[0] == 0 &&
  29. c.playfieldItems[1] == 0 &&
  30. c.playfieldItems[2] == 1 &&
  31. c.playfieldItems[3] == 1
  32. ) {
  33. return "OK: memory_generateConstPlayfield";
  34. }
  35. return "ERR: memory_generateConstPlayfield";
  36. }