Wip: Working on room movements, player location in room, and data storage
This commit is contained in:
Generated
+1
@@ -1,6 +1,7 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="BackendCodeEditorSettings">
|
<component name="BackendCodeEditorSettings">
|
||||||
|
<option name="/Default/CodeInspection/ExcludedFiles/FilesAndFoldersToSkip2/=BDF50448_002D2D09_002D587C_002DB381_002D254F4D0C7518_002Fd_003AEngine_002Fd_003Asrc_002Ff_003Aworld_002Ecpp/@EntryIndexedValue" value="ForceIncluded" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CDeclarationWithImplicitIntType/@EntryIndexedValue" value="WARNING" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CDeclarationWithImplicitIntType/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CommentTypo/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=CommentTypo/@EntryIndexedValue" value="DO_NOT_SHOW" type="string" />
|
||||||
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConstevalIfIsAlwaysConstant/@EntryIndexedValue" value="WARNING" type="string" />
|
<option name="/Default/CodeInspection/Highlighting/InspectionSeverities/=ConstevalIfIsAlwaysConstant/@EntryIndexedValue" value="WARNING" type="string" />
|
||||||
|
|||||||
@@ -6,7 +6,8 @@ set(SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/src/room.cpp
|
|||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/game.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/game.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/player.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/player.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/scenery.cpp
|
${CMAKE_CURRENT_SOURCE_DIR}/src/scenery.cpp
|
||||||
${CMAKE_CURRENT_SOURCE_DIR}/src/CommandParser.cpp)
|
${CMAKE_CURRENT_SOURCE_DIR}/src/CommandParser.cpp
|
||||||
|
${CMAKE_CURRENT_SOURCE_DIR}/src/world.cpp)
|
||||||
|
|
||||||
|
|
||||||
add_library(Engine SHARED ${SOURCES})
|
add_library(Engine SHARED ${SOURCES})
|
||||||
|
|||||||
@@ -6,8 +6,8 @@
|
|||||||
typedef int (*FUNCTION)(const std::string &s);
|
typedef int (*FUNCTION)(const std::string &s);
|
||||||
|
|
||||||
static std::vector<std::string> Verbs{"Quit", "Exit", "Go", "Move", "Look"};
|
static std::vector<std::string> Verbs{"Quit", "Exit", "Go", "Move", "Look"};
|
||||||
static std::vector<std::string> Nouns{"Object", "Door", "North", "South", "East",
|
static std::vector<std::string> Nouns{"Object", "Door", "North", "South", "East", "West",
|
||||||
"West", "Up", "Down", "Left", "right"};
|
"Up", "Down", "Left", "Right", "To", "At"};
|
||||||
|
|
||||||
class CommandParser {
|
class CommandParser {
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -28,10 +28,8 @@ private:
|
|||||||
std::ifstream stream;
|
std::ifstream stream;
|
||||||
bool isActive;
|
bool isActive;
|
||||||
|
|
||||||
|
|
||||||
inline static Game *game_;
|
inline static Game *game_;
|
||||||
|
|
||||||
|
|
||||||
// Likely need to make sure Player is ADDED to room
|
// Likely need to make sure Player is ADDED to room
|
||||||
// We want player and objects to exist IN room
|
// We want player and objects to exist IN room
|
||||||
Room currentRoom;
|
Room currentRoom;
|
||||||
@@ -44,7 +42,7 @@ public:
|
|||||||
void Run();
|
void Run();
|
||||||
bool Save();
|
bool Save();
|
||||||
|
|
||||||
void ChangeRoom(Room r);
|
void ChangeRoom(const Room &r);
|
||||||
Room GetCurrentRoom() { return currentRoom; }
|
Room GetCurrentRoom() { return currentRoom; }
|
||||||
|
|
||||||
inline bool operator!() const {
|
inline bool operator!() const {
|
||||||
@@ -64,9 +62,7 @@ public:
|
|||||||
return *game_;
|
return *game_;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void SetGameInstance(Game * g) {
|
static void SetGameInstance(Game *g) { game_ = g; }
|
||||||
game_ = g;
|
|
||||||
}
|
|
||||||
|
|
||||||
~Game();
|
~Game();
|
||||||
};
|
};
|
||||||
|
|||||||
+1
-10
@@ -10,12 +10,7 @@ class Player : Creature {
|
|||||||
private:
|
private:
|
||||||
// Inventory inventory;
|
// 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:
|
public:
|
||||||
|
|
||||||
Player();
|
Player();
|
||||||
Player(Player &rhs);
|
Player(Player &rhs);
|
||||||
Player &operator=(Player &rhs);
|
Player &operator=(Player &rhs);
|
||||||
@@ -25,18 +20,14 @@ public:
|
|||||||
void Die() override;
|
void Die() override;
|
||||||
void TakeDamage(int damageType, float damage) override;
|
void TakeDamage(int damageType, float damage) override;
|
||||||
float GetHealth() 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;
|
using std::swap;
|
||||||
swap(lhs.id, rhs.id);
|
swap(lhs.id, rhs.id);
|
||||||
swap(lhs.name, rhs.name);
|
swap(lhs.name, rhs.name);
|
||||||
swap(lhs.description, rhs.description);
|
swap(lhs.description, rhs.description);
|
||||||
swap(lhs.stats, rhs.stats);
|
swap(lhs.stats, rhs.stats);
|
||||||
swap(lhs.level, rhs.level);
|
swap(lhs.level, rhs.level);
|
||||||
swap(lhs.prevRoomID, rhs.prevRoomID);
|
|
||||||
swap(lhs.curRoomID, rhs.curRoomID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
~Player();
|
~Player();
|
||||||
|
|||||||
+17
-1
@@ -4,6 +4,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include "json.hpp"
|
#include "json.hpp"
|
||||||
|
#include "player.h"
|
||||||
#include "scenery.h"
|
#include "scenery.h"
|
||||||
|
|
||||||
using json = nlohmann::json;
|
using json = nlohmann::json;
|
||||||
@@ -26,14 +27,17 @@ private:
|
|||||||
int id;
|
int id;
|
||||||
std::string name;
|
std::string name;
|
||||||
std::string description;
|
std::string description;
|
||||||
|
Player player;
|
||||||
std::vector<Exit> exits;
|
std::vector<Exit> exits;
|
||||||
std::vector<Scenery> scenery;
|
std::vector<Scenery> scenery; /// ToDo: Replace with entity component system
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Room();
|
Room();
|
||||||
Room(int i, std::string n, std::string desc, std::vector<Exit> e, std::vector<Scenery> s);
|
Room(int i, std::string n, std::string desc, std::vector<Exit> e, std::vector<Scenery> s);
|
||||||
Room(const Room &r);
|
Room(const Room &r);
|
||||||
|
|
||||||
|
void Enter(Player &p);
|
||||||
|
|
||||||
void PrintAvalibleExits();
|
void PrintAvalibleExits();
|
||||||
void Print() const;
|
void Print() const;
|
||||||
int GetID() const { return id; }
|
int GetID() const { return id; }
|
||||||
@@ -53,8 +57,20 @@ public:
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Room &operator=(Room rhs);
|
||||||
|
|
||||||
~Room();
|
~Room();
|
||||||
|
|
||||||
friend void to_json(nlohmann::json &j, const Room &r);
|
friend void to_json(nlohmann::json &j, const Room &r);
|
||||||
friend void from_json(const nlohmann::json &j, 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);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "room.h"
|
||||||
|
|
||||||
|
class World {
|
||||||
|
private:
|
||||||
|
std::vector<std::vector<Room>> rooms;
|
||||||
|
|
||||||
|
public:
|
||||||
|
void Init();
|
||||||
|
};
|
||||||
@@ -61,11 +61,15 @@ int CommandParser::Parse() {
|
|||||||
nouns = Noun(c);
|
nouns = Noun(c);
|
||||||
|
|
||||||
for (const auto &verb: verbs) {
|
for (const auto &verb: verbs) {
|
||||||
|
|
||||||
if (!commands[verb]) {
|
if (!commands[verb]) {
|
||||||
CommandUnrecognized();
|
CommandUnrecognized();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (const auto &n: nouns) {
|
||||||
|
noun = n;
|
||||||
|
}
|
||||||
|
|
||||||
toRun = commands[verb];
|
toRun = commands[verb];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+12
-9
@@ -59,15 +59,11 @@ void Game::Run() {
|
|||||||
|
|
||||||
bool Game::Save() { return false; }
|
bool Game::Save() { return false; }
|
||||||
|
|
||||||
void Game::ChangeRoom(Room r) {
|
void Game::ChangeRoom(const Room &r) {
|
||||||
if (currentRoom != r) {
|
if (currentRoom != r) {
|
||||||
currentRoom = r;
|
currentRoom = r;
|
||||||
|
|
||||||
player.ChangeRoom(currentRoom.GetID());
|
currentRoom.Enter(player);
|
||||||
|
|
||||||
currentRoom.Print();
|
|
||||||
printf("\n");
|
|
||||||
currentRoom.PrintAvalibleExits();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +137,15 @@ int Move(const std::string &c) {
|
|||||||
break;
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,8 +157,7 @@ int Look(const std::string &c) {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
Game::~Game()
|
Game::~Game() {
|
||||||
{
|
|
||||||
isActive = false;
|
isActive = false;
|
||||||
progress = 0;
|
progress = 0;
|
||||||
}
|
}
|
||||||
+4
-25
@@ -2,24 +2,17 @@
|
|||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
Player::Player()
|
Player::Player() { Init(); }
|
||||||
{
|
|
||||||
Init();
|
|
||||||
}
|
|
||||||
|
|
||||||
Player::Player(Player &rhs)
|
Player::Player(Player &rhs) {
|
||||||
{
|
|
||||||
id = rhs.id;
|
id = rhs.id;
|
||||||
level = rhs.level;
|
level = rhs.level;
|
||||||
stats = rhs.stats;
|
stats = rhs.stats;
|
||||||
name = rhs.name;
|
name = rhs.name;
|
||||||
description = rhs.description;
|
description = rhs.description;
|
||||||
curRoomID = rhs.curRoomID;
|
|
||||||
prevRoomID = rhs.prevRoomID;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Player& Player::operator=(Player& rhs)
|
Player &Player::operator=(Player &rhs) {
|
||||||
{
|
|
||||||
swap(*this, rhs);
|
swap(*this, rhs);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
@@ -42,24 +35,10 @@ void Player::TakeDamage(int damageType, float damage) {
|
|||||||
|
|
||||||
float Player::GetHealth() { return 0.0f; }
|
float Player::GetHealth() { return 0.0f; }
|
||||||
|
|
||||||
void Player::ChangeRoom(int roomID) {
|
Player::~Player() {
|
||||||
if (prevRoomID == roomID) {
|
|
||||||
curRoomID = prevRoomID;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if (curRoomID != roomID) {
|
|
||||||
prevRoomID = curRoomID;
|
|
||||||
curRoomID = roomID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Player::~Player()
|
|
||||||
{
|
|
||||||
id = -1;
|
id = -1;
|
||||||
level = -1;
|
level = -1;
|
||||||
stats = {};
|
stats = {};
|
||||||
name.erase();
|
name.erase();
|
||||||
description.erase();
|
description.erase();
|
||||||
curRoomID = -1;
|
|
||||||
prevRoomID = -1;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,6 +33,16 @@ Room::~Room() {
|
|||||||
exits.clear();
|
exits.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Room::Enter(Player &p) {
|
||||||
|
player = p;
|
||||||
|
Print();
|
||||||
|
}
|
||||||
|
|
||||||
|
Room &Room::operator=(Room rhs) {
|
||||||
|
swap(*this, rhs);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
void Room::Print() const {
|
void Room::Print() const {
|
||||||
printf("%s\n", name.c_str());
|
printf("%s\n", name.c_str());
|
||||||
printf("%s\n", description.c_str());
|
printf("%s\n", description.c_str());
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
#include "world.h"
|
||||||
|
|
||||||
|
void World::Init() { return; }
|
||||||
@@ -1,8 +1,8 @@
|
|||||||
|
#include <chrono>
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
void EditRooms() {
|
void EditRooms() {
|
||||||
|
|
||||||
|
|
||||||
fs::path path("Resources/rooms.json");
|
fs::path path("Resources/rooms.json");
|
||||||
|
|
||||||
std::vector<std::vector<Room>> roomDat = {
|
std::vector<std::vector<Room>> roomDat = {
|
||||||
@@ -43,9 +43,12 @@ void EditRooms() {
|
|||||||
outFile.close();
|
outFile.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[]) {
|
int main(int argc, char *argv[]) {
|
||||||
Game game; // Calls default constructor which Initializes GAME
|
Game game;
|
||||||
|
double delta;
|
||||||
|
double t;
|
||||||
|
|
||||||
|
// double current_time =
|
||||||
|
|
||||||
if (!game) {
|
if (!game) {
|
||||||
game.Init();
|
game.Init();
|
||||||
|
|||||||
Reference in New Issue
Block a user