Implement basic rooms and navigation

This commit is contained in:
Timothy O'Barr
2026-08-20 08:10:07 -05:00
parent 707b88c736
commit 9b72d1588e
11 changed files with 125 additions and 115 deletions
+37 -27
View File
@@ -1,41 +1,51 @@
#pragma once
#include <iostream>
#include <iomanip>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
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<Stat> 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<std::string, Stat> 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;
};
-6
View File
@@ -1,6 +0,0 @@
#pragma once
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
+4 -1
View File
@@ -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);
+15 -12
View File
@@ -1,22 +1,25 @@
#pragma once
#include <iostream>
#include <string>
#include <math.h>
#include <string>
#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);
};
-22
View File
@@ -1,22 +0,0 @@
#pragma once
#include <iostream>
#include <string>
#include <math.h>
#include "creature.h"
class Player : Creature
{
private:
// Inventory inventory;
public:
void Init();
void LevelUp();
void Die();
void TakeDamage();
};
+5 -1
View File
@@ -30,11 +30,15 @@ public:
Room(int id, std::string name, std::string desc, std::vector<Exit> 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);