Wip: Working on room movements, player location in room, and data storage
This commit is contained in:
@@ -61,11 +61,15 @@ int CommandParser::Parse() {
|
||||
nouns = Noun(c);
|
||||
|
||||
for (const auto &verb: verbs) {
|
||||
|
||||
if (!commands[verb]) {
|
||||
CommandUnrecognized();
|
||||
break;
|
||||
}
|
||||
|
||||
for (const auto &n: nouns) {
|
||||
noun = n;
|
||||
}
|
||||
|
||||
toRun = commands[verb];
|
||||
}
|
||||
|
||||
|
||||
+13
-10
@@ -59,15 +59,11 @@ void Game::Run() {
|
||||
|
||||
bool Game::Save() { return false; }
|
||||
|
||||
void Game::ChangeRoom(Room r) {
|
||||
void Game::ChangeRoom(const Room &r) {
|
||||
if (currentRoom != r) {
|
||||
currentRoom = r;
|
||||
|
||||
player.ChangeRoom(currentRoom.GetID());
|
||||
|
||||
currentRoom.Print();
|
||||
printf("\n");
|
||||
currentRoom.PrintAvalibleExits();
|
||||
currentRoom.Enter(player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,7 +137,15 @@ int Move(const std::string &c) {
|
||||
break;
|
||||
};
|
||||
|
||||
Game::Instance().ChangeRoom(rooms[curY][curX]);
|
||||
Room temp;
|
||||
try {
|
||||
temp = rooms.at(curY).at(curX);
|
||||
} catch (std::out_of_range) {
|
||||
printf("Error, Room Data non existent \n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
Game::Instance().ChangeRoom(temp);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -153,8 +157,7 @@ int Look(const std::string &c) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
Game::~Game()
|
||||
{
|
||||
Game::~Game() {
|
||||
isActive = false;
|
||||
progress = 0;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-25
@@ -2,24 +2,17 @@
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
|
||||
Player::Player()
|
||||
{
|
||||
Init();
|
||||
}
|
||||
Player::Player() { Init(); }
|
||||
|
||||
Player::Player(Player &rhs)
|
||||
{
|
||||
Player::Player(Player &rhs) {
|
||||
id = rhs.id;
|
||||
level = rhs.level;
|
||||
stats = rhs.stats;
|
||||
name = rhs.name;
|
||||
description = rhs.description;
|
||||
curRoomID = rhs.curRoomID;
|
||||
prevRoomID = rhs.prevRoomID;
|
||||
}
|
||||
|
||||
Player& Player::operator=(Player& rhs)
|
||||
{
|
||||
Player &Player::operator=(Player &rhs) {
|
||||
swap(*this, rhs);
|
||||
return *this;
|
||||
}
|
||||
@@ -42,24 +35,10 @@ void Player::TakeDamage(int damageType, float damage) {
|
||||
|
||||
float Player::GetHealth() { return 0.0f; }
|
||||
|
||||
void Player::ChangeRoom(int roomID) {
|
||||
if (prevRoomID == roomID) {
|
||||
curRoomID = prevRoomID;
|
||||
}
|
||||
|
||||
else if (curRoomID != roomID) {
|
||||
prevRoomID = curRoomID;
|
||||
curRoomID = roomID;
|
||||
}
|
||||
}
|
||||
|
||||
Player::~Player()
|
||||
{
|
||||
Player::~Player() {
|
||||
id = -1;
|
||||
level = -1;
|
||||
stats = {};
|
||||
name.erase();
|
||||
description.erase();
|
||||
curRoomID = -1;
|
||||
prevRoomID = -1;
|
||||
}
|
||||
|
||||
@@ -33,6 +33,16 @@ Room::~Room() {
|
||||
exits.clear();
|
||||
}
|
||||
|
||||
void Room::Enter(Player &p) {
|
||||
player = p;
|
||||
Print();
|
||||
}
|
||||
|
||||
Room &Room::operator=(Room rhs) {
|
||||
swap(*this, rhs);
|
||||
return *this;
|
||||
}
|
||||
|
||||
void Room::Print() const {
|
||||
printf("%s\n", name.c_str());
|
||||
printf("%s\n", description.c_str());
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
#include "world.h"
|
||||
|
||||
void World::Init() { return; }
|
||||
Reference in New Issue
Block a user