From 9b72d1588e6694cfd734c8c98b12a8db81f9c888 Mon Sep 17 00:00:00 2001 From: Timothy O'Barr Date: Thu, 20 Aug 2026 08:10:07 -0500 Subject: [PATCH] Implement basic rooms and navigation --- .idea/vcs.xml | 6 ++++ Engine/headers/creature.h | 64 ++++++++++++++++++++++---------------- Engine/headers/creature.h~ | 6 ---- Engine/headers/game.h | 5 ++- Engine/headers/player.h | 27 +++++++++------- Engine/headers/player.h~ | 22 ------------- Engine/headers/room.h | 6 +++- Engine/src/game.cpp | 15 ++++----- Engine/src/player.cpp | 33 +++++++++++--------- Engine/src/player.cpp~ | 22 ------------- Engine/src/room.cpp | 34 ++++++++++++++++++-- 11 files changed, 125 insertions(+), 115 deletions(-) create mode 100644 .idea/vcs.xml delete mode 100644 Engine/headers/creature.h~ delete mode 100644 Engine/headers/player.h~ delete mode 100644 Engine/src/player.cpp~ diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Engine/headers/creature.h b/Engine/headers/creature.h index 529d803..c826581 100644 --- a/Engine/headers/creature.h +++ b/Engine/headers/creature.h @@ -1,41 +1,51 @@ #pragma once -#include #include +#include #include #include #include -enum DmgType {SINGLE, MULTI}; +enum DmgType { SINGLE, MULTI }; -struct Stat -{ - int statID; - std::string statName; - float stat; +struct Stat { + int statID; + float stat; }; -class Creature -{ - protected: - int id; - int level; - std::vector stats; - std::string name; - std::string description; +struct Stats { + float hp; + float speed; + float magic; + float defense; +}; - public: - virtual void Init() = 0; - virtual void LevelUp() = 0; - virtual void Die() = 0; - virtual void TakeDamage(int damageType, float damage) = 0; - virtual float GetHealth() = 0; +struct RoomInfo { + int roomID; + int x, y; +}; - - bool IsAlive() { return GetHealth() > 0; } - - void PrintDescription() { printf("%s\n", description); } - void PrintName() { printf("%s\n", name); } +class Creature { +protected: + int id = -1; + int level = 0; + Stats stats = {}; + // std::map stats; + std::string name; + std::string description; - virtual ~Creature() = default; +public: + virtual void Init() = 0; + virtual void LevelUp() = 0; + virtual void Die() = 0; + virtual void TakeDamage(int damageType, float damage) = 0; + virtual float GetHealth() = 0; + + + bool IsAlive() { return GetHealth() > 0; } + + void PrintDescription() { printf("%s\n", description.c_str()); } + void PrintName() { printf("%s\n", name.c_str()); } + + virtual ~Creature() = default; }; diff --git a/Engine/headers/creature.h~ b/Engine/headers/creature.h~ deleted file mode 100644 index acdbf29..0000000 --- a/Engine/headers/creature.h~ +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#include -#include -#include -#include diff --git a/Engine/headers/game.h b/Engine/headers/game.h index b63f718..b6a007d 100644 --- a/Engine/headers/game.h +++ b/Engine/headers/game.h @@ -11,6 +11,9 @@ extern bool isActive; +extern int curX, curY; + + #define MAP_HEIGHT 5 #define MAP_WIDTH 5 @@ -40,4 +43,4 @@ public: static void SetIsActive(const bool active) { isActive = active; } }; -static int Exit(std::string n); +static int Quit(std::string n); diff --git a/Engine/headers/player.h b/Engine/headers/player.h index 121c889..063eb1c 100644 --- a/Engine/headers/player.h +++ b/Engine/headers/player.h @@ -1,22 +1,25 @@ #pragma once #include -#include #include +#include #include "creature.h" -class Player : Creature -{ +class Player : Creature { +private: + // Inventory inventory; - private: - // Inventory inventory; - - public: + // Lets keep the room a loose reference to avoid to many hardcoded details and other info + int curRoomID = -1; + int prevRoomID = -1; - void Init(); - void LevelUp(); - void Die(); - void TakeDamage(int damageType, float damage); - float GetHealth(); +public: + void Init() override; + void LevelUp() override; + void Die() override; + void TakeDamage(int damageType, float damage) override; + float GetHealth() override; + + void ChangeRoom(int roomID); }; diff --git a/Engine/headers/player.h~ b/Engine/headers/player.h~ deleted file mode 100644 index d272fd9..0000000 --- a/Engine/headers/player.h~ +++ /dev/null @@ -1,22 +0,0 @@ -#pragma once - -#include -#include -#include -#include "creature.h" - - -class Player : Creature -{ - - private: - // Inventory inventory; - - public: - - void Init(); - void LevelUp(); - void Die(); - void TakeDamage(); - -}; diff --git a/Engine/headers/room.h b/Engine/headers/room.h index 0948380..b2ad8eb 100644 --- a/Engine/headers/room.h +++ b/Engine/headers/room.h @@ -30,11 +30,15 @@ public: Room(int id, std::string name, std::string desc, std::vector e); Room(const Room &r); - int AvalibleExits() { return exits.size(); } + int AvalibleExits() const { return exits.size(); } void Print() const; + int GetID() const { return id; } + ~Room(); friend void to_json(nlohmann::json &j, const Room &r); friend void from_json(const nlohmann::json &j, Room &r); }; + +static int Move(std::string c); diff --git a/Engine/src/game.cpp b/Engine/src/game.cpp index 14a8a41..48ef43a 100644 --- a/Engine/src/game.cpp +++ b/Engine/src/game.cpp @@ -3,6 +3,8 @@ bool isActive; +int curX, curY; + Game::Game() { progress = 0; Init(); @@ -23,17 +25,16 @@ bool Game::Init() { rooms = json.get>>(); player.Init(); parser = CommandParser(); + parser.AddCommand("Exit", Quit); - FUNCTION exit = Exit; - - parser.AddCommand("Exit", exit); - - // Initalize Objects + currentRoom = rooms[0][0]; + player.ChangeRoom(currentRoom.GetID()); + currentRoom.Print(); return true; } -void Game::ChangeRoom(Direction dir) {} +void Game::ChangeRoom(Direction dir) { currentRoom.Print(); } void Game::Run() { while (isActive) { @@ -44,7 +45,7 @@ void Game::Run() { bool Game::Save() { return false; } -int Exit(std::string n) { +int Quit(std::string n) { isActive = false; return 0; } diff --git a/Engine/src/player.cpp b/Engine/src/player.cpp index 50942ff..9506594 100644 --- a/Engine/src/player.cpp +++ b/Engine/src/player.cpp @@ -1,28 +1,31 @@ #include "player.h" -void Player::Init() -{ - // initalize stats, room location, inventory and item data +void Player::Init() { + // initialize stats, room location, inventory and item data + stats = Stats{100.0f, 50.00f, 150.00f, 50.00f}; + name = "Player"; } -void Player::LevelUp() -{ +void Player::LevelUp() {} +void Player::Die() { + // Now. You must, die! } -void Player::Die() -{ - // Now. You must, die! +void Player::TakeDamage(int damageType, float damage) { + // Ouch } -void Player::TakeDamage(int damageType, float damage) -{ - // Ouch -} +float Player::GetHealth() { return 0.0f; } -float Player::GetHealth() -{ +void Player::ChangeRoom(int roomID) { + if (prevRoomID == roomID) { + curRoomID = prevRoomID; + } - return 0.0f; + else if (curRoomID != roomID) { + prevRoomID = curRoomID; + curRoomID = roomID; + } } diff --git a/Engine/src/player.cpp~ b/Engine/src/player.cpp~ deleted file mode 100644 index 3938616..0000000 --- a/Engine/src/player.cpp~ +++ /dev/null @@ -1,22 +0,0 @@ -#include "player.h" - -void Player::Init() -{ - // initalize stats, room location, inventory and item data - -} - -void Player::LevelUp() -{ - -} - -void Player::Die() -{ - // Now. You must, die! -} - -void Player::TakeDamage() -{ - // Ouch -} diff --git a/Engine/src/room.cpp b/Engine/src/room.cpp index 983cd0b..7013aae 100644 --- a/Engine/src/room.cpp +++ b/Engine/src/room.cpp @@ -1,5 +1,7 @@ #include "room.h" +#include "game.h" + Room::Room() { id = -1; name = "Nothing"; @@ -33,7 +35,6 @@ void Room::Print() const { printf("%s\n", description.c_str()); } - void from_json(const json &j, Exit &e) { j.at("exitID").get_to(e.exitID); j.at("dir").get_to(e.dir); @@ -50,7 +51,36 @@ void from_json(const json &j, Room &r) { j.at("exits").get_to(r.exits); } - void to_json(nlohmann::json &j, const Room &r) { j = json{{"id", r.id}, {"name", r.name}, {"description", r.description}, {"exits", r.exits}}; } + +int Move(std::string c) { + + char dir; + printf("What Direction: "); + std::cin >> dir; + + + switch (dir) { + case 'N': + curY += 1; + break; + + case 'S': + curY -= 1; + break; + + case 'E': + curX += 1; + break; + + case 'W': + curX -= 1; + break; + default: + return 0; + break; + }; + return 0; +}