2011-06-22 20:12:22 +00:00
|
|
|
/* Do basic initialization, get the loop going */
|
|
|
|
|
2011-06-28 02:07:52 +00:00
|
|
|
#include "gamestate.h"
|
|
|
|
#include "game.h"
|
|
|
|
#include <SDL.h>
|
2011-06-22 20:12:22 +00:00
|
|
|
|
2011-06-28 02:07:52 +00:00
|
|
|
int main(int argc, char** argv)
|
2011-06-22 20:12:22 +00:00
|
|
|
{
|
2011-06-28 02:07:52 +00:00
|
|
|
// Barebones setup for our game
|
|
|
|
if (SDL_Init(SDL_INIT_EVERYTHING) < 0) return false;
|
|
|
|
SDL_WM_SetCaption("TreeWars","TreeWars");
|
|
|
|
|
|
|
|
stack<GameState*> state_stack;
|
|
|
|
|
|
|
|
// initialize the stack by initting and pushing the initial state(s)
|
|
|
|
GameState* tmpstate = new Game();
|
|
|
|
if (!tmpstate->init()) exit(1);
|
|
|
|
state_stack.push(tmpstate);
|
|
|
|
|
|
|
|
while (!state_stack.empty())
|
|
|
|
{
|
|
|
|
GameState* state = state_stack.top();
|
|
|
|
try {
|
|
|
|
state->execute(state_stack);
|
|
|
|
} catch (StateExit& e) {
|
|
|
|
|
|
|
|
// remove the old state
|
|
|
|
state_stack.pop();
|
|
|
|
delete state;
|
|
|
|
|
|
|
|
// init the new state, discarding it if we fail
|
|
|
|
while (!(state_stack.empty() || state_stack.top()->init()))
|
|
|
|
{
|
|
|
|
state_stack.pop();
|
|
|
|
delete state;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
SDL_Quit();
|
|
|
|
|
|
|
|
return 0;
|
2011-06-22 20:12:22 +00:00
|
|
|
}
|