Inital Commit
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
#include "CommandParser.h"
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <sstream>
|
||||
|
||||
CommandParser::CommandParser() {}
|
||||
|
||||
bool CommandParser::AddCommand(std::string c, FUNCTION f) {
|
||||
commands.emplace(c, f);
|
||||
return true;
|
||||
}
|
||||
|
||||
void CommandParser::RemoveCommand(std::string c) { commands.erase(c); }
|
||||
|
||||
std::vector<std::string> CommandParser::Verb(std::stringstream &sentences) {
|
||||
std::string word;
|
||||
|
||||
std::vector<std::string> verbs = {};
|
||||
|
||||
while (sentences >> word) {
|
||||
if (std::find(Verbs.begin(), Verbs.end(), word) != Verbs.end()) {
|
||||
verbs.push_back(word);
|
||||
}
|
||||
}
|
||||
|
||||
if (verbs.empty()) {
|
||||
CommandUnrecognized();
|
||||
}
|
||||
|
||||
return verbs;
|
||||
}
|
||||
|
||||
std::vector<std::string> CommandParser::Noun(std::stringstream &sentences) {
|
||||
|
||||
std::string word;
|
||||
std::vector<std::string> nouns = {};
|
||||
|
||||
while (sentences >> word) {
|
||||
if (std::find(Nouns.begin(), Nouns.end(), word) != Nouns.end()) {
|
||||
nouns.push_back(word);
|
||||
}
|
||||
}
|
||||
return nouns;
|
||||
}
|
||||
|
||||
|
||||
int CommandParser::Parse() {
|
||||
std::string cmd;
|
||||
std::string word;
|
||||
|
||||
std::string noun;
|
||||
|
||||
std::vector<std::string> verbs;
|
||||
std::vector<std::string> nouns;
|
||||
|
||||
printf("Please Enter a command \n");
|
||||
printf("> ");
|
||||
getline(std::cin, cmd);
|
||||
cmd[0] = toupper(cmd[0]);
|
||||
std::stringstream c(cmd);
|
||||
|
||||
verbs = Verb(c);
|
||||
nouns = Noun(c);
|
||||
|
||||
for (const auto &verb: verbs) {
|
||||
commands[verb]("");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
#include "game.h"
|
||||
#include <fstream>
|
||||
|
||||
bool isActive;
|
||||
|
||||
Game::Game() {
|
||||
progress = 0;
|
||||
Init();
|
||||
}
|
||||
|
||||
bool Game::Init() {
|
||||
isActive = true;
|
||||
|
||||
rooms.resize(MAP_HEIGHT);
|
||||
for (int i = 0; i < MAP_HEIGHT; i++) {
|
||||
rooms[i].resize(MAP_WIDTH);
|
||||
}
|
||||
|
||||
// Read rooms into buffer
|
||||
stream.open(absolute(filePath));
|
||||
json = nlohmann::json::parse(stream);
|
||||
|
||||
// rooms = json.get<std::vector<std::vector<Room>>>();
|
||||
auto &roomData = json["rooms"];
|
||||
for (const auto &roomCol: rooms) {
|
||||
for (const auto &roomRow: roomCol) {
|
||||
// rooms.push_back(roomRow.get<Room>());
|
||||
}
|
||||
}
|
||||
|
||||
player.Init();
|
||||
parser = CommandParser();
|
||||
|
||||
FUNCTION exit = Exit;
|
||||
|
||||
parser.AddCommand("Exit", exit);
|
||||
|
||||
// Initalize Objects
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void Game::ChangeRoom(Direction dir) {}
|
||||
|
||||
void Game::Run() {
|
||||
while (isActive) {
|
||||
parser.Parse();
|
||||
// Process game logic in here
|
||||
}
|
||||
}
|
||||
|
||||
bool Game::Save() { return false; }
|
||||
|
||||
int Exit(std::string n) {
|
||||
isActive = false;
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
#include <iostream>
|
||||
|
||||
int main()
|
||||
{
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
#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(int damageType, float damage)
|
||||
{
|
||||
// Ouch
|
||||
}
|
||||
|
||||
float Player::GetHealth()
|
||||
{
|
||||
|
||||
return 0.0f;
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
#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
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
#include "room.h"
|
||||
|
||||
Room::Room() {
|
||||
id = -1;
|
||||
name = "Nothing";
|
||||
description = "There's nothing here";
|
||||
exits.clear();
|
||||
}
|
||||
|
||||
Room::Room(int id, std::string n, std::string desc, std::vector<Exit> e) {
|
||||
id = id;
|
||||
name = n;
|
||||
description = desc;
|
||||
exits = e;
|
||||
}
|
||||
|
||||
Room::Room(const Room &r) {
|
||||
id = r.id;
|
||||
name = r.name;
|
||||
description = r.description;
|
||||
exits = r.exits;
|
||||
}
|
||||
|
||||
Room::~Room() {
|
||||
id = -1;
|
||||
name = "";
|
||||
description = "";
|
||||
exits.clear();
|
||||
}
|
||||
|
||||
void Room::Print() const {
|
||||
printf("%s\n", name.c_str());
|
||||
printf("%s\n", description.c_str());
|
||||
}
|
||||
|
||||
|
||||
inline void from_json(const json &j, Exit &e) {
|
||||
j.at("exitID").get_to(e.exitID);
|
||||
j.at("dir").get_to(e.dir);
|
||||
j.at("isLocked").get_to(e.isLocked);
|
||||
}
|
||||
|
||||
inline void to_json(json &j, const Exit &e) {
|
||||
j = json{{"exitID", e.exitID}, {"dir", e.dir}, {"isLocked", e.isLocked}};
|
||||
}
|
||||
|
||||
|
||||
inline void from_json(const json &j, Room &r) {
|
||||
j.at("id").get_to(r.id);
|
||||
j.at("name").get_to(r.name);
|
||||
j.at("description").get_to(r.description);
|
||||
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}};
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
#include "scenery.h"
|
||||
|
||||
Scenery::Scenery()
|
||||
{
|
||||
type = ObjectType::SCENERY;
|
||||
name = "Scenery";
|
||||
containsItem = false;
|
||||
}
|
||||
|
||||
void Scenery::Interact()
|
||||
{
|
||||
if (containsItem)
|
||||
{
|
||||
// Give Item
|
||||
}
|
||||
Examine();
|
||||
}
|
||||
|
||||
void Scenery::Examine()
|
||||
{
|
||||
printf("%s\n", GetDescription());
|
||||
}
|
||||
|
||||
Scenery::~Scenery()
|
||||
{
|
||||
type = ObjectType::NONE;
|
||||
name = "";
|
||||
keywords.clear();
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
#include "object.h"
|
||||
Reference in New Issue
Block a user