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
+8 -7
View File
@@ -3,6 +3,8 @@
bool isActive;
int curX, curY;
Game::Game() {
progress = 0;
Init();
@@ -23,17 +25,16 @@ bool Game::Init() {
rooms = json.get<std::vector<std::vector<Room>>>();
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;
}
+18 -15
View File
@@ -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;
}
}
-22
View File
@@ -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
}
+32 -2
View File
@@ -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;
}