Source

zorkish / 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_ */