Implement basic rooms and navigation
This commit is contained in:
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
+35
-25
@@ -1,41 +1,51 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <iostream>
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
enum DmgType {SINGLE, MULTI};
|
enum DmgType { SINGLE, MULTI };
|
||||||
|
|
||||||
struct Stat
|
struct Stat {
|
||||||
{
|
int statID;
|
||||||
int statID;
|
float stat;
|
||||||
std::string statName;
|
|
||||||
float stat;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class Creature
|
struct Stats {
|
||||||
{
|
float hp;
|
||||||
protected:
|
float speed;
|
||||||
int id;
|
float magic;
|
||||||
int level;
|
float defense;
|
||||||
std::vector<Stat> stats;
|
};
|
||||||
std::string name;
|
|
||||||
std::string description;
|
|
||||||
|
|
||||||
public:
|
struct RoomInfo {
|
||||||
virtual void Init() = 0;
|
int roomID;
|
||||||
virtual void LevelUp() = 0;
|
int x, y;
|
||||||
virtual void Die() = 0;
|
};
|
||||||
virtual void TakeDamage(int damageType, float damage) = 0;
|
|
||||||
virtual float GetHealth() = 0;
|
|
||||||
|
|
||||||
|
class Creature {
|
||||||
|
protected:
|
||||||
|
int id = -1;
|
||||||
|
int level = 0;
|
||||||
|
Stats stats = {};
|
||||||
|
// std::map<std::string, Stat> stats;
|
||||||
|
std::string name;
|
||||||
|
std::string description;
|
||||||
|
|
||||||
bool IsAlive() { return GetHealth() > 0; }
|
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;
|
||||||
|
|
||||||
void PrintDescription() { printf("%s\n", description); }
|
|
||||||
void PrintName() { printf("%s\n", name); }
|
|
||||||
|
|
||||||
virtual ~Creature() = default;
|
bool IsAlive() { return GetHealth() > 0; }
|
||||||
|
|
||||||
|
void PrintDescription() { printf("%s\n", description.c_str()); }
|
||||||
|
void PrintName() { printf("%s\n", name.c_str()); }
|
||||||
|
|
||||||
|
virtual ~Creature() = default;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
|
|
||||||
#include <iostream>
|
|
||||||
#include <iomanip>
|
|
||||||
#include <math.h>
|
|
||||||
#include <string>
|
|
||||||
@@ -11,6 +11,9 @@
|
|||||||
|
|
||||||
extern bool isActive;
|
extern bool isActive;
|
||||||
|
|
||||||
|
extern int curX, curY;
|
||||||
|
|
||||||
|
|
||||||
#define MAP_HEIGHT 5
|
#define MAP_HEIGHT 5
|
||||||
#define MAP_WIDTH 5
|
#define MAP_WIDTH 5
|
||||||
|
|
||||||
@@ -40,4 +43,4 @@ public:
|
|||||||
static void SetIsActive(const bool active) { isActive = active; }
|
static void SetIsActive(const bool active) { isActive = active; }
|
||||||
};
|
};
|
||||||
|
|
||||||
static int Exit(std::string n);
|
static int Quit(std::string n);
|
||||||
|
|||||||
+14
-11
@@ -1,22 +1,25 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
#include <string>
|
||||||
#include "creature.h"
|
#include "creature.h"
|
||||||
|
|
||||||
|
|
||||||
class Player : Creature
|
class Player : Creature {
|
||||||
{
|
private:
|
||||||
|
// Inventory inventory;
|
||||||
|
|
||||||
private:
|
// Lets keep the room a loose reference to avoid to many hardcoded details and other info
|
||||||
// Inventory inventory;
|
int curRoomID = -1;
|
||||||
|
int prevRoomID = -1;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
void Init() override;
|
||||||
|
void LevelUp() override;
|
||||||
|
void Die() override;
|
||||||
|
void TakeDamage(int damageType, float damage) override;
|
||||||
|
float GetHealth() override;
|
||||||
|
|
||||||
void Init();
|
void ChangeRoom(int roomID);
|
||||||
void LevelUp();
|
|
||||||
void Die();
|
|
||||||
void TakeDamage(int damageType, float damage);
|
|
||||||
float GetHealth();
|
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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();
|
|
||||||
|
|
||||||
};
|
|
||||||
@@ -30,11 +30,15 @@ public:
|
|||||||
Room(int id, std::string name, std::string desc, std::vector<Exit> e);
|
Room(int id, std::string name, std::string desc, std::vector<Exit> e);
|
||||||
Room(const Room &r);
|
Room(const Room &r);
|
||||||
|
|
||||||
int AvalibleExits() { return exits.size(); }
|
int AvalibleExits() const { return exits.size(); }
|
||||||
void Print() const;
|
void Print() const;
|
||||||
|
|
||||||
|
int GetID() const { return id; }
|
||||||
|
|
||||||
~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);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static int Move(std::string c);
|
||||||
|
|||||||
+8
-7
@@ -3,6 +3,8 @@
|
|||||||
|
|
||||||
bool isActive;
|
bool isActive;
|
||||||
|
|
||||||
|
int curX, curY;
|
||||||
|
|
||||||
Game::Game() {
|
Game::Game() {
|
||||||
progress = 0;
|
progress = 0;
|
||||||
Init();
|
Init();
|
||||||
@@ -23,17 +25,16 @@ bool Game::Init() {
|
|||||||
rooms = json.get<std::vector<std::vector<Room>>>();
|
rooms = json.get<std::vector<std::vector<Room>>>();
|
||||||
player.Init();
|
player.Init();
|
||||||
parser = CommandParser();
|
parser = CommandParser();
|
||||||
|
parser.AddCommand("Exit", Quit);
|
||||||
|
|
||||||
FUNCTION exit = Exit;
|
currentRoom = rooms[0][0];
|
||||||
|
player.ChangeRoom(currentRoom.GetID());
|
||||||
parser.AddCommand("Exit", exit);
|
currentRoom.Print();
|
||||||
|
|
||||||
// Initalize Objects
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Game::ChangeRoom(Direction dir) {}
|
void Game::ChangeRoom(Direction dir) { currentRoom.Print(); }
|
||||||
|
|
||||||
void Game::Run() {
|
void Game::Run() {
|
||||||
while (isActive) {
|
while (isActive) {
|
||||||
@@ -44,7 +45,7 @@ void Game::Run() {
|
|||||||
|
|
||||||
bool Game::Save() { return false; }
|
bool Game::Save() { return false; }
|
||||||
|
|
||||||
int Exit(std::string n) {
|
int Quit(std::string n) {
|
||||||
isActive = false;
|
isActive = false;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
+18
-15
@@ -1,28 +1,31 @@
|
|||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
|
||||||
void Player::Init()
|
void Player::Init() {
|
||||||
{
|
// initialize stats, room location, inventory and item data
|
||||||
// initalize 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()
|
void Player::TakeDamage(int damageType, float damage) {
|
||||||
{
|
// Ouch
|
||||||
// Now. You must, die!
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Player::TakeDamage(int damageType, float damage)
|
float Player::GetHealth() { return 0.0f; }
|
||||||
{
|
|
||||||
// Ouch
|
|
||||||
}
|
|
||||||
|
|
||||||
float Player::GetHealth()
|
void Player::ChangeRoom(int roomID) {
|
||||||
{
|
if (prevRoomID == roomID) {
|
||||||
|
curRoomID = prevRoomID;
|
||||||
|
}
|
||||||
|
|
||||||
return 0.0f;
|
else if (curRoomID != roomID) {
|
||||||
|
prevRoomID = curRoomID;
|
||||||
|
curRoomID = roomID;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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
@@ -1,5 +1,7 @@
|
|||||||
#include "room.h"
|
#include "room.h"
|
||||||
|
|
||||||
|
#include "game.h"
|
||||||
|
|
||||||
Room::Room() {
|
Room::Room() {
|
||||||
id = -1;
|
id = -1;
|
||||||
name = "Nothing";
|
name = "Nothing";
|
||||||
@@ -33,7 +35,6 @@ void Room::Print() const {
|
|||||||
printf("%s\n", description.c_str());
|
printf("%s\n", description.c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void from_json(const json &j, Exit &e) {
|
void from_json(const json &j, Exit &e) {
|
||||||
j.at("exitID").get_to(e.exitID);
|
j.at("exitID").get_to(e.exitID);
|
||||||
j.at("dir").get_to(e.dir);
|
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);
|
j.at("exits").get_to(r.exits);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void to_json(nlohmann::json &j, const Room &r) {
|
void to_json(nlohmann::json &j, const Room &r) {
|
||||||
j = json{{"id", r.id}, {"name", r.name}, {"description", r.description}, {"exits", r.exits}};
|
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;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user