因此,对于我的下一个游戏,我正在创建类以改善我的游戏架构我有一个名为 GameState 的抽象类,所有 GameState(菜单、窗口、屏幕、游戏本身)必须继承它才能添加到游戏中,但我的 BlankState是对我的 GameState 设计的测试让我遇到了编译器的麻烦,因为出于某种原因,它被认为是一个抽象类,谁能告诉我为什么?我觉得我在这里遗漏了一些非常明显的东西。
这是 GameState.h 的内容
#ifndef GUARD_GAMESTATE_H
#define GUARD_GAMESTATE_H
#include<SDL.h>
class Game;
class GameState {
protected:
Game *m_pGame;
public:
GameState( Game& );
virtual void load() = 0;
virtual void handle_events( SDL_Event& events ) = 0;
virtual void logic() = 0;
virtual void draw() = 0;
virtual void unload() = 0;
virtual ~GameState() = 0;
};
class BlankState : public GameState {
private:
SDL_Surface *background;
public:
BlankState(Game& game);
void load();
void handle_events();
void logic();
void draw();
void unload();
~BlankState();
};
#endif
这是我实现 GameState 构造函数和 BlankStates 继承方法的 GameState.cpp
#include"GameState.h"
#include"Game.h"
#include"AssetLoader.h"
GameState::GameState(Game& game) {
m_pGame = &game;
m_pGame->addState(this);
}
BlankState::BlankState(Game& game)
:GameState(game)
{}
void BlankState::load() {
background = AssetLoader::loadImage("assets\background.png");
}
void BlankState::handle_events() {}
void BlankState::logic() {}
void BlankState::draw() {
SDL_Rect lol;
lol.x = 0;
lol.y = 0;
SDL_BlitSurface(background, NULL, m_pGame->getSurface(), &lol);
}
void BlankState::unload() {
SDL_FreeSurface(background);
}
BlankState::~BlankState() {}
在此先感谢您的帮助