Commits

Rhys ! committed 120442b Draft

refactored to not use singletons

  • Participants
  • Parent commits 4ac51a1

Comments (0)

Files changed (28)

 								<option id="llvm.c.link.option.paths.1743481513" name="Library search path (-L)" superClass="llvm.c.link.option.paths" valueType="libPaths">
 									<listOptionValue builtIn="false" value="/usr/lib"/>
 									<listOptionValue builtIn="false" value="/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6"/>
-									<listOptionValue builtIn="false" value="/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5/"/>
+									<listOptionValue builtIn="false" value="/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6/"/>
 								</option>
 								<inputType id="cdt.managedbuild.tool.llvm.c.linker.input.2024826335" superClass="cdt.managedbuild.tool.llvm.c.linker.input">
 									<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>
 								</option>
 								<option id="llvm.c_cpp.compiler.option.optimization.level.2101210747" name="Optimization Level" superClass="llvm.c_cpp.compiler.option.optimization.level" value="llvm.c_cpp.compiler.optimization.level.none" valueType="enumerated"/>
 								<option id="llvm.c_cpp.compiler.option.debugging.level.1116714121" name="Debug Level" superClass="llvm.c_cpp.compiler.option.debugging.level" value="llvm.c_cpp.compiler.debugging.level.max" valueType="enumerated"/>
-								<option id="llvm.c_cpp.compiler.option.misc.other.350487282" superClass="llvm.c_cpp.compiler.option.misc.other" value="-c -fmessage-length=0 -std=c++0x" valueType="string"/>
+								<option id="llvm.c_cpp.compiler.option.misc.other.350487282" name="Other flags" superClass="llvm.c_cpp.compiler.option.misc.other" value="-c -fmessage-length=0 -std=c++0x -Weverything -Wno-c++98-compat -Wno-shadow -Wno-weak-vtables -Wno-padded" valueType="string"/>
+								<option id="llvm.c_cpp.compiler.option.warnings.allwarn.1406711839" name="All warnings (-Wall)" superClass="llvm.c_cpp.compiler.option.warnings.allwarn" value="false" valueType="boolean"/>
 								<inputType id="cdt.managedbuild.tool.llvm.cpp.compiler.input.1179866234" superClass="cdt.managedbuild.tool.llvm.cpp.compiler.input"/>
 							</tool>
 						</toolChain>
 								</option>
 								<option id="llvm.c.link.option.paths.56092692" name="Library search path (-L)" superClass="llvm.c.link.option.paths" valueType="libPaths">
 									<listOptionValue builtIn="false" value="/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6"/>
-									<listOptionValue builtIn="false" value="/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.5/"/>
+									<listOptionValue builtIn="false" value="/usr/lib/x86_64-linux-gnu/gcc/x86_64-linux-gnu/4.6/"/>
 								</option>
 								<inputType id="cdt.managedbuild.tool.llvm.c.linker.input.1256476665" superClass="cdt.managedbuild.tool.llvm.c.linker.input">
 									<additionalInput kind="additionalinputdependency" paths="$(USER_OBJS)"/>

.settings/org.eclipse.ltk.core.refactoring.prefs

+eclipse.preferences.version=1
+org.eclipse.ltk.core.refactoring.enable.project.refactoring.history=false

AboutStage.h

-/*
- * AboutStage.h
- *
- *  Created on: 19/08/2012
- *      Author: rhys
- */
-
-#ifndef ABOUTSTAGE_H_
-#define ABOUTSTAGE_H_
-
-#include "SimpleDisplayStage.h"
-
-class AboutStage : public SimpleDisplayStage {
-public:
-    static AboutStage& instance() {
-        static AboutStage ins;
-        return ins;
-    }
-
-    virtual void add_strings() {
-        cout << "===ABOUT ZORKISH===" << endl;
-        cout << "Written by: Rhys Adams" << endl;
-    }
-
-private:
-    AboutStage() = default;
-    AboutStage(const AboutStage&) = delete;
-    void operator=(const AboutStage&) = delete;
-};
-
-#endif /* ABOUTSTAGE_H_ */
+/*
+ * AboutStage.hpp
+ *
+ *  Created on: 19/08/2012
+ *      Author: rhys
+ */
+
+#ifndef ABOUTSTAGE_HPP_
+#define ABOUTSTAGE_HPP_
+
+#include "SimpleDisplayStage.hpp"
+
+class AboutStage : public SimpleDisplayStage {
+public:
+    AboutStage(ZorkishGame& game) : SimpleDisplayStage(game) {};
+
+    virtual void print_message() {
+        using std::cout;
+        cout << "===ABOUT ZORKISH===\n";
+        cout << "Written by: Rhys Adams\n";
+    }
+};
+
+#endif /* ABOUTSTAGE_HPP_ */

ActiveStageManager.hpp

+/*
+ * ActiveStageManager.hpp
+ *
+ *  Created on: 19/08/2012
+ *      Author: rhys
+ */
+
+#ifndef ACTIVESTAGEMANAGER_HPP_
+#define ACTIVESTAGEMANAGER_HPP_
+
+#include <stack>
+#include "GameStage.hpp"
+
+class ActiveStageManager {
+private:
+    GameStage* next_stage = nullptr;
+    std::stack<GameStage*> stage_stack;
+
+public:
+    bool ready() {
+        return !this->stage_stack.empty();
+    }
+
+    void set_next_stage(GameStage* stage) {
+        if (this->stage_stack.empty()) {
+            this->stage_stack.push(stage);
+            stage->activate();
+        } else {
+            this->next_stage = stage;
+        }
+    }
+
+    void update() {
+        GameStage* current_stage = this->stage_stack.top();
+        GameStage::Status css = current_stage->update(this);
+
+        if (this->next_stage != nullptr || css == GameStage::Status::FINISH) {
+            current_stage->deactivate();
+        }
+
+        if (css == GameStage::Status::FINISH) {
+            current_stage->cleanup();
+            this->stage_stack.pop();
+        }
+
+        if (this->next_stage != nullptr) {
+            this->stage_stack.push(next_stage);
+            next_stage->activate();
+            next_stage = nullptr;
+        }
+    }
+
+    void draw() {
+        this->stage_stack.top()->draw();
+    }
+};
+
+#endif /* ACTIVESTAGEMANAGER_HPP_ */

ConsoleStage.h

-/*
- * ConsoleStage.h
- *
- *  Created on: 20/08/2012
- *      Author: rhys
- */
-
-#ifndef CONSOLESTAGE_H_
-#define CONSOLESTAGE_H_
-
-#include <boost/lexical_cast.hpp>
-#include <iostream>
-using namespace std;
-
-class ConsoleStage : public GameStage {
-protected:
-    int input_int() {
-        string in;
-        getline(cin, in);
-        try {
-            return boost::lexical_cast<int>(in);
-        } catch (boost::bad_lexical_cast&) {
-            return -1;
-        }
-    }
-};
-
-
-#endif /* CONSOLESTAGE_H_ */

GameStage.h

-/*
- * GameStage.h
- *
- *  Created on: 19/08/2012
- *      Author: rhys
- */
-
-#ifndef GAMESTAGE_H_
-#define GAMESTAGE_H_
-
-class StageManager;
-
-class GameStage {
-public:
-    enum class Status { CONTINUE, FINISH };
-
-    virtual ~GameStage() {};
-
-    // Called each time the stage becomes active.
-    virtual void activate() { };
-    // Called each time the stage becomes inactive, by finishing or being
-    // pushed down the stage stack.
-    virtual void deactivate() { };
-    // Called each time the stage becomes inactive by finishing.
-    virtual void cleanup() { };
-    virtual Status update(StageManager* smgr) = 0;
-    virtual void draw() = 0;
-};
-
-#endif /* GAMESTAGE_H_ */
+/*
+ * GameStage.hpp
+ *
+ *  Created on: 19/08/2012
+ *      Author: rhys
+ */
+
+#ifndef GAMESTAGE_HPP_
+#define GAMESTAGE_HPP_
+
+class ActiveStageManager;
+
+class GameStage {
+public:
+    enum class Status { CONTINUE, FINISH };
+
+    virtual ~GameStage() = default;
+
+    // Called each time the stage becomes active.
+    virtual void activate() { };
+    // Called each time the stage becomes inactive, by finishing or being
+    // pushed down the stage stack.
+    virtual void deactivate() { };
+    // Called each time the stage becomes inactive by finishing.
+    virtual void cleanup() { };
+    virtual Status update(ActiveStageManager* smgr) = 0;
+    virtual void draw() = 0;
+};
+
+#endif /* GAMESTAGE_HPP_ */

GameState.h

-/*
- * GameState.h
- *
- *  Created on: 20/08/2012
- *      Author: rhys
- */
-
-#ifndef GAMESTATE_H_
-#define GAMESTATE_H_
-
-#include <string>
-
-class GameState {
-public:
-    int score = 0;
-    string adventure;
-    int moves = 0;
-
-    static GameState& instance() {
-        static GameState ins;
-        return ins;
-    }
-
-private:
-    GameState() = default;
-    GameState(const GameState&) = delete;
-    void operator=(const GameState&) = delete;
-};
-
-
-#endif /* GAMESTATE_H_ */

HallOfFameStage.h

-/*
- * HallOfFameStage.h
- *
- *  Created on: 20/08/2012
- *      Author: rhys
- */
-
-#ifndef HALLOFFAMESTAGE_H_
-#define HALLOFFAMESTAGE_H_
-
-#include "SimpleDisplayStage.h"
-
-class HallOfFameStage : public SimpleDisplayStage {
-public:
-    static HallOfFameStage& instance() {
-        static HallOfFameStage ins;
-        return ins;
-    }
-
-    virtual void add_strings() {
-        cout << "===HALL OF FAME===" << endl;
-        cout << "Top 10 Zorkish Adventure Champions\n" << endl;
-        cout << "    1. Fred, Mountain World, 5000" << endl;
-        cout << "    2. Mary, Mountain World, 4000" << endl;
-        cout << "    3. Joe, Water World, 3000" << endl;
-        cout << "    4. Henry, Mountain World, 2000" << endl;
-        cout << "    5. Susan, Mountain World, 1000" << endl;
-        cout << "    6. Alfred, Water World, 900" << endl;
-        cout << "    7. Clark, Mountain World, 800" << endl;
-        cout << "    8. Harold, Mountain World, 500" << endl;
-        cout << "    9. Julie, Water World, 300" << endl;
-        cout << "   10. Bill, Box World, -5" << endl;
-    }
-
-private:
-    HallOfFameStage() = default;
-    HallOfFameStage(const HallOfFameStage&) = delete;
-    void operator=(const HallOfFameStage&) = delete;
-};
-
-#endif /* HALLOFFAMESTAGE_H_ */

HallOfFameStage.hpp

+/*
+ * HallOfFameStage.hpp
+ *
+ *  Created on: 20/08/2012
+ *      Author: rhys
+ */
+
+#ifndef HALLOFFAMESTAGE_HPP_
+#define HALLOFFAMESTAGE_HPP_
+
+#include "SimpleDisplayStage.hpp"
+
+class HallOfFameStage : public SimpleDisplayStage {
+public:
+    HallOfFameStage(ZorkishGame& game) : SimpleDisplayStage(game) {};
+
+    virtual void print_message() {
+        using std::cout;
+        cout << "===HALL OF FAME===";
+        cout << "Top 10 Zorkish Adventure Champions\n\n";
+        cout << "    1. Fred, Mountain World, 5000\n";
+        cout << "    2. Mary, Mountain World, 4000\n";
+        cout << "    3. Joe, Water World, 3000\n";
+        cout << "    4. Henry, Mountain World, 2000\n";
+        cout << "    5. Susan, Mountain World, 1000\n";
+        cout << "    6. Alfred, Water World, 900\n";
+        cout << "    7. Clark, Mountain World, 800\n";
+        cout << "    8. Harold, Mountain World, 500\n";
+        cout << "    9. Julie, Water World, 300\n";
+        cout << "   10. Bill, Box World, -5\n";
+    }
+};
+
+#endif /* HALLOFFAMESTAGE_HPP_ */

HelpStage.h

-/*
- * HelpStage.h
- *
- *  Created on: 19/08/2012
- *      Author: rhys
- */
-
-#ifndef HELPSTAGE_H_
-#define HELPSTAGE_H_
-
-#include "SimpleDisplayStage.h"
-
-class HelpStage : public SimpleDisplayStage {
-public:
-    static HelpStage& instance() {
-        static HelpStage ins;
-        return ins;
-    }
-
-    virtual void add_strings() {
-        cout << "===HELP===" << endl;
-        cout << "The following commands are supported:" << endl << endl;
-        cout << "quit" << endl;
-        cout << "hiscore" << endl;
-    }
-
-private:
-    HelpStage() = default;
-    HelpStage(const HelpStage&) = delete;
-    void operator=(const HelpStage&) = delete;
-};
-
-#endif /* HELPSTAGE_H_ */
+/*
+ * HelpStage.hpp
+ *
+ *  Created on: 19/08/2012
+ *      Author: rhys
+ */
+
+#ifndef HELPSTAGE_HPP_
+#define HELPSTAGE_HPP_
+
+#include "SimpleDisplayStage.hpp"
+
+class HelpStage : public SimpleDisplayStage {
+public:
+    HelpStage(ZorkishGame& game) : SimpleDisplayStage(game) {};
+
+    virtual void print_message() {
+        using std::cout;
+        cout << "===HELP===\n";
+        cout << "The following commands are supported:\n\n";
+        cout << "quit\n";
+        cout << "hiscore\n";
+    }
+};
+
+#endif /* HELPSTAGE_HPP_ */

HighScoreStage.h

-/*
- * HiScoreStage.h
- *
- *  Created on: 20/08/2012
- *      Author: rhys
- */
-
-#ifndef HIGHSCORESTAGE_H_
-#define HIGHSCORESTAGE_H_
-
-#include <iostream>
-#include "GameStage.h"
-#include "GameState.h"
-using namespace std;
-
-class HighScoreStage : public GameStage {
-public:
-    static HighScoreStage& instance() {
-        static HighScoreStage ins;
-        return ins;
-    }
-
-    virtual Status update(StageManager* smgr) {
-        string in;
-        getline(cin, in);
-        return GameStage::Status::FINISH;
-    }
-
-    virtual void draw() {
-        cout << "===HIGH SCORE==" << endl;
-        cout << "Congratulations!" << endl;
-        cout << "You have made it to the Zorkish Hall Of Fame" << endl << endl;
-
-        cout << "Adventure: " << GameState::instance().adventure << endl;
-        cout << "Score: " << GameState::instance().score << endl;
-        cout << "Moves: " << GameState::instance().moves << endl << endl;
-
-        cout << "Enter your name: ";
-    }
-
-private:
-    HighScoreStage() = default;
-    HighScoreStage(const HighScoreStage&) = delete;
-    void operator=(const HighScoreStage&) = delete;
-};
-
-#endif /* HIGHSCORESTAGE_H_ */

HighScoreStage.hpp

+/*
+ * HiScoreStage.hpp
+ *
+ *  Created on: 20/08/2012
+ *      Author: rhys
+ */
+
+#ifndef HIGHSCORESTAGE_HPP_
+#define HIGHSCORESTAGE_HPP_
+
+#include <iostream>
+#include "ZorkishGame.hpp"
+
+class HighScoreStage : public ZorkishStage {
+private:
+    int score;
+    int moves;
+    std::string adventure_name;
+
+public:
+    HighScoreStage(ZorkishGame& game) : ZorkishStage(game) {};
+
+    void set_score(int score, int moves, std::string adventure_name) {
+        this->score = score;
+        this->moves = moves;
+        this->adventure_name = adventure_name;
+    }
+
+    virtual Status update(ActiveStageManager*) {
+        std::string in;
+        getline(std::cin, in);
+        return GameStage::Status::FINISH;
+    }
+
+    virtual void draw() {
+        using std::cout;
+        cout << "===HIGH SCORE==\n";
+        cout << "Congratulations!\n";
+        cout << "You have made it to the Zorkish Hall Of Fame\n\n";
+
+        cout << "Adventure: " << this->adventure_name << '\n';
+        cout << "Score: " << this->score << '\n';
+        cout << "Moves: " << this->moves << "\n\n";
+
+        cout << "Enter your name: ";
+    }
+};
+
+#endif /* HIGHSCORESTAGE_HPP_ */

MainMenuStage.h

-/*
- * MainMenuStage.h
- *
- *  Created on: 19/08/2012
- *      Author: rhys
- */
-
-#ifndef MAINMENUSTAGE_H_
-#define MAINMENUSTAGE_H_
-
-#include "StageManager.h"
-#include "AboutStage.h"
-#include "HallOfFameStage.h"
-#include "HelpStage.h"
-#include "SelectAdventureStage.h"
-
-class MainMenuStage : public ConsoleStage {
-private:
-    string message;
-
-public:
-    static MainMenuStage& instance() {
-        static MainMenuStage ins;
-        return ins;
-    }
-
-    virtual Status update(StageManager* smgr) {
-        switch (this->input_int()) {
-        case 1:
-            smgr->set_next_stage(&SelectAdventureStage::instance());
-            break;
-        case 2:
-            smgr->set_next_stage(&HallOfFameStage::instance());
-            break;
-        case 3:
-            smgr->set_next_stage(&HelpStage::instance());
-            break;
-        case 4:
-            smgr->set_next_stage(&AboutStage::instance());
-            break;
-        case 5:
-            return GameStage::Status::FINISH;
-            break;
-        default:
-            this->message = "Please select a number listed above.";
-            break;
-        }
-
-        return GameStage::Status::CONTINUE;
-    }
-
-    virtual void draw() {
-        cout << "===ZORKISH===" << endl;
-        cout << "Main Menu:" << endl;
-        cout << "1. Select adventure and play" << endl;
-        cout << "2. Hall of Fame" << endl;
-        cout << "3. Help" << endl;
-        cout << "4. About" << endl;
-        cout << "5. Quit\n" << endl;
-        if (!this->message.empty()) {
-            cout << this->message << endl;
-            this->message.clear();
-        }
-        cout << "Select 1-5: ";
-    };
-
-private:
-    MainMenuStage() = default;
-    MainMenuStage(const MainMenuStage&) = delete;
-    void operator=(const MainMenuStage&) = delete;
-};
-
-#endif /* MAINMENUSTAGE_H_ */

MainMenuStage.hpp

+/*
+ * MainMenuStage.hpp
+ *
+ *  Created on: 19/08/2012
+ *      Author: rhys
+ */
+
+#ifndef MAINMENUSTAGE_HPP_
+#define MAINMENUSTAGE_HPP_
+
+#include "ActiveStageManager.hpp"
+#include "ZorkishStage.hpp"
+#include "AboutStage.hpp"
+#include "HallOfFameStage.hpp"
+#include "HelpStage.hpp"
+#include "SelectAdventureStage.hpp"
+
+class MainMenuStage : public ZorkishStage {
+private:
+    std::string message;
+
+public:
+    MainMenuStage(ZorkishGame& game) : ZorkishStage(game) {};
+
+    virtual Status update(ActiveStageManager* smgr) {
+        switch (this->input_int()) {
+        case 1:
+            smgr->set_next_stage(&this->game.select_adventure());
+            break;
+        case 2:
+            smgr->set_next_stage(&this->game.hall_of_fame());
+            break;
+        case 3:
+            smgr->set_next_stage(&this->game.help());
+            break;
+        case 4:
+            smgr->set_next_stage(&this->game.about());
+            break;
+        case 5:
+            return GameStage::Status::FINISH;
+        default:
+            this->message = "Please select a number listed above.";
+            break;
+        }
+
+        return GameStage::Status::CONTINUE;
+    }
+
+    virtual void draw() {
+        using std::cout;
+        cout << "===ZORKISH===\n";
+        cout << "Main Menu:\n";
+        cout << "1. Select adventure and play\n";
+        cout << "2. Hall of Fame\n";
+        cout << "3. Help\n";
+        cout << "4. About\n";
+        cout << "5. Quit\n\n";
+        if (!this->message.empty()) {
+            cout << this->message << '\n';
+            this->message.clear();
+        }
+        cout << "Select 1-5: ";
+    };
+};
+
+#endif /* MAINMENUSTAGE_HPP_ */

SelectAdventureStage.h

-/*
- * SelectAdventureStage.h
- *
- *  Created on: 20/08/2012
- *      Author: rhys
- */
-
-#ifndef SELECTADVENTURESTAGE_H_
-#define SELECTADVENTURESTAGE_H_
-
-#include "TestAdventure.h"
-
-class SelectAdventureStage : public ConsoleStage {
-private:
-    string message;
-
-public:
-    static SelectAdventureStage& instance() {
-        static SelectAdventureStage ins;
-        return ins;
-    }
-
-    virtual Status update(StageManager* smgr) {
-        switch (this->input_int()) {
-        case 1:
-            smgr->set_next_stage(&TestAdventure::instance());
-            return GameStage::Status::FINISH;
-            break;
-        default:
-            this->message = "Please select a number listed above.";
-            break;
-        }
-
-        return GameStage::Status::CONTINUE;
-    }
-
-    virtual void draw() {
-        cout << "===Select Adventure===" << endl;
-        cout << "Choose your adventure:" << endl;
-        cout << "1. Test world" << endl;
-        if (!this->message.empty()) {
-            cout << this->message << endl;
-            this->message.clear();
-        }
-        cout << "Select 1-1: ";
-    }
-
-private:
-    SelectAdventureStage() = default;
-    SelectAdventureStage(const SelectAdventureStage&) = delete;
-    void operator=(const SelectAdventureStage&) = delete;
-};
-
-#endif /* SELECTADVENTURESTAGE_H_ */

SelectAdventureStage.hpp

+/*
+ * SelectAdventureStage.hpp
+ *
+ *  Created on: 20/08/2012
+ *      Author: rhys
+ */
+
+#ifndef SELECTADVENTURESTAGE_HPP_
+#define SELECTADVENTURESTAGE_HPP_
+
+#include "TestAdventure.hpp"
+
+class SelectAdventureStage : public ZorkishStage {
+private:
+    std::string message;
+
+public:
+    SelectAdventureStage(ZorkishGame& game) : ZorkishStage(game) {};
+
+    virtual Status update(ActiveStageManager* smgr) {
+        switch (this->input_int()) {
+        case 1:
+            smgr->set_next_stage(&this->game.test_adventure());
+            return GameStage::Status::FINISH;
+        default:
+            this->message = "Please select a number listed above.";
+            break;
+        }
+
+        return GameStage::Status::CONTINUE;
+    }
+
+    virtual void draw() {
+        using std::cout;
+        cout << "===Select Adventure===\n";
+        cout << "Choose your adventure:\n";
+        cout << "1. Test world\n";
+        if (!this->message.empty()) {
+            cout << this->message << '\n';
+            this->message.clear();
+        }
+        cout << "Select 1-1: ";
+    }
+};
+
+#endif /* SELECTADVENTURESTAGE_HPP_ */

SimpleDisplayStage.h

-/*
- * SimpleDisplayStage.h
- *
- *  Created on: 19/08/2012
- *      Author: rhys
- */
-
-#ifndef SIMPLEDISPLAYSTAGE_H_
-#define SIMPLEDISPLAYSTAGE_H_
-
-#include <iostream>
-#include "ConsoleStage.h"
-
-class SimpleDisplayStage : public ConsoleStage {
-public:
-    virtual Status update(StageManager* smgr) {
-        int c;
-        while ((c = cin.get()) != '\n');
-        return GameStage::Status::FINISH;
-    }
-
-    virtual void draw() {
-        this->add_strings();
-        cout << endl << "Press Enter to return to the Main Menu.";
-    }
-
-    virtual void add_strings() = 0;
-};
-
-#endif /* SIMPLEDISPLAYSTAGE_H_ */

SimpleDisplayStage.hpp

+/*
+ * SimpleDisplayStage.hpp
+ *
+ *  Created on: 19/08/2012
+ *      Author: rhys
+ */
+
+#ifndef SIMPLEDISPLAYSTAGE_HPP_
+#define SIMPLEDISPLAYSTAGE_HPP_
+
+#include <iostream>
+#include "ZorkishStage.hpp"
+
+class SimpleDisplayStage : public ZorkishStage {
+public:
+    SimpleDisplayStage(ZorkishGame& game) : ZorkishStage(game) {};
+
+    virtual Status update(ActiveStageManager*) {
+        int c;
+        while ((c = std::cin.get()) != '\n');
+        return GameStage::Status::FINISH;
+    }
+
+    virtual void draw() {
+        this->print_message();
+        std::cout << "\nPress Enter to return to the Main Menu." << std::flush;
+    }
+
+    virtual void print_message() = 0;
+};
+
+#endif /* SIMPLEDISPLAYSTAGE_HPP_ */

StageManager.h

-/*
- * StageManager.h
- *
- *  Created on: 19/08/2012
- *      Author: rhys
- */
-
-#ifndef STAGEMANAGER_H_
-#define STAGEMANAGER_H_
-
-#include <stack>
-#include "GameStage.h"
-using namespace std;
-
-class StageManager {
-private:
-    GameStage* next_stage = nullptr;
-    stack<GameStage*> stage_stack;
-
-public:
-    bool ready() {
-        return !this->stage_stack.empty();
-    }
-
-    void set_next_stage(GameStage* stage) {
-        if (this->stage_stack.empty()) {
-            this->stage_stack.push(stage);
-            stage->activate();
-        } else {
-            this->next_stage = stage;
-        }
-    }
-
-    void update() {
-        GameStage* current_stage = this->stage_stack.top();
-        GameStage::Status css = current_stage->update(this);
-
-        if (this->next_stage != nullptr || css == GameStage::Status::FINISH) {
-            current_stage->deactivate();
-        }
-
-        if (css == GameStage::Status::FINISH) {
-            current_stage->cleanup();
-            this->stage_stack.pop();
-        }
-
-        if (this->next_stage != nullptr) {
-            this->stage_stack.push(next_stage);
-            next_stage->activate();
-            next_stage = nullptr;
-        }
-    }
-
-    void draw() {
-        this->stage_stack.top()->draw();
-    }
-};
-
-#endif /* STAGEMANAGER_H_ */

TestAdventure.h

-/*
- * TestAdventure.h
- *
- *  Created on: 20/08/2012
- *      Author: rhys
- */
-
-#ifndef TESTADVENTURE_H_
-#define TESTADVENTURE_H_
-
-#include <iostream>
-#include <boost/algorithm/string.hpp>
-#include "HighScoreStage.h"
-using namespace std;
-
-class TestAdventure : public GameStage {
-private:
-    string message;
-    bool alive;
-    bool hiscore;
-    int moves;
-
-    TestAdventure() {
-        this->cleanup();
-    }
-
-public:
-    static TestAdventure& instance() {
-        static TestAdventure ins;
-        return ins;
-    }
-
-    virtual Status update(StageManager* smgr) {
-        if (!this->alive) {
-            if (this->hiscore) {
-                GameState::instance().adventure = "Test Adventure";
-                GameState::instance().moves = this->moves;
-                GameState::instance().score = 10;
-                smgr->set_next_stage(&HighScoreStage::instance());
-            }
-
-            return GameStage::Status::FINISH;
-        }
-
-        string in;
-        getline(cin, in);
-        boost::to_upper(in);
-        if (in == "QUIT") {
-            this->message = "Your adventure has ended without fame or fortune.";
-            this->alive = false;
-        } else if (in == "HISCORE") {
-            this->message = "You have entered the magic word and will now see the \"New High Score\" screen.";
-            this->hiscore = true;
-            this->alive = false;
-        } else {
-            this->message = "I don't know how to do that.";
-        }
-
-        this->moves++;
-        return GameStage::Status::CONTINUE;
-    }
-
-    virtual void draw() {
-        if (!this->message.empty()) {
-            cout << this->message << endl;
-            this->message.clear();
-        }
-        if (this->alive) {
-            cout << ":> ";
-        }
-    }
-
-    virtual void cleanup() {
-        this->hiscore = false;
-        this->alive = true;
-        this->moves = 0;
-        this->message = "Welcome to Zorkish: Void World\nThis world is simple and pointless. Used it to test Zorkish phase 1 spec.";
-    }
-
-private:
-    TestAdventure(const TestAdventure&) = delete;
-    void operator=(const TestAdventure&) = delete;
-};
-
-#endif /* TESTADVENTURE_H_ */

TestAdventure.hpp

+/*
+ * TestAdventure.hpp
+ *
+ *  Created on: 20/08/2012
+ *      Author: rhys
+ */
+
+#ifndef TESTADVENTURE_HPP_
+#define TESTADVENTURE_HPP_
+
+#include <iostream>
+#include <boost/algorithm/string.hpp>
+#include "HighScoreStage.hpp"
+
+class TestAdventure : public ZorkishStage {
+private:
+    std::string message;
+    int moves;
+    bool alive;
+    bool hiscore;
+
+public:
+    TestAdventure(ZorkishGame& game) : ZorkishStage(game) {
+        this->cleanup();
+    }
+
+    virtual Status update(ActiveStageManager* smgr) {
+        if (!this->alive) {
+            if (this->hiscore) {
+                this->game.high_score().set_score(10, this->moves, "Test Adventure");
+                smgr->set_next_stage(&this->game.high_score());
+            }
+
+            return GameStage::Status::FINISH;
+        }
+
+        std::string in;
+        getline(std::cin, in);
+        boost::to_upper(in);
+        if (in == "QUIT") {
+            this->message = "Your adventure has ended without fame or fortune.";
+            this->alive = false;
+        } else if (in == "HISCORE") {
+            this->message = "You have entered the magic word and will now see the \"New High Score\" screen.";
+            this->hiscore = true;
+            this->alive = false;
+        } else {
+            this->message = "I don't know how to do that.";
+        }
+
+        this->moves++;
+        return GameStage::Status::CONTINUE;
+    }
+
+    virtual void draw() {
+        using std::cout;
+        if (!this->message.empty()) {
+            cout << this->message << '\n';
+            this->message.clear();
+        }
+        if (this->alive) {
+            cout << ":> ";
+        }
+    }
+
+    virtual void cleanup() {
+        this->message = "Welcome to Zorkish: Void World\nThis world is simple and pointless. Used it to test Zorkish phase 1 spec.";
+        this->moves = 0;
+        this->alive = true;
+        this->hiscore = false;
+    }
+};
+
+#endif /* TESTADVENTURE_HPP_ */
+/*
+ * ZorkishGame.cpp
+ *
+ *  Created on: 24/08/2012
+ *      Author: rhys
+ */
+
+#include "ZorkishGame.hpp"
+#include "MainMenuStage.hpp"
+
+ZorkishGame::ZorkishGame() {
+    this->smgr.set_next_stage(&this->main_menu());
+}
+
+ActiveStageManager& ZorkishGame::stage_manager() {
+    return this->smgr;
+}
+
+// Use of exit-time destructors is intentional
+#pragma clang diagnostic push
+#pragma clang diagnostic ignored "-Wexit-time-destructors"
+
+AboutStage& ZorkishGame::about() {
+    static AboutStage s(*this);
+    return s;
+}
+
+HallOfFameStage& ZorkishGame::hall_of_fame() {
+    static HallOfFameStage s(*this);
+    return s;
+}
+
+HelpStage& ZorkishGame::help() {
+    static HelpStage s(*this);
+    return s;
+}
+
+HighScoreStage& ZorkishGame::high_score() {
+    static HighScoreStage s(*this);
+    return s;
+}
+
+MainMenuStage& ZorkishGame::main_menu() {
+    static MainMenuStage s(*this);
+    return s;
+}
+
+SelectAdventureStage& ZorkishGame::select_adventure() {
+    static SelectAdventureStage s(*this);
+    return s;
+}
+
+TestAdventure& ZorkishGame::test_adventure() {
+    static TestAdventure s(*this);
+    return s;
+}
+
+#pragma clang diagnostic pop
+/*
+ * ZorkishGame.hpp
+ *
+ *  Created on: 24/08/2012
+ *      Author: rhys
+ */
+
+#ifndef ZORKISH_HPP_
+#define ZORKISH_HPP_
+
+#include "ActiveStageManager.hpp"
+
+class AboutStage;
+class HallOfFameStage;
+class HelpStage;
+class HighScoreStage;
+class MainMenuStage;
+class SelectAdventureStage;
+class TestAdventure;
+
+class ZorkishGame {
+private:
+    ActiveStageManager smgr;
+
+public:
+    ZorkishGame();
+
+    ActiveStageManager& stage_manager();
+
+    AboutStage& about();
+    HallOfFameStage& hall_of_fame();
+    HelpStage& help();
+    HighScoreStage& high_score();
+    MainMenuStage& main_menu();
+    SelectAdventureStage& select_adventure();
+    TestAdventure& test_adventure();
+};
+
+#endif /* ZORKISH_HPP_ */
+/*
+ * ZorkishStage.hpp
+ *
+ *  Created on: 20/08/2012
+ *      Author: rhys
+ */
+
+#ifndef ZORKISHSTAGE_HPP_
+#define ZORKISHSTAGE_HPP_
+
+#include <boost/lexical_cast.hpp>
+#include <iostream>
+#include "ZorkishGame.hpp"
+
+class ZorkishStage : public GameStage {
+public:
+    ZorkishStage(ZorkishGame& game) : game(game) {}
+
+protected:
+    ZorkishGame& game;
+
+    static int input_int() {
+        std::string in;
+        getline(std::cin, in);
+        try {
+            return boost::lexical_cast<int>(in);
+        } catch (boost::bad_lexical_cast&) {
+            return -1;
+        }
+    }
+
+private:
+    ZorkishStage(const ZorkishStage&) = delete;
+    void operator=(const ZorkishStage&) = delete;
+};
+
+
+#endif /* ZORKISHSTAGE_HPP_ */
  *  Created on: 19/08/2012
  *      Author: rhys
  */
-#include <iostream>
-#include "MainMenuStage.h"
-using namespace std;
+
+#include "ZorkishGame.hpp"
 
 int main() {
-    StageManager st;
-    st.set_next_stage(&MainMenuStage::instance());
+    ZorkishGame game;
+    ActiveStageManager& smgr = game.stage_manager();
 
-    while (st.ready()) {
-        st.draw();
-        st.update();
+    while (smgr.ready()) {
+        smgr.draw();
+        smgr.update();
     }
 
     return 0;