Wip: Working on room movements, player location in room, and data storage

This commit is contained in:
Timothy O'Barr
2026-09-11 16:07:17 -05:00
parent 0e7406db96
commit b9104dad64
13 changed files with 79 additions and 62 deletions
+2 -2
View File
@@ -6,8 +6,8 @@
typedef int (*FUNCTION)(const std::string &s);
static std::vector<std::string> Verbs{"Quit", "Exit", "Go", "Move", "Look"};
static std::vector<std::string> Nouns{"Object", "Door", "North", "South", "East",
"West", "Up", "Down", "Left", "right"};
static std::vector<std::string> Nouns{"Object", "Door", "North", "South", "East", "West",
"Up", "Down", "Left", "Right", "To", "At"};
class CommandParser {
private:
+2 -6
View File
@@ -28,10 +28,8 @@ private:
std::ifstream stream;
bool isActive;
inline static Game *game_;
// Likely need to make sure Player is ADDED to room
// We want player and objects to exist IN room
Room currentRoom;
@@ -44,7 +42,7 @@ public:
void Run();
bool Save();
void ChangeRoom(Room r);
void ChangeRoom(const Room &r);
Room GetCurrentRoom() { return currentRoom; }
inline bool operator!() const {
@@ -64,9 +62,7 @@ public:
return *game_;
}
static void SetGameInstance(Game * g) {
game_ = g;
}
static void SetGameInstance(Game *g) { game_ = g; }
~Game();
};
+3 -12
View File
@@ -7,36 +7,27 @@
class Player : Creature {
private:
private:
// Inventory inventory;
// Lets keep the room a loose reference to avoid to many hardcoded details and other info
int curRoomID = -1;
int prevRoomID = -1;
public:
Player();
Player(Player &rhs);
Player& operator=(Player& rhs);
Player &operator=(Player &rhs);
void Init() override;
void LevelUp() override;
void Die() override;
void TakeDamage(int damageType, float damage) override;
float GetHealth() override;
void ChangeRoom(int roomID);
inline friend void swap(Player& lhs, Player &rhs) noexcept
{
inline friend void swap(Player &lhs, Player &rhs) noexcept {
using std::swap;
swap(lhs.id, rhs.id);
swap(lhs.name, rhs.name);
swap(lhs.description, rhs.description);
swap(lhs.stats, rhs.stats);
swap(lhs.level, rhs.level);
swap(lhs.prevRoomID, rhs.prevRoomID);
swap(lhs.curRoomID, rhs.curRoomID);
}
~Player();
+17 -1
View File
@@ -4,6 +4,7 @@
#include <string>
#include <vector>
#include "json.hpp"
#include "player.h"
#include "scenery.h"
using json = nlohmann::json;
@@ -26,14 +27,17 @@ private:
int id;
std::string name;
std::string description;
Player player;
std::vector<Exit> exits;
std::vector<Scenery> scenery;
std::vector<Scenery> scenery; /// ToDo: Replace with entity component system
public:
Room();
Room(int i, std::string n, std::string desc, std::vector<Exit> e, std::vector<Scenery> s);
Room(const Room &r);
void Enter(Player &p);
void PrintAvalibleExits();
void Print() const;
int GetID() const { return id; }
@@ -53,8 +57,20 @@ public:
return false;
}
Room &operator=(Room rhs);
~Room();
friend void to_json(nlohmann::json &j, const Room &r);
friend void from_json(const nlohmann::json &j, Room &r);
inline friend void swap(Room &lhs, Room &rhs) noexcept {
using std::swap;
swap(lhs.id, rhs.id);
swap(lhs.name, rhs.name);
swap(lhs.description, rhs.description);
swap(lhs.player, rhs.player);
swap(lhs.exits, rhs.exits);
swap(lhs.scenery, rhs.scenery);
}
};
+10
View File
@@ -0,0 +1,10 @@
#pragma once
#include "room.h"
class World {
private:
std::vector<std::vector<Room>> rooms;
public:
void Init();
};