Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
text-adventure/Room.h
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
112 lines (75 sloc)
2.12 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//code adapted from: https://www.youtube.com/watch?v=ajL1KjTch2A&t=7s and https://www.youtube.com/watch?v=ikA4yiurkug | |
#ifndef ROOM_H | |
#define ROOM_H | |
#include<iostream> | |
#include<string> | |
using namespace std; | |
enum Direction { NORTH = 0, SOUTH = 1, EAST = 2, WEST = 3}; | |
string GetPositionString(Direction direction) { | |
if (direction == NORTH) { return "NORTH"; } | |
else if (direction == SOUTH) { return "SOUTH"; } | |
else if (direction == EAST) { return "EAST"; } | |
else if (direction == WEST) { return "WEST"; } | |
else { return "UNKNOWN"; } | |
} | |
struct Room { | |
Room(); | |
Room(string r_name, string r_description); | |
void CloseRooms(string toNorthRoom, string toEastRoom, string toSouthRoom, string toWestRoom); | |
void Begin(string id = "", string name = "", string description = ""); | |
void OutputRinfo(); | |
void OutputCloseRooms(); | |
bool CanMoveto(Direction direction); | |
string GetCloseRoomId(Direction direction); | |
string GetID(); | |
string id; | |
string name; | |
string description; | |
string closeroomIds[4]; | |
}; | |
Room::Room() { | |
Begin(); | |
}; | |
Room::Room(string id, string name, string description) { | |
Begin(id, name, description); | |
}; | |
void Room::Begin(string id /*= ""*/, string name/*= ""*/, string description/*= ""*/) { | |
this->id = id; | |
this->name = name; | |
this->description = description; | |
for (int i = 0; i < 4; i++) | |
{ | |
closeroomIds[i] = "NULL"; | |
} | |
}; | |
void Room::CloseRooms(string toNorthRoom, string toEastRoom, string toSouthRoom, string toWestRoom) { | |
closeroomIds[NORTH] = toNorthRoom; | |
closeroomIds[SOUTH] = toSouthRoom; | |
closeroomIds[EAST] = toEastRoom; | |
closeroomIds[WEST] = toWestRoom; | |
}; | |
void Room::OutputRinfo() { | |
string userInput; | |
cout<< "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl | |
<< name << endl | |
<< description << endl | |
<<"~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" | |
<< endl; | |
OutputCloseRooms(); | |
cout << "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~" << endl; | |
cout << "What will you do?" << endl; | |
cout << "=>"; | |
getline(cin, userInput); | |
} | |
void Room::OutputCloseRooms() { | |
cout << "\t You can go: "; | |
for (int i = 0; i < 4; i++) | |
{ | |
if (closeroomIds[i] != "NULL") | |
{ | |
cout << GetPositionString(Direction(i)) << " "; | |
} | |
} | |
cout << endl; | |
} | |
#endif |