Guest User

Untitled

a guest
Aug 28th, 2026
171
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.33 KB | None | 0 0
  1. //CurrentGameState.h
  2. #pragma once
  3. #include <string>
  4. #include "GameState.h"
  5.  
  6. class CurrentGameState
  7. {
  8. GameState* _currentState;
  9.  
  10. GameState _startState;
  11. //states
  12.  
  13. std::string _command;
  14. public:
  15.  
  16. CurrentGameState();
  17. ~CurrentGameState();
  18. void Loop();
  19. bool IsLooping();
  20. };
  21.  
  22. //CurrentGameState.cpp
  23. #include <iostream>
  24. #include "CurrentGameState.h"
  25.  
  26. CurrentGameState::CurrentGameState()
  27. {
  28. _currentState = &_startState;
  29. }
  30.  
  31. CurrentGameState::~CurrentGameState()
  32. {
  33.  
  34. }
  35.  
  36. void CurrentGameState::Loop()
  37. {
  38. std::cout << "Enter an action: ";
  39. getline(std::cin, _command);
  40. _currentState->Action(this, _command);//<- right here is where the issue occurs
  41.  
  42. system("pause");
  43. system("cls");
  44. }
  45.  
  46. bool CurrentGameState::IsLooping()
  47. {
  48. return _currentState != nullptr;
  49. }
  50.  
  51. //GameState.h
  52. #pragma once
  53. #include <iostream>
  54. #include "CurrentGameState.h"
  55.  
  56. class GameState
  57. {
  58.  
  59. public:
  60. virtual void OnPush();
  61. virtual void OnPop();
  62. virtual void Init();
  63. virtual void Action(CurrentGameState* currentGameState, std::string command);
  64. };
  65.  
  66. //GameState.cpp
  67. #include "GameState.h"
  68.  
  69. void GameState::OnPush()
  70. {
  71.  
  72. }
  73.  
  74. void GameState::OnPop()
  75. {
  76.  
  77. }
  78.  
  79. void GameState::Init()
  80. {
  81.  
  82. }
  83.  
  84. void GameState::Action(CurrentGameState* currentGameState, std::string command)
  85. {
  86. std::cout << "Action is: " << command << std::endl;
  87. }
Advertisement
Add Comment
Please, Sign In to add comment