Wip: working on add scenery
This commit is contained in:
+18
-7
@@ -24,15 +24,26 @@ protected:
|
||||
int roomIdItBelongsTo;
|
||||
|
||||
public:
|
||||
Object() = default;
|
||||
Object(const int i, std::string n, std::string desc, std::vector<std::string> k, const ObjectType o, const bool ct,
|
||||
const int rID) {
|
||||
id = i;
|
||||
name = std::move(n);
|
||||
description = std::move(desc);
|
||||
keywords = std::move(k);
|
||||
type = o;
|
||||
canTake = ct;
|
||||
roomIdItBelongsTo = rID;
|
||||
}
|
||||
virtual void Interact() = 0;
|
||||
std::string const GetName() { return name; }
|
||||
std::string const GetDescription() { return description; }
|
||||
std::string GetName() const { return name; }
|
||||
std::string GetDescription() const { return description; }
|
||||
|
||||
ObjectType const GetObjectType() { return type; }
|
||||
std::vector<std::string> const GetKeywords() { return keywords; }
|
||||
int GetId() { return id; }
|
||||
int GetRoomId() { return roomIdItBelongsTo; }
|
||||
bool CanTake() { return canTake; }
|
||||
ObjectType GetObjectType() const { return type; }
|
||||
std::vector<std::string> GetKeywords() const { return keywords; }
|
||||
int GetId() const { return id; }
|
||||
int GetRoomId() const { return roomIdItBelongsTo; }
|
||||
bool CanTake() const { return canTake; }
|
||||
virtual ~Object() = default;
|
||||
};
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include "json.hpp"
|
||||
#include "object.h"
|
||||
#include "scenery.h"
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
@@ -27,10 +27,11 @@ private:
|
||||
std::string name;
|
||||
std::string description;
|
||||
std::vector<Exit> exits;
|
||||
std::vector<Scenery> scenery;
|
||||
|
||||
public:
|
||||
Room();
|
||||
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, std::vector<Scenery> s);
|
||||
Room(const Room &r);
|
||||
|
||||
void PrintAvalibleExits();
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include <iostream>
|
||||
#include "object.h"
|
||||
|
||||
class Scenery : Object
|
||||
{
|
||||
private:
|
||||
bool containsItem;
|
||||
class Scenery : public Object {
|
||||
public:
|
||||
Scenery();
|
||||
Scenery(int i, std::string n, std::string desc, std::vector<std::string> k, ObjectType t, bool cT, int rID);
|
||||
void Examine();
|
||||
void Interact();
|
||||
~Scenery();
|
||||
void Interact() override;
|
||||
|
||||
|
||||
friend void from_json(const nlohmann::json &j, Scenery &s);
|
||||
friend void to_json(json &j, const Scenery &s);
|
||||
};
|
||||
|
||||
+6
-3
@@ -10,11 +10,12 @@ Room::Room() {
|
||||
exits.clear();
|
||||
}
|
||||
|
||||
Room::Room(int id, std::string n, std::string desc, std::vector<Exit> e) {
|
||||
Room::Room(int id, std::string n, std::string desc, std::vector<Exit> e, std::vector<Scenery> s) {
|
||||
id = id;
|
||||
name = n;
|
||||
description = desc;
|
||||
exits = e;
|
||||
scenery = s;
|
||||
}
|
||||
|
||||
Room::Room(const Room &r) {
|
||||
@@ -67,8 +68,10 @@ void from_json(const json &j, Room &r) {
|
||||
j.at("name").get_to(r.name);
|
||||
j.at("description").get_to(r.description);
|
||||
j.at("exits").get_to(r.exits);
|
||||
j.at("scenery").get_to(r.scenery);
|
||||
}
|
||||
|
||||
void to_json(nlohmann::json &j, const Room &r) {
|
||||
j = json{{"id", r.id}, {"name", r.name}, {"description", r.description}, {"exits", r.exits}};
|
||||
void to_json(json &j, const Room &r) {
|
||||
j = json{
|
||||
{"id", r.id}, {"name", r.name}, {"description", r.description}, {"exits", r.exits}, {"scenery", r.scenery}};
|
||||
}
|
||||
|
||||
+29
-18
@@ -1,29 +1,40 @@
|
||||
#include "scenery.h"
|
||||
|
||||
Scenery::Scenery()
|
||||
{
|
||||
Scenery::Scenery() {
|
||||
type = ObjectType::SCENERY;
|
||||
name = "Scenery";
|
||||
containsItem = false;
|
||||
}
|
||||
|
||||
void Scenery::Interact()
|
||||
{
|
||||
if (containsItem)
|
||||
{
|
||||
// Give Item
|
||||
}
|
||||
Examine();
|
||||
Scenery::Scenery(int i, std::string n, std::string desc, std::vector<std::string> k, ObjectType t, bool cT, int rID) {
|
||||
id = i;
|
||||
name = std::move(n);
|
||||
description = std::move(desc);
|
||||
keywords = std::move(k);
|
||||
type = t;
|
||||
canTake = cT;
|
||||
roomIdItBelongsTo = rID;
|
||||
}
|
||||
|
||||
void Scenery::Examine()
|
||||
{
|
||||
printf("%s\n", GetDescription().data());
|
||||
void Scenery::Interact() { Examine(); }
|
||||
|
||||
void Scenery::Examine() { printf("%s\n", GetDescription().data()); }
|
||||
|
||||
void from_json(const json &j, Scenery &s) {
|
||||
j.at("id").get_to(s.id);
|
||||
j.at("name").get_to(s.name);
|
||||
j.at("description").get_to(s.description);
|
||||
j.at("keywords").get_to(s.keywords);
|
||||
j.at("type").get_to(s.type);
|
||||
j.at("canTake").get_to(s.canTake);
|
||||
j.at("roomIdItBelongsTo").get_to(s.roomIdItBelongsTo);
|
||||
}
|
||||
|
||||
Scenery::~Scenery()
|
||||
{
|
||||
type = ObjectType::NONE;
|
||||
name = "";
|
||||
keywords.clear();
|
||||
void to_json(json &j, const Scenery &s) {
|
||||
j = json{{"id", s.id},
|
||||
{"name", s.name},
|
||||
{"description", s.description},
|
||||
{"keywords", s.keywords},
|
||||
{"type", s.type},
|
||||
{"canTake", s.canTake},
|
||||
{"roomIdItBelongsTo", s.roomIdItBelongsTo}};
|
||||
}
|
||||
|
||||
@@ -14,6 +14,10 @@
|
||||
"isLocked": false
|
||||
}
|
||||
],
|
||||
"scenery": [
|
||||
{
|
||||
}
|
||||
],
|
||||
"id": -8528,
|
||||
"name": "Test Room 1"
|
||||
},
|
||||
|
||||
@@ -3,13 +3,49 @@
|
||||
int main(int argc, char *argv[]) {
|
||||
Game game; // Calls default constructor which Initializes GAME
|
||||
|
||||
if (!game) {
|
||||
fs::path path("Resources/rooms.json");
|
||||
|
||||
std::vector<std::vector<Room>> rooms = {
|
||||
{
|
||||
{
|
||||
0,
|
||||
"Test Room 1",
|
||||
"First Test Room",
|
||||
{{0, S, false}, {1, E, false}},
|
||||
{{0, "Rock", "A Grey Rock", {"Rock"}, ObjectType::SCENERY, false, 0}},
|
||||
},
|
||||
{1,
|
||||
"Test Room 2",
|
||||
"A court yard",
|
||||
{{2, W, false}, {3, E, false}, {4, S, false}},
|
||||
{{1,
|
||||
"Tree",
|
||||
"A fine looking Tree stands in the courtyard",
|
||||
{"Tree"},
|
||||
ObjectType::SCENERY,
|
||||
false,
|
||||
1}}},
|
||||
|
||||
},
|
||||
{{3,
|
||||
"Test Room 3",
|
||||
"You can hear the sound of a waterfall nearby",
|
||||
{{5, N, false}, {6, E, false}},
|
||||
{{3, "Waterfall", "A fine waterfall on a cliff", {"Waterfall"}, ObjectType::SCENERY, false, 3}}}}};
|
||||
|
||||
nlohmann::json j(rooms);
|
||||
|
||||
std::fstream outFile(absolute(path), std::fstream::in | std::fstream::out | std::fstream::app);
|
||||
outFile << std::setw(4) << j << std::endl;
|
||||
|
||||
outFile.close();
|
||||
/*if (!game) {
|
||||
game.Init();
|
||||
Game::SetGameInstance(&game);
|
||||
}
|
||||
while (game.GetIsActive()) {
|
||||
game.Run();
|
||||
}
|
||||
}*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user