77 lines
1.8 KiB
C++
77 lines
1.8 KiB
C++
#pragma once
|
|
#include <iostream>
|
|
#include <memory>
|
|
#include <string>
|
|
#include <vector>
|
|
#include "json.hpp"
|
|
#include "player.h"
|
|
#include "scenery.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);
|
|
};
|
|
|
|
static std::map<std::string, Direction> directions{{"N", N}, {"S", S}, {"E", E}, {"W", W}};
|
|
static std::map<Direction, std::string> directionChar{{N, "N"}, {S, "S"}, {E, "E"}, {W, "W"}};
|
|
|
|
class Room {
|
|
private:
|
|
int id;
|
|
std::string name;
|
|
std::string description;
|
|
Player player;
|
|
std::vector<Exit> exits;
|
|
std::vector<Scenery> scenery; /// ToDo: Replace with entity component system
|
|
|
|
public:
|
|
Room();
|
|
Room(int i, std::string n, std::string desc, std::vector<Exit> e, std::vector<Scenery> s);
|
|
Room(const Room &r);
|
|
|
|
void Enter(Player &p);
|
|
|
|
void PrintAvalibleExits();
|
|
void Print() const;
|
|
int GetID() const { return id; }
|
|
|
|
bool ValidDirection(Direction d);
|
|
|
|
inline bool operator==(const Room &rhs) const {
|
|
if (id == rhs.id) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
inline bool operator!=(const Room &rhs) const {
|
|
if (id != rhs.id) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
Room &operator=(Room rhs);
|
|
|
|
~Room();
|
|
|
|
friend void to_json(nlohmann::json &j, const 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);
|
|
}
|
|
};
|