I'm writing my semester project and it has to be made in C++ and I'm more into other languages. I would like to create a thing that is managing my game states, but I'm not doing well. I made the same game state managing system in Java and I would like to keep the same appropach.
gsm.h
#pragma once
#include <iostream>
#include <map>
#include "gamestate.h"
class GameStateManager {
private:
std::map<int, GameState> gameStates;
GameState currentState;
public:
GameStateManager();
void method();
void add(int id, GameState state);
};
gsm.cpp
#include "gsm.h"
#include "playstate.h"
GameStateManager::GameStateManager() {
}
void GameStateManager::add(int id, GameState state) {
gameStates.insert(id, state);
}
void GameStateManager::method() {
currentState.method();
}
gamestate.h
#pragma once
#include "gsm.h"
class GameState {
protected:
GameStateManager gsm;
public:
GameState(GameStateManager gsm);
virtual void method();
};
gamestate.cpp
#include "gamestate.h"
GameState::GameState(GameStateManager gsm) : gsm(gsm) { }
playstate.h
#pragma once
#include "gamestate.h"
class PlayState : public GameState {
public:
PlayState(GameStateManager gsm);
void method() override;
};
playstate.cpp
#include "playstate.h"
#include "gamestate.h"
#include <cstdio>
PlayState::PlayState(GameStateManager gsm): GameState(gsm) {}
void PlayState::method() {
printf("Say hello");
}
main.cpp
#include "gamestate.h"
#include "gsm.h"
#include "playstate.h"
int main() {
GameStateManager gsm;
PlayState playState(gsm);
gsm.add(0, playState);
}
I got a lot of errors like: 'GameState': undeclared identifier, syntax error: indetifier 'GameState'
Aucun commentaire:
Enregistrer un commentaire