Wip: Working on Room Movement
This commit is contained in:
@@ -44,19 +44,21 @@ std::vector<std::string> CommandParser::Noun(std::stringstream &sentences) {
|
||||
return nouns;
|
||||
}
|
||||
|
||||
|
||||
int CommandParser::Parse() {
|
||||
std::string cmd;
|
||||
std::string word;
|
||||
|
||||
std::string noun;
|
||||
std::string noun = "";
|
||||
|
||||
std::vector<std::string> verbs;
|
||||
std::vector<std::string> nouns;
|
||||
FUNCTION toRun;
|
||||
|
||||
|
||||
printf("Please Enter a command \n");
|
||||
printf("> ");
|
||||
getline(std::cin, cmd);
|
||||
std::cin.clear();
|
||||
cmd[0] = toupper(cmd[0]);
|
||||
std::stringstream c(cmd);
|
||||
|
||||
@@ -69,8 +71,19 @@ int CommandParser::Parse() {
|
||||
printf("Sorry kid, can't understand ya! \n");
|
||||
break;
|
||||
}
|
||||
|
||||
commands[verb]("");
|
||||
toRun = commands[verb];
|
||||
}
|
||||
|
||||
if (toRun) {
|
||||
toRun(noun);
|
||||
}
|
||||
cmd.clear();
|
||||
word.clear();
|
||||
verbs.clear();
|
||||
nouns.clear();
|
||||
c.clear();
|
||||
|
||||
toRun = nullptr;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+44
-14
@@ -3,6 +3,8 @@
|
||||
|
||||
bool isActive;
|
||||
|
||||
std::vector<std::vector<Room>> rooms;
|
||||
|
||||
Game::Game() {
|
||||
curX = 0;
|
||||
curY = 0;
|
||||
@@ -46,20 +48,33 @@ void Game::Run() {
|
||||
|
||||
bool Game::Save() { return false; }
|
||||
|
||||
int Quit(std::string n) {
|
||||
void Game::ChangeRoom(Room r) {
|
||||
if (currentRoom != r) {
|
||||
currentRoom = r;
|
||||
|
||||
currentRoom.Print();
|
||||
printf("\n");
|
||||
currentRoom.PrintAvalibleExits();
|
||||
}
|
||||
}
|
||||
|
||||
int Quit(const std::string &n) {
|
||||
isActive = false;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Move(const std::string &c) {
|
||||
|
||||
int Move(std::string c) {
|
||||
std::string dirInput = c;
|
||||
|
||||
std::string dirInput;
|
||||
printf("What Direction: ");
|
||||
std::cin >> dirInput;
|
||||
dirInput[0] = toupper(dirInput[0]);
|
||||
int tmpX = 0, tmpY = 0;
|
||||
|
||||
Direction dir = directions[dirInput.data()];
|
||||
if (dirInput.empty()) {
|
||||
printf("What Direction: ");
|
||||
std::cin >> dirInput;
|
||||
dirInput[0] = toupper(dirInput[0]);
|
||||
}
|
||||
const Direction dir = directions[dirInput.data()];
|
||||
|
||||
if (!Game::instance().GetCurrentRoom().ValidDirection(dir)) {
|
||||
printf("Sorry, can't move that direction kiddo \n");
|
||||
@@ -68,33 +83,48 @@ int Move(std::string c) {
|
||||
|
||||
switch (dir) {
|
||||
case N:
|
||||
curY += 1;
|
||||
tmpY -= 1;
|
||||
break;
|
||||
|
||||
case S:
|
||||
curY -= 1;
|
||||
tmpY += 1;
|
||||
break;
|
||||
|
||||
case E:
|
||||
curX += 1;
|
||||
tmpX += 1;
|
||||
break;
|
||||
|
||||
case W:
|
||||
curX -= 1;
|
||||
tmpX -= 1;
|
||||
break;
|
||||
default:
|
||||
printf("Incorrect direction \n");
|
||||
return 0;
|
||||
break;
|
||||
};
|
||||
|
||||
if (tmpX > 0 && tmpX < MAP_WIDTH) {
|
||||
curX = tmpX;
|
||||
} else {
|
||||
printf("Ye hit a wall of some kind! \n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (tmpY > 0 && tmpY < MAP_HEIGHT) {
|
||||
curY = tmpY;
|
||||
} else {
|
||||
printf("Ye hit a wall of some kind! \n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
Game::instance().ChangeRoom(rooms[curY][curX]);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int Look(std::string c) {
|
||||
int Look(const std::string &c) {
|
||||
Room cur = Game::instance().GetCurrentRoom();
|
||||
cur.Print();
|
||||
printf("\n");
|
||||
cur.PrintAvalibleExits();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ void Room::Print() const {
|
||||
void Room::PrintAvalibleExits() {
|
||||
printf("Available exits are: \n");
|
||||
for (const auto &exit: exits) {
|
||||
printf(directionChar[exit.dir] + '\n');
|
||||
printf(directionChar[exit.dir].data(), "\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user