Inital Commit

This commit is contained in:
Timothy O'Barr
2026-08-07 13:10:07 -05:00
commit 34f7d3f7bb
72 changed files with 31475 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
#pragma once
#include <map>
#include <string>
#include <vector>
typedef int (*FUNCTION)(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"};
class CommandParser {
private:
// std::vector<std::string> commands;
std::map<std::string, FUNCTION> commands;
public:
CommandParser();
bool AddCommand(std::string c, FUNCTION f);
void RemoveCommand(std::string c);
std::vector<std::string> Verb(std::stringstream &sentences);
std::vector<std::string> Noun(std::stringstream &sentences);
static inline void CommandUnrecognized() { printf("I don't know how to do that.\n"); }
int Parse();
};
+41
View File
@@ -0,0 +1,41 @@
#pragma once
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
#include <vector>
enum DmgType {SINGLE, MULTI};
struct Stat
{
int statID;
std::string statName;
float stat;
};
class Creature
{
protected:
int id;
int level;
std::vector<Stat> stats;
std::string name;
std::string description;
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); }
void PrintName() { printf("%s\n", name); }
virtual ~Creature() = default;
};
+6
View File
@@ -0,0 +1,6 @@
#pragma once
#include <iostream>
#include <iomanip>
#include <math.h>
#include <string>
+42
View File
@@ -0,0 +1,42 @@
#pragma once
#include <filesystem>
#include <fstream>
#include <string>
#include <vector>
#include "CommandParser.h"
#include "game.h"
#include "json.hpp"
#include "player.h"
#include "room.h"
extern bool isActive;
#define MAP_HEIGHT 5
#define MAP_WIDTH 5
namespace fs = std::filesystem;
class Game {
private:
std::vector<std::vector<Room>> rooms;
Player player;
int progress;
CommandParser parser;
nlohmann::json json;
fs::path filePath = "Resources/Rooms.json";
std::ifstream stream;
public:
Game();
static bool GetIsActive() { return isActive; }
bool Init();
void ChangeRoom(Direction dir);
void Run();
bool Save();
static void SetIsActive(const bool active) { isActive = active; }
};
static int Exit(std::string n);
+49
View File
@@ -0,0 +1,49 @@
#pragma once
#include <iomanip>
#include <iostream>
#include <vector>
#include "json.hpp"
using json = nlohmann::json;
enum class ObjectType { ITEM, SCENERY, NONE };
class Object {
protected:
int id;
std::string name;
std::string description;
std::vector<std::string> keywords;
ObjectType type;
bool canTake;
int roomIdItBelongsTo;
public:
virtual void Interact() = 0;
std::string const GetName() { return name; }
std::string const GetDescription() { return description; }
ObjectType const GetObjectType() { return type; }
std::vector<std::string> const GetKeywords() { return keywords; }
int GetId() { return id; }
int GetRoomId() { return roomIdItBelongsTo; }
bool CanTake() { return canTake; }
virtual ~Object() = default;
};
// Global/Namespace scope serialization functions
inline void to_json(json &j, Object &obj) {
j = json{{"id", obj.GetId()},
{"name", obj.GetName()},
{"description", obj.GetDescription()},
{"keywords", obj.GetKeywords()},
{"type", obj.GetObjectType()},
{"canTake", obj.CanTake()},
{"roomIdItBelongsTo", obj.GetRoomId()}};
}
+22
View File
@@ -0,0 +1,22 @@
#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(int damageType, float damage);
float GetHealth();
};
+22
View File
@@ -0,0 +1,22 @@
#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();
};
+41
View File
@@ -0,0 +1,41 @@
#pragma once
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include "json.hpp"
#include "object.h"
using json = nlohmann::json;
enum Direction { N, S, E, W };
struct Exit {
int exitID;
Direction dir;
bool isLocked;
friend void from_json(const json &j, Exit &e);
friend void to_json(json &j, const Exit &e);
};
class Room {
private:
int id;
std::string name;
std::string description;
std::vector<Exit> exits;
std::vector<std::unique_ptr<Object>> objects;
public:
Room();
Room(int id, std::string name, std::string desc, std::vector<Exit> e);
Room(const Room &r);
int AvalibleExits() { return exits.size(); }
void Print() const;
~Room();
friend void to_json(nlohmann::json &j, const Room &r);
friend void from_json(const nlohmann::json &j, Room &r);
};
+16
View File
@@ -0,0 +1,16 @@
#pragma once
#include <iostream>
#include <iomanip>
#include "object.h"
class Scenery : Object
{
private:
bool containsItem;
public:
Scenery();
void Examine();
void Interact();
~Scenery();
};
+7
View File
@@ -0,0 +1,7 @@
#pragma once
#include <iostream>
#include <iomanip>
#include "object.h"
class Scenery : Object