treewars/gamestate.h

42 lines
823 B
C
Raw Normal View History

/* Abstract instance of a game state.
This contains the basic functions for game looping code,
and has a fully-functional event handler we can overload later
*/
#ifndef _GAME_STATE_H_
#define _GAME_STATE_H_
#include "mainevent.h"
#include <SDL.h>
#include <exception>
#include <stack>
using std::exception;
using std::stack;
class StateExit : public exception {};
class GameState : public MainEvent
{
public:
GameState(stack<GameState*>* state_stack, SDL_Surface* display);
virtual ~GameState() {}
virtual bool init() = 0;
void execute() throw(StateExit);
bool initted() { return init_done;}
protected:
virtual void iterate() = 0;
virtual void render() = 0;
void on_exit();
stack<GameState*>* state_stack;
SDL_Surface* display;
bool init_done;
};
#endif