コード例 #1
0
ファイル: GameOutput.cpp プロジェクト: celloist/Rogue
void GameOutput::displayShortestPathToExit (map<Room *, pair<int, Room *>> backTrack, Room* start, Room* exit) {
    Room* lastRoom = exit;
    string path;
    int size = backTrack.size();
    int i =0;
    int numOfEnemies = 0;
    string hp;
    int numOfTraps = 0;

    while (lastRoom != start && i < size) {
        auto room = backTrack[lastRoom];
        Room* from = room.second;

        string direction;
        /*
         * guage direction
         */
        if (lastRoom->getByEdgeName("north") == from) {
            direction = "zuid";
        } else if (lastRoom->getByEdgeName("south") == from) {
            direction = "noord";
        }else if (lastRoom->getByEdgeName("west") == from) {
            direction = "oost";
        }else if (lastRoom->getByEdgeName("east") == from) {
            direction = "west";
        }

        if (path.empty()){
            path = direction;
        } else {
            path= direction + " - " + path;
        }

        /*
         * Add enemies
         */

        if (from->getEnemies()) {
            vector<Enemy*>* enemies = from->getEnemies();
            for (auto it = enemies->begin(); it != enemies->end(); it++) {
                numOfEnemies++;

                if (hp.length() > 1) {
                    hp += ", " + to_string(it.operator*()->health);
                } else {
                    hp += to_string(it.operator*()->health);
                }

                hp+= " hp";
            }
        }

        if (from->hasTrap()) {
            numOfTraps++;
        }

        backTrack.erase(lastRoom);

        lastRoom = from;
        i++;
    }

    string output = "Het kortste pad naar de uitgang is: " + (path.size() > 0 ? path : "hier blijven")  + ".\n";

    if (numOfEnemies > 0) {
        output+= "Aantal vijanden: "+ to_string(numOfEnemies) + " (" + hp + ").";
    } else {
        output+= "Geen vijanden.";
    }

    output+= "\n";

    if (numOfTraps > 0) {
        output+= "Aantal vallen: "+ to_string(numOfTraps);
    } else {
        output+= "Geen vallen.";
    }

    cout << output + "\n";
}
コード例 #2
0
ファイル: CheatLevelOutput.cpp プロジェクト: celloist/Rogue
void CheatLevelOutput::displayLevel(Level *currentLevel) {
    Room* current = currentLevel->getNorthEastRoom();
    Room* firstOfTop = current;

    bool hasNextRow = currentLevel->getNorthEastRoom() != nullptr;
    bool hasNextCol = hasNextRow;

    string bottom;
    string trapsAndEnemies= "";
    int index = 1;
    while (firstOfTop != nullptr) {
        char letter = 'A';
        while(current != nullptr){

            current->accept(this);
            //output = output + " ";

            string num;

            if (current->getByEdgeName("east") != nullptr) {
                if (current->isConnectedTo(current->getByEdgeName("east"))) {
                    num = to_string(current->getDistanceTo(current->getByEdgeName("east")));
                    output+= " <"+ ((num.length() <= 1) ? " " + num : num ) +">";
                } else {
                    output += " < ~>";
                }

                output+= " ";
            }

            if (current->getByEdgeName("south") != nullptr) {
                if (current->isConnectedTo(current->getByEdgeName("south"))) {
                    num = to_string(current->getDistanceTo(current->getByEdgeName("south")));
                    bottom += "<" + ((num.length() <= 1) ? " " + num : num) + "> ";
                } else {
                    bottom += "< ~> ";
                }


                while (bottom.length() < output.length() -1) {
                    bottom+=" ";
                }
            }

            if (current->getEnemies() && current->getEnemies()->size() > 0 || current->hasTrap()) {
                trapsAndEnemies+=  letter + to_string(index) + ": \n";
                if (current->hasTrap()) {
                    trapsAndEnemies+= "- Heeft een val!\n";
                }

                if (current->getEnemies() && current->getEnemies()->size() > 0) {
                    vector<Enemy*>* enemies = current->getEnemies();

                    string hp = "";
                    for (auto it = enemies->begin(); it != enemies->end(); it++) {
                        if (hp.length() == 0) {
                            hp+= to_string(it.operator*()->health);
                        } else {
                            hp+= ", "+ to_string(it.operator*()->health);
                        }
                    }

                    trapsAndEnemies+= "Heeft "+ to_string(enemies->size()) + " vijand(en) met ("+ hp + ")\n";
                }

                trapsAndEnemies+= "\n";
            }

            current = current->getByEdgeName("east");
            letter++;
        }

        cout << output + "\n\n" + bottom + "\n\n";
        output = "";
        bottom = "";

        firstOfTop = firstOfTop->getByEdgeName("south");
        current = firstOfTop;
        index++;
    }

    cout << trapsAndEnemies;
    cout << "\n";
}