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.

memory_Context.cpp 3.3KB

5 months ago
5 months ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #include <utility>
  2. #include "any.h"
  3. #include "memory_Context.h"
  4. #include <iostream>
  5. libany::any memory_Context::field(const std::string &fieldName) {
  6. if (fieldName == "didLaunch") {
  7. return didLaunch;
  8. } else if (fieldName == "exit") {
  9. return exit;
  10. } else if (fieldName == "hiddenItems") {
  11. return hiddenItems;
  12. } else if (fieldName == "input") {
  13. return input;
  14. } else if (fieldName == "mismatchedItems") {
  15. return mismatchedItems;
  16. } else if (fieldName == "outputGoOn") {
  17. return outputGoOn;
  18. } else if (fieldName == "outputGreeting") {
  19. return outputGreeting;
  20. } else if (fieldName == "outputHelp") {
  21. return outputHelp;
  22. } else if (fieldName == "outputMatchedItems") {
  23. return outputMatchedItems;
  24. } else if (fieldName == "outputMismatchedItems") {
  25. return outputMismatchedItems;
  26. } else if (fieldName == "outputPromptSelection") {
  27. return outputPromptSelection;
  28. } else if (fieldName == "outputVictory") {
  29. return outputVictory;
  30. } else if (fieldName == "playfieldItems") {
  31. return playfieldItems;
  32. } else if (fieldName == "playfieldSize") {
  33. return playfieldSize;
  34. } else if (fieldName == "selectedId") {
  35. return selectedId;
  36. } else if (fieldName == "selectedItems") {
  37. return selectedItems;
  38. }
  39. // victory
  40. return victory;
  41. }
  42. void memory_Context::setField(const std::string &fieldName, libany::any value) {
  43. if (fieldName == "didLaunch") {
  44. didLaunch = libany::any_cast<bool>(value);
  45. } else if (fieldName == "exit") {
  46. exit = libany::any_cast<bool>(value);
  47. } else if (fieldName == "hiddenItems") {
  48. hiddenItems = libany::any_cast<std::vector<int> >(value);
  49. } else if (fieldName == "input") {
  50. std::cout << "memory_Context-01\n";
  51. try {
  52. input = libany::any_cast<std::string>(value);
  53. } catch (libany::bad_any_cast &e) {
  54. std::cout << "memory_Context-01 exception/type: " << e.what() << ", " << value.type().name() << std::endl;
  55. }
  56. std::cout << "memory_Context-02\n";
  57. } else if (fieldName == "mismatchedItems") {
  58. mismatchedItems = libany::any_cast<std::vector<int> >(value);
  59. } else if (fieldName == "outputGoOn") {
  60. outputGoOn = libany::any_cast<std::string>(value);
  61. } else if (fieldName == "outputGreeting") {
  62. outputGreeting = libany::any_cast<std::string>(value);
  63. } else if (fieldName == "outputHelp") {
  64. outputHelp = libany::any_cast<std::string>(value);
  65. } else if (fieldName == "outputMatchedItems") {
  66. outputMatchedItems = libany::any_cast<std::string>(value);
  67. } else if (fieldName == "outputMismatchedItems") {
  68. outputMismatchedItems = libany::any_cast<std::string>(value);
  69. } else if (fieldName == "outputPromptSelection") {
  70. outputPromptSelection = libany::any_cast<std::string>(value);
  71. } else if (fieldName == "outputVictory") {
  72. outputVictory = libany::any_cast<std::string>(value);
  73. } else if (fieldName == "playfieldItems") {
  74. playfieldItems = libany::any_cast<std::map<int, int> >(value);
  75. } else if (fieldName == "playfieldSize") {
  76. playfieldSize = libany::any_cast<int>(value);
  77. } else if (fieldName == "selectedId") {
  78. selectedId = libany::any_cast<int>(value);
  79. } else if (fieldName == "selectedItems") {
  80. selectedItems = libany::any_cast<std::vector<int> >(value);
  81. } else if (fieldName == "victory") {
  82. victory = libany::any_cast<bool>(value);
  83. }
  84. }
  85. memory_Context memory_createContext() {
  86. return memory_Context();
  87. }