Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
1 changed file
with
112 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
//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 |