From 9a23bd154771f7a5eef1252dacabee7274f518d9 Mon Sep 17 00:00:00 2001 From: Tamir Atias Date: Fri, 3 Feb 2012 01:43:47 +0200 Subject: [PATCH] [Add] New & Load in main menu now functioning properly. --- src/Unuk/Game.cpp | 16 +++++++++++----- src/Unuk/Game.h | 5 ++++- src/Unuk/main.cpp | 32 +++++++++++++++++++++++++++----- 3 files changed, 42 insertions(+), 11 deletions(-) diff --git a/src/Unuk/Game.cpp b/src/Unuk/Game.cpp index f2f049d..5c85285 100644 --- a/src/Unuk/Game.cpp +++ b/src/Unuk/Game.cpp @@ -17,12 +17,19 @@ Game::~Game(void) { //delete _player; } -gameNavVal_t Game::Run(const string savegameIDArg) { +void Game::New(const string& savegameIDArg) { + NewSavegame(savegameIDArg); + _map.Load("map"); +} + +void Game::Load(const string& savegameIDArg) { + LoadSavegame(savegameIDArg); +} + +gameNavVal_t Game::Run(void) { _player->SetXY(400, 400); _player->LoadSprites("../Data/Media/Images/Characters/Player.png", 40, 45); - LoadSavegame(savegameIDArg); - int fps = 0; int frame = 0; int nextGameTick = SDL_GetTicks(); @@ -307,8 +314,7 @@ void Game::LoadSavegame(const string savegameIDArg) { // Create new save if can't load file. if(!mapFile.LoadFile()) { - NewSavegame(savegameIDArg); - _map.Load("map"); + New(savegameIDArg); return; } diff --git a/src/Unuk/Game.h b/src/Unuk/Game.h index 4f238ae..f393464 100644 --- a/src/Unuk/Game.h +++ b/src/Unuk/Game.h @@ -25,8 +25,11 @@ class Game { public: Game(void); ~Game(void); + + void New(const string& savegameIDArg); + void Load(const string& savegameIDArg); - gameNavVal_t Run(const string savegameIDArg); + gameNavVal_t Run(void); private: void HandleInput(void); diff --git a/src/Unuk/main.cpp b/src/Unuk/main.cpp index d0e9489..050d74e 100644 --- a/src/Unuk/main.cpp +++ b/src/Unuk/main.cpp @@ -24,6 +24,23 @@ #endif #endif +static gameNavVal_t RunGame(bool load) { + Debug::logger->message("Entering game state.."); + Game* game = new Game; + + if(load) { + game->Load("save"); + } else { + game->New("save"); + } + + gameNavVal_t ret = game->Run(); + + delete game; + + return ret; +} + #if !defined(_WIN32) || defined(_DEBUG) int main() { #else @@ -78,10 +95,7 @@ int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int) { switch(menu->Run()) { case mainMenuNewGame: delete menu; - Debug::logger->message("Entering game state.."); - game = new Game; - - switch(game->Run("save")) { + switch(RunGame(false)) { case gameMainMenu: menu = new MainMenu; break; @@ -89,9 +103,17 @@ int WINAPI WinMain(HINSTANCE,HINSTANCE,LPSTR,int) { menuRunning = false; break; } - delete game; break; case mainMenuLoadGame: + delete menu; + switch(RunGame(true)) { + case gameMainMenu: + menu = new MainMenu; + break; + case gameQuitGame: + menuRunning = false; + break; + } break; case mainMenuOptions: break;