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.

125 lines
4.0KB

  1. #include <map>
  2. #include <string>
  3. #include <vector>
  4. #include "ctx.h"
  5. #ifndef memory_Context_HEADER
  6. #define memory_Context_HEADER
  7. struct memory_Context {
  8. bool didLaunch = false;
  9. bool exit = false;
  10. std::string input = "";
  11. std::vector<int> hiddenItems;
  12. std::vector<int> mismatchedItems;
  13. std::string recentField = "none";
  14. std::string outputGoOn = "";
  15. std::string outputGreeting = "";
  16. std::string outputHelp = "";
  17. std::string outputMatchedItems = "";
  18. std::string outputMismatchedItems = "";
  19. std::string outputPromptSelection = "";
  20. std::string outputVictory = "";
  21. std::map<int, int> playfieldItems;
  22. int playfieldSize = 0;
  23. int selectedId = -1;
  24. std::vector<int> selectedItems;
  25. bool victory = false;
  26. template <typename T> T field(const std::string &fieldName) {
  27. if (fieldName == "didLaunch") {
  28. return *reinterpret_cast<T*>(&didLaunch);
  29. } else if (fieldName == "exit") {
  30. return *reinterpret_cast<T*>(&exit);
  31. } else if (fieldName == "input") {
  32. return *reinterpret_cast<T*>(&input);
  33. } else if (fieldName == "hiddenItems") {
  34. return *reinterpret_cast<T*>(&hiddenItems);
  35. } else if (fieldName == "mismatchedItems") {
  36. return *reinterpret_cast<T*>(&mismatchedItems);
  37. } else if (fieldName == "outputGoOn") {
  38. return *reinterpret_cast<T*>(&outputGoOn);
  39. } else if (fieldName == "outputGreeting") {
  40. return *reinterpret_cast<T*>(&outputGreeting);
  41. } else if (fieldName == "outputHelp") {
  42. return *reinterpret_cast<T*>(&outputHelp);
  43. } else if (fieldName == "outputMatchedItems") {
  44. return *reinterpret_cast<T*>(&outputMatchedItems);
  45. } else if (fieldName == "outputMismatchedItems") {
  46. return *reinterpret_cast<T*>(&outputMismatchedItems);
  47. } else if (fieldName == "outputPromptSelection") {
  48. return *reinterpret_cast<T*>(&outputPromptSelection);
  49. } else if (fieldName == "outputVictory") {
  50. return *reinterpret_cast<T*>(&outputVictory);
  51. } else if (fieldName == "playfieldItems") {
  52. return *reinterpret_cast<T*>(&playfieldItems);
  53. } else if (fieldName == "playfieldSize") {
  54. return *reinterpret_cast<T*>(&playfieldSize);
  55. } else if (fieldName == "selectedId") {
  56. return *reinterpret_cast<T*>(&selectedId);
  57. } else if (fieldName == "selectedItems") {
  58. return *reinterpret_cast<T*>(&selectedItems);
  59. }
  60. // victory
  61. return *reinterpret_cast<T*>(&victory);
  62. }
  63. void setField(const std::string &fieldName, bool value) {
  64. if (fieldName == "didLaunch") {
  65. didLaunch = value;
  66. } else if (fieldName == "exit") {
  67. exit = value;
  68. } else if (fieldName == "victory") {
  69. victory = value;
  70. }
  71. }
  72. void setField(const std::string &fieldName, const std::string &value) {
  73. if (fieldName == "input") {
  74. input = value;
  75. } else if (fieldName == "outputGoOn") {
  76. outputGoOn = value;
  77. } else if (fieldName == "outputGreeting") {
  78. outputGreeting = value;
  79. } else if (fieldName == "outputHelp") {
  80. outputHelp = value;
  81. } else if (fieldName == "outputMatchedItems") {
  82. outputMatchedItems = value;
  83. } else if (fieldName == "outputMismatchedItems") {
  84. outputMismatchedItems = value;
  85. } else if (fieldName == "outputPromptSelection") {
  86. outputPromptSelection = value;
  87. } else if (fieldName == "outputVictory") {
  88. outputVictory = value;
  89. }
  90. }
  91. void setField(const std::string &fieldName, const std::vector<int> &value) {
  92. if (fieldName == "hiddenItems") {
  93. hiddenItems = value;
  94. } else if (fieldName == "mismatchedItems") {
  95. mismatchedItems = value;
  96. } else if (fieldName == "selectedItems") {
  97. selectedItems = value;
  98. }
  99. }
  100. void setField(const std::string &fieldName, const std::map<int, int> &value) {
  101. if (fieldName == "playfieldItems") {
  102. playfieldItems = value;
  103. }
  104. }
  105. void setField(const std::string &fieldName, int value) {
  106. if (fieldName == "playfieldSize") {
  107. playfieldSize = value;
  108. } else if (fieldName == "selectedId") {
  109. selectedId = value;
  110. }
  111. }
  112. };
  113. memory_Context memory_createContext();
  114. #endif // memory_Context_HEADER