Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //CurrentGameState.h
- #pragma once
- #include <string>
- #include "GameState.h"
- class CurrentGameState
- {
- GameState* _currentState;
- GameState _startState;
- //states
- std::string _command;
- public:
- CurrentGameState();
- ~CurrentGameState();
- void Loop();
- bool IsLooping();
- };
- //CurrentGameState.cpp
- #include <iostream>
- #include "CurrentGameState.h"
- CurrentGameState::CurrentGameState()
- {
- _currentState = &_startState;
- }
- CurrentGameState::~CurrentGameState()
- {
- }
- void CurrentGameState::Loop()
- {
- std::cout << "Enter an action: ";
- getline(std::cin, _command);
- _currentState->Action(this, _command);//<- right here is where the issue occurs
- system("pause");
- system("cls");
- }
- bool CurrentGameState::IsLooping()
- {
- return _currentState != nullptr;
- }
- //GameState.h
- #pragma once
- #include <iostream>
- #include "CurrentGameState.h"
- class GameState
- {
- public:
- virtual void OnPush();
- virtual void OnPop();
- virtual void Init();
- virtual void Action(CurrentGameState* currentGameState, std::string command);
- };
- //GameState.cpp
- #include "GameState.h"
- void GameState::OnPush()
- {
- }
- void GameState::OnPop()
- {
- }
- void GameState::Init()
- {
- }
- void GameState::Action(CurrentGameState* currentGameState, std::string command)
- {
- std::cout << "Action is: " << command << std::endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment