mercredi 28 décembre 2022

C++ Text Adventure, Trying to use vector as validation to create individualized story for that path and arrays if path is choosen

Im looking to take my vector and depending on the p_room[] choosen give a special dialog and crerate a array for that specific vector. for example if the user goes from startingRoom to startingEast then to eastlvl1 i want a special dialog for the eastlvl1 i tried if statments but they appear when the app is first ran. i want a way to create path specific dialog along with creating arrays along that path so if they reach a certain point and find an object i can create an array and store the object. but i dont want the user to always have an inventory i only want it to exist once they find an object if they find

#include <iostream>
#include <vector>
#include <string>
#include "Room.h"

using namespace std;

class Program{
    
    public:
    Program();
    ~Program();
    void setUpRooms();

    void Run();
    
    private:

    int createRoom(string name, string description);

    void handleUserInput();
    Room* p_ptrCurrentRooms;
    vector<Room*> p_rooms;
    bool p_done;

    Room customRoom();
};

Program::Program(){

    p_ptrCurrentRooms = nullptr;
    setUpRooms();
    p_done = false;

}

void Program::Run() {


    string status = "";

    while (!p_done){

        p_ptrCurrentRooms->outputRoomInfo();


        handleUserInput() ;

         Menu::Pause();




    }

}
void Program::setUpRooms() {

    int spawn = createRoom("your house","theres a flash of light");

    int startingRoom = createRoom("Town Center","You appear in a mysteries town");
    int startingNorth = createRoom("Capital","You enter the capital");
    int startingSouth = createRoom("Dense Forest","You enter a forest where light can barely reach the ground");
    int startingEast = createRoom("Ocean","You have reached an ocean");
    int startingWest = createRoom("Town","you have traveled deeper into town");

    int northLevel1 = createRoom("Castle","you find a massive castle");
    int northSthLevel1 = createRoom("Town center","Back at the town center but it looks different from before, yet you are unsure how");
    int northEstLevel1 = createRoom("Ocean","You have reached a port");
    int northWstLevel1 = createRoom("Slums","A dirtier and much more unpleasant place compared to previous surroundings ");

    int northLvl2 = createRoom("Castle","you reach the castle gate and are stopped by guards, you explain your situation. They look you over and can clearly tell you arent"
                                        " from there at least and allow you to pass with an escort. continue north to proceed with your escort.  ");
    //northSthLevel1
    int northEstLvl2 = createRoom("Castle","You walk the castle wall, it is miles long and even taller. made from a hard stone you've never seen before");
    int northWstLvl2 = createRoom("Castle","You walk the castle wall, it is miles long and even taller. made from a hard stone you've never seen before");

    int southLevel1 = createRoom("Dense Forest","You travel deeper into the the dense forest, nothing interesting found");
    int southNorthLevel1 = createRoom("Dense forest","The forest was so dark and dense when you entered... are you lost?");
    int southEstLevel1 = createRoom("Dense Forest","just more forest nothing interesting.");
    int southWstLevel1 = createRoom("Dense Forest","just more forest nothing interesting.");
    int southLevel2 = createRoom("Dense Forest","You travel deeper into the the dense forest, nothing interesting found");
    int southNrthLvl2 = createRoom("Dense Forest","You reach the edge of the forest, you've made it out.");
    int southEstLvl2 = createRoom("Dense Forest","just more forest nothing interesting. its starting to get dark");
    int southWstLvl2 = createRoom("Dense Forest","just more forest nothing interesting. its starting to get dark");


    int eastLvl1 = createRoom("Ocean","You have entered the ocean continue east to swim further into ocean");
    int eastNrthLvl1 = createRoom("Port","you found a port, continue east from here to board a ship");
    int eastSthlvl1 = createRoom("Market","you find a market that sells a variety of the days catches");
    //use northsthlvl1
    int eastlvl2 = createRoom("Ocean","you have started your swim into the ocean");
    int eastNrthLvl2 = createRoom("Port","you continue along the port, continue east from here to board a ship");
    int eastSthlvl2 = createRoom("Market","you continue along the market that sells a variety of the days catches");
    //use northSouthLevel1

    int westLvl1 = createRoom("Town","The path you where walking opens into a large square with shops spread throughout the square");
    int westNrthLvl1 = createRoom("Town","You come across a building marked Guild. by its stature maybe it has some importance or information. continue North to enter");
    int westSthLvl1 = createRoom("Town","Hunters Lodge... wonder what information they may carry");
    // use northSthLevel1

    int westLvl2 = createRoom("Town square","You've entered teh center of the town square you are surrounded by shops. continue North, South, West to enter a shop and east to back up");
    int westNrthLvl2 = createRoom("Guild","you've entered the guild the building seems bigger on the inside, it seems over whelming. - Continue North, West, or East to venture through guild and south to exit");
    int westSthLvl2 = createRoom("Hunters Lodge","you have entered the lodge there are mounts of unknown animals on the wall. - Continue South, West, East to explore lodge and North to exit");
    //use northSthLevel1

    // NORTH, SOUTH, EAST, WEST
    p_rooms[spawn]->setNeighbors( p_rooms[startingRoom],p_rooms[startingRoom], p_rooms[startingRoom], p_rooms[startingRoom]);
    p_rooms[startingRoom]->setNeighbors(p_rooms[startingNorth],p_rooms[startingSouth],p_rooms[startingEast], p_rooms[startingWest]);
    p_rooms[startingNorth]->setNeighbors(p_rooms[northLevel1], p_rooms[northSthLevel1], p_rooms[northEstLevel1], p_rooms[northWstLevel1]);
    p_rooms[startingSouth]->setNeighbors(p_rooms[southNorthLevel1],p_rooms[southLevel1],p_rooms[southEstLevel1],p_rooms[southWstLevel1]);
    p_rooms[startingEast]->setNeighbors(p_rooms[eastNrthLvl1],p_rooms[eastSthlvl1],p_rooms[eastLvl1],p_rooms[northSthLevel1]);
    p_rooms[startingWest]->setNeighbors(p_rooms[westNrthLvl1], p_rooms[westSthLvl1], p_rooms[northSthLevel1], p_rooms[westLvl1]);
    p_rooms[northLevel1]->setNeighbors(p_rooms[northLvl2],p_rooms[northSthLevel1], p_rooms[northEstLvl2], p_rooms[northWstLvl2]);
    p_rooms[southLevel1]->setNeighbors(p_rooms[southNrthLvl2], p_rooms[southLevel2], p_rooms[southEstLvl2], p_rooms[southWstLvl2]);
    p_rooms[eastLvl1]->setNeighbors(p_rooms[eastNrthLvl2], p_rooms[eastSthlvl2], p_rooms[eastlvl2], p_rooms[northSthLevel1]);
    p_rooms[westLvl1]->setNeighbors(p_rooms[westNrthLvl2], p_rooms[westSthLvl2], p_rooms[northSthLevel1], p_rooms[westLvl2]);


p_ptrCurrentRooms = p_rooms[spawn];






}
int Program::createRoom(string name, string description){

    int index = p_rooms.size();

    Room* room = new Room;

    room->setUp(name, description);
    p_rooms.push_back(room);
    
    return index;
}



void Program::handleUserInput(){


    string userIn;
    userIn = Menu::GetStringLine("What would you like to do next");
    if(StringUtil::ToLower(userIn) == "north" || StringUtil::ToLower(userIn) == "n"){


        if(p_ptrCurrentRooms->canGo(NORTH)){


           cout << "you went North";
            p_ptrCurrentRooms = p_ptrCurrentRooms->ptrNeighborNorth;

        }else{
            cout << "you cant go north";
        }
    }
    else if(StringUtil::ToLower(userIn) == "south" || StringUtil::ToLower(userIn) == "s"){

        if(p_ptrCurrentRooms->canGo(SOUTH)){

            cout << "you went South";
            p_ptrCurrentRooms = p_ptrCurrentRooms->ptrNeighborSouth;

        }else{
            cout << "you cant go South";
        }
    }
    else if(StringUtil::ToLower(userIn) == "east" || StringUtil::ToLower(userIn) == "e"){

        if(p_ptrCurrentRooms->canGo(EAST)){

            cout << "you went East";
            p_ptrCurrentRooms = p_ptrCurrentRooms->ptrNeighborEast;

        }else{
            cout << "you cant go East";
        }
    }
   else if(StringUtil::ToLower(userIn) == "west" ||StringUtil::ToLower(userIn) == "w" ){

        if(p_ptrCurrentRooms->canGo(WEST)){

            cout<< "you went west";
            p_ptrCurrentRooms = p_ptrCurrentRooms->ptrNeighborWest;

        }else{
            cout<< "you cant go west";
        }
    } else{
       cout<< "Unknown command";
   }




}
Program::~Program(){

    for(auto ptrRoom : p_rooms){
        if(ptrRoom!= nullptr){
            delete ptrRoom;
        }
    }

}











ive tried p_room.at() or declaring the specific room in if staments but all that does is print the message first in the console

Aucun commentaire:

Enregistrer un commentaire