diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..3ba9c43 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,32 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(gdb) Launch", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/Text-Adventure", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "externalConsole": false, + "MIMode": "gdb", + "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "-enable-pretty-printing", + "ignoreFailures": true + }, + { + "description": "Set Disassembly Flavor to Intel", + "text": "-gdb-set disassembly-flavor intel", + "ignoreFailures": true + } + ] + } + ] +} \ No newline at end of file diff --git a/Editor/headers/creature.h b/Editor/headers/creature.h index 529d803..6932429 100644 --- a/Editor/headers/creature.h +++ b/Editor/headers/creature.h @@ -34,8 +34,8 @@ class Creature bool IsAlive() { return GetHealth() > 0; } - void PrintDescription() { printf("%s\n", description); } - void PrintName() { printf("%s\n", name); } + void PrintDescription() { printf("%s\n", description.data()); } + void PrintName() { printf("%s\n", name.data()); } virtual ~Creature() = default; }; diff --git a/Editor/src/playerEditor.cpp b/Editor/src/playerEditor.cpp index bd6d383..b5a1fd9 100644 --- a/Editor/src/playerEditor.cpp +++ b/Editor/src/playerEditor.cpp @@ -15,8 +15,8 @@ void PlayerEditor::Edit() { printf("Options: %s\n"); - for (auto &command : commands.begin()) + /*for (const auto &command : commands.begin()) { - printf("%s\n", command.c_str()); - } + printf("%s\n", command); + }*/ } diff --git a/Engine/headers/game.h b/Engine/headers/game.h index df62a90..9a06b47 100644 --- a/Engine/headers/game.h +++ b/Engine/headers/game.h @@ -26,6 +26,8 @@ private: nlohmann::json json; fs::path filePath = "Resources/Rooms.json"; std::ifstream stream; + + inline static Game *game_; // Likely need to make sure Player is ADDED to room @@ -44,13 +46,14 @@ public: static void SetIsActive(const bool active) { isActive = active; } - static Game &instance() { - static Game *game_; + static Game &Instance() { if (game_ == nullptr) { game_ = new Game(); } return *game_; } + + ~Game() = default; }; // Commands diff --git a/Engine/headers/scenery.h~ b/Engine/headers/scenery.h~ deleted file mode 100644 index 9d2f96c..0000000 --- a/Engine/headers/scenery.h~ +++ /dev/null @@ -1,7 +0,0 @@ -#pragma once - -#include -#include -#include "object.h" - -class Scenery : Object diff --git a/Engine/src/CommandParser.cpp b/Engine/src/CommandParser.cpp index 771a657..16a6aba 100644 --- a/Engine/src/CommandParser.cpp +++ b/Engine/src/CommandParser.cpp @@ -1,6 +1,5 @@ #include "CommandParser.h" #include -#include #include #include @@ -24,10 +23,6 @@ std::vector CommandParser::Verb(std::stringstream &sentences) { } } - if (verbs.empty()) { - CommandUnrecognized(); - } - return verbs; } @@ -68,7 +63,7 @@ int CommandParser::Parse() { for (const auto &verb: verbs) { if (!commands[verb]) { - printf("Sorry kid, can't understand ya! \n"); + CommandUnrecognized(); break; } toRun = commands[verb]; diff --git a/Engine/src/game.cpp b/Engine/src/game.cpp index 50f2a44..d176afe 100644 --- a/Engine/src/game.cpp +++ b/Engine/src/game.cpp @@ -1,4 +1,6 @@ #include "game.h" +#include +#include #include bool isActive; @@ -20,6 +22,17 @@ bool Game::Init() { rooms[i].resize(MAP_WIDTH); } + filePath = fs::absolute(filePath); + + + if (!fs::exists(filePath)) { + printf("File Read error! Could not find Json at: \n"); + printf("%s", filePath.c_str()); + isActive = false; + return false; + } + + // Read rooms into buffer stream.open(absolute(filePath)); json = nlohmann::json::parse(stream); @@ -32,9 +45,7 @@ bool Game::Init() { parser.AddCommand("Move", Move); parser.AddCommand("Look", Look); - currentRoom = rooms[curY][curX]; - player.ChangeRoom(currentRoom.GetID()); - currentRoom.Print(); + ChangeRoom(rooms[0][0]); return true; } @@ -52,6 +63,8 @@ void Game::ChangeRoom(Room r) { if (currentRoom != r) { currentRoom = r; + player.ChangeRoom(currentRoom.GetID()); + currentRoom.Print(); printf("\n"); currentRoom.PrintAvalibleExits(); @@ -67,7 +80,7 @@ int Move(const std::string &c) { std::string dirInput = c; - int tmpX = 0, tmpY = 0; + int tmpX = curX, tmpY = curY; if (dirInput.empty()) { printf("What Direction: "); @@ -76,7 +89,7 @@ int Move(const std::string &c) { } const Direction dir = directions[dirInput.data()]; - if (!Game::instance().GetCurrentRoom().ValidDirection(dir)) { + if (!Game::Instance().GetCurrentRoom().ValidDirection(dir)) { printf("Sorry, can't move that direction kiddo \n"); return 0; } @@ -84,18 +97,42 @@ int Move(const std::string &c) { switch (dir) { case N: tmpY -= 1; + if (tmpY > 0 && tmpY < MAP_HEIGHT) { + curY = tmpY; + } else { + printf("Ye hit a wall of some kind! \n"); + return -1; + } break; case S: tmpY += 1; + if (tmpY > 0 && tmpY < MAP_HEIGHT) { + curY = tmpY; + } else { + printf("Ye hit a wall of some kind! \n"); + return -1; + } break; case E: tmpX += 1; + if (tmpX > 0 && tmpX < MAP_WIDTH) { + curX = tmpX; + } else { + printf("Ye hit a wall of some kind! \n"); + return -1; + } break; case W: tmpX -= 1; + if (tmpX > 0 && tmpX < MAP_WIDTH) { + curX = tmpX; + } else { + printf("Ye hit a wall of some kind! \n"); + return -1; + } break; default: printf("Incorrect direction \n"); @@ -103,26 +140,12 @@ int Move(const std::string &c) { break; }; - if (tmpX > 0 && tmpX < MAP_WIDTH) { - curX = tmpX; - } else { - printf("Ye hit a wall of some kind! \n"); - return -1; - } - - if (tmpY > 0 && tmpY < MAP_HEIGHT) { - curY = tmpY; - } else { - printf("Ye hit a wall of some kind! \n"); - return -1; - } - - Game::instance().ChangeRoom(rooms[curY][curX]); + Game::Instance().ChangeRoom(rooms[curY][curX]); return 0; } int Look(const std::string &c) { - Room cur = Game::instance().GetCurrentRoom(); + Room cur = Game::Instance().GetCurrentRoom(); cur.Print(); printf("\n"); cur.PrintAvalibleExits(); diff --git a/Engine/src/room.cpp b/Engine/src/room.cpp index 9fbd5b8..3846304 100644 --- a/Engine/src/room.cpp +++ b/Engine/src/room.cpp @@ -1,4 +1,5 @@ #include "room.h" +#include #include "game.h" @@ -38,7 +39,8 @@ void Room::Print() const { void Room::PrintAvalibleExits() { printf("Available exits are: \n"); for (const auto &exit: exits) { - printf(directionChar[exit.dir].data(), "\n"); + printf(directionChar[exit.dir].c_str()); + printf("\n"); } } diff --git a/Engine/src/scenery.cpp b/Engine/src/scenery.cpp index 1a13bec..abd716f 100644 --- a/Engine/src/scenery.cpp +++ b/Engine/src/scenery.cpp @@ -18,7 +18,7 @@ void Scenery::Interact() void Scenery::Examine() { - printf("%s\n", GetDescription()); + printf("%s\n", GetDescription().data()); } Scenery::~Scenery()