void DungeonQuest::processInput(std::string& input) {
    std::string cmd;
    std::string arg;
    splitInput(input, cmd, arg);

    if(cmd == "quit") {
        stop();
        return;
    }

    if(cmd == "walk") {
        m_player->walk(arg);
        displayLocation();
    }

    if(cmd == "loot") {
        m_player->loot();
    }

    if(cmd == "inventory") {
        m_player->displayInventory();
    }

    if(cmd == "attack") {
        m_player->attack();
    }
}
Exemple #2
0
void displayError(const string &msg, const string &kind) {
    LocationPtr location = topLocation();
    if (location.ptr()) {
        int line, column;
        displayLocation(location, line, column);
        fprintf(stderr, "%s(%d,%d): %s: %s\n",
                location->source->fileName.c_str(),
                line+1, column, kind.c_str(), msg.c_str());
        displayCompileContext();
        displayDebugStack();
    }
    else {
        fprintf(stderr, "error: %s\n", msg.c_str());
    }
}
void DungeonQuest::run() {
    // SET UP
    Room* roomEntrance = new Room("The Entrance Hall");
    Room* roomPrison = new Room("The Prison");
    Room* roomArmory = new Room("The Armory");
    Room* roomTortureChamber = new Room("The Torture Chamber");
    Room* roomCatacombs = new Room("The Catacombs");

    Item* itemShortSword = new Item("Short Sword", Item::WEAPON, 2);
    Item* itemShield = new Item("Shield", Item::ARMOR, 1);
    Item* itemHelmet = new Item("Helmet", Item::ARMOR, 2);

    Monster* monsterZombie = new Monster("Zombie", 5, 1);
    Monster* monsterGhost = new Monster("Ghost", 10, 2);

    roomEntrance->link(roomArmory, NULL, NULL, NULL);
    roomArmory->link(NULL, roomEntrance, roomPrison, roomTortureChamber);
    roomPrison->link(NULL, NULL, NULL, roomArmory);
    roomTortureChamber->link(roomCatacombs, NULL, roomArmory, NULL);
    roomCatacombs->link(NULL, roomTortureChamber, NULL, NULL);

    roomArmory->setItem(itemShortSword);
    roomPrison->setItem(itemShield);
    roomTortureChamber->setItem(itemHelmet);

    roomArmory->setMonster(monsterZombie);
    roomCatacombs->setMonster(monsterGhost);

    m_rooms.push_back(roomEntrance);
    m_rooms.push_back(roomPrison);
    m_rooms.push_back(roomArmory);
    m_rooms.push_back(roomTortureChamber);
    m_rooms.push_back(roomCatacombs);

    m_player = new Player(roomEntrance);

    // START GAME
    std::cout << "***************************" << std::endl;
    std::cout << "Welcome to Dungeon Quest!" << std::endl;
    displayLocation();

    // GAME LOOP
    std::string input;

    while(m_isRunning) {
        if(getInput(input)) {
            processInput(input);
        } else {
            std::cerr << "*** BAD INPUT ***" << std::endl;
            break;
        }
    }

    // CLEAN UP

    // Player
    delete m_player;

    // Rooms
    delete roomEntrance;
    delete roomPrison;
    delete roomArmory;
    delete roomTortureChamber;
    delete roomCatacombs;

    // Items
    delete itemShortSword;
    delete itemShield;
    delete itemHelmet;

    // Monsters
    delete monsterZombie;
    delete monsterGhost;
}