-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Initial state. * Added NcursesInstance, NcursesView. * Added initial view requests. * Fixed MapRequest. * Added observer pattern behaviour between PathosInstance and View. * MapObject containing Char. * Initial Hostile abstract mob.
- Loading branch information
Showing
23 changed files
with
421 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pathos | ||
|
||
# Prerequisites | ||
*.d | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
SRCDIR = src | ||
CXXFLAGS = -std=c++17 -I${SRCDIR} -Wall -Wextra -Wpedantic -MMD -g | ||
SOURCES = $(shell find ${SRCDIR} -name '*.cc') | ||
OBJECTS = ${SOURCES:.cc=.o} | ||
DEPENDS = ${SOURCES:.cc=.d} | ||
EXEC = pathos | ||
|
||
${EXEC}: ${OBJECTS} | ||
${CXX} ${LDFLAGS} $^ -lncurses -o $@ | ||
|
||
-include ${DEPENDS} | ||
|
||
.PHONY: clean | ||
|
||
clean: | ||
rm -f ${OBJECTS} ${DEPENDS} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef PATHOS_OBSERVABLE | ||
#define PATHOS_OBSERVABLE | ||
|
||
#include <memory> | ||
#include <unordered_set> | ||
|
||
#include "abstract/Observer.h" | ||
|
||
namespace Pathos { | ||
|
||
template <typename Event> class Observable { | ||
std::unordered_set<Observer<Event> *> observers; | ||
|
||
public: | ||
virtual ~Observable() {} | ||
|
||
void addObserver(Observer<Event> *o) { observers.insert(o); } | ||
void removeObserver(Observer<Event> *o) { observers.erase(0); } | ||
void notify(Event *e) { | ||
for (auto *o : observers) | ||
o->process(e); | ||
} | ||
}; | ||
|
||
} // namespace Pathos | ||
|
||
#endif // PATHOS_OBSERVABLE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#ifndef PATHOS_OBSERVER | ||
#define PATHOS_OBSERVER | ||
|
||
namespace Pathos { | ||
|
||
template <typename Event> class Observer { | ||
public: | ||
virtual ~Observer() {} | ||
virtual void process(Event *e) = 0; | ||
}; | ||
|
||
} // namespace Pathos | ||
|
||
#endif // PATHOS_OBSERVER |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#include "core/PathosInstance.h" | ||
#include "abstract/Observable.h" | ||
#include "request/ViewRequest.h" | ||
#include "view/curses/MapView.h" | ||
#include "view/curses/NcursesInstance.h" | ||
|
||
using namespace Pathos; | ||
|
||
PathosInstance::PathosInstance() | ||
: curses{std::make_unique<NcursesInstance>()}, | ||
view{std::make_unique<MapView>(curses.get())} { | ||
Observable<ViewRequest>::addObserver(view.get()); | ||
} | ||
|
||
PathosInstance::~PathosInstance() {} | ||
|
||
void PathosInstance::run() {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef PATHOS_PATHOS_INSTANCE | ||
#define PATHOS_PATHOS_INSTANCE | ||
|
||
#include <memory> | ||
|
||
#include "abstract/Observable.h" | ||
#include "request/ViewRequest.h" | ||
|
||
namespace Pathos { | ||
|
||
class View; | ||
class NcursesInstance; | ||
|
||
class PathosInstance : public Observable<ViewRequest> { | ||
std::unique_ptr<NcursesInstance> curses; | ||
std::unique_ptr<View> view; | ||
|
||
public: | ||
PathosInstance(); | ||
~PathosInstance(); | ||
|
||
void run(); | ||
}; | ||
|
||
} // namespace Pathos | ||
|
||
#endif // PATHOS_PATHOS_INSTANCE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
#include "core/PathosInstance.h" | ||
|
||
int main() { return 0; } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef PATHOS_MAP | ||
#define PATHOS_MAP | ||
|
||
#include <vector> | ||
|
||
#include "map/MapObject.h" | ||
|
||
namespace Pathos { | ||
|
||
class Map { | ||
std::vector<std::vector<MapObject>> map; | ||
|
||
public: | ||
// TODO: | ||
Map(MapObject *m) {} | ||
virtual ~Map() {} | ||
}; | ||
|
||
} // namespace Pathos | ||
|
||
#endif // PATHOS_MAP |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#ifndef PATHOS_MAP_OBJECT | ||
#define PATHOS_MAP_OBJECT | ||
|
||
namespace Pathos { | ||
|
||
class MapObject { | ||
public: | ||
enum class Char { Lantern }; | ||
|
||
MapObject(Char c) : c{c} {} | ||
virtual ~MapObject() {} | ||
|
||
private: | ||
// Object's symbol in the view. | ||
Char c; | ||
}; | ||
|
||
} // namespace Pathos | ||
|
||
#endif // PATHOS_MAP_OBJECT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
#ifndef PATHOS_HOSTILE | ||
#define PATHOS_HOSTILE | ||
|
||
#include "map/MapObject.h" | ||
|
||
namespace Pathos { | ||
|
||
class Hostile : MapObject { | ||
public: | ||
Hostile() : MapObject(MapObject::Char::Lantern) {} | ||
virtual ~Hostile() {} | ||
}; | ||
|
||
} // namespace Pathos | ||
|
||
#endif // PATHOS_HOSTILE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include "request/MapRequest.h" | ||
#include "map/Map.h" | ||
#include "view/View.h" | ||
|
||
using namespace Pathos; | ||
|
||
// TODO: Complete after Map | ||
|
||
MapRequest::MapRequest(Map *m) {} | ||
|
||
MapRequest::~MapRequest() {} | ||
|
||
void MapRequest::beDrawnBy(View &view) const { view.draw(*this); } | ||
|
||
void MapRequest::convertMap(Map *m) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#ifndef PATHOS_MAP_REQUEST | ||
#define PATHOS_MAP_REQUEST | ||
|
||
#include <vector> | ||
|
||
#include "request/ViewRequest.h" | ||
|
||
namespace Pathos { | ||
|
||
class Map; | ||
|
||
struct MapRequest : public ViewRequest { | ||
std::vector<std::vector<char>> map; | ||
|
||
MapRequest(Map *m); | ||
~MapRequest(); | ||
|
||
void beDrawnBy(View &view) const override; | ||
|
||
private: | ||
void convertMap(Map *m); | ||
}; | ||
|
||
} // namespace Pathos | ||
|
||
#endif // PATHOS_MAP_REQUEST |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#include "request/NotificationRequest.h" | ||
#include "view/View.h" | ||
#include <string> | ||
#include <vector> | ||
|
||
using namespace Pathos; | ||
|
||
// TODO | ||
|
||
NotificationRequest::NotificationRequest(std::vector<std::string> &n) | ||
: notifications{n} {} | ||
|
||
NotificationRequest::~NotificationRequest() {} | ||
|
||
void NotificationRequest::beDrawnBy(View &view) const { view.draw(*this); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef PATHOS_NOTIFICATION_REQUEST | ||
#define PATHOS_NOTIFICATION_REQUEST | ||
|
||
#include <string> | ||
#include <vector> | ||
|
||
#include "request/ViewRequest.h" | ||
|
||
namespace Pathos { | ||
|
||
class View; | ||
|
||
struct NotificationRequest : public ViewRequest { | ||
std::vector<std::string> notifications; | ||
|
||
NotificationRequest(std::vector<std::string> &n); | ||
~NotificationRequest(); | ||
|
||
void beDrawnBy(View &view) const override; | ||
}; | ||
|
||
} // namespace Pathos | ||
|
||
#endif // PATHOS_NOTIFICATION_REQUEST |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
#ifndef PATHOS_VIEW_REQUEST | ||
#define PATHOS_VIEW_REQUEST | ||
|
||
namespace Pathos { | ||
|
||
class View; | ||
|
||
struct ViewRequest { | ||
virtual ~ViewRequest() {} | ||
virtual void beDrawnBy(View &view) const = 0; | ||
}; | ||
|
||
} // namespace Pathos | ||
|
||
#endif // PATHOS_VIEW_REQUEST |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#include "view/View.h" | ||
|
||
using namespace Pathos; | ||
|
||
void View::process(ViewRequest *req) { req->beDrawnBy(*this); } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
#ifndef PATHOS_VIEW | ||
#define PATHOS_VIEW | ||
|
||
#include "abstract/Observer.h" | ||
#include "request/ViewRequest.h" | ||
|
||
namespace Pathos { | ||
|
||
class MapRequest; | ||
class NotificationRequest; | ||
|
||
class View : public Observer<ViewRequest> { | ||
public: | ||
virtual ~View() {} | ||
|
||
void process(ViewRequest *req); | ||
|
||
virtual void draw(const MapRequest &req) = 0; | ||
virtual void draw(const NotificationRequest &req) = 0; | ||
}; | ||
|
||
} // namespace Pathos | ||
|
||
#endif // PATHOS_VIEW |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include "view/curses/MapView.h" | ||
#include "view/curses/NcursesInstance.h" | ||
#include "view/curses/NcursesView.h" | ||
|
||
using namespace Pathos; | ||
|
||
MapView::MapView(NcursesInstance *curses) | ||
: NcursesView(curses), height{NcursesView::getHeight()}, | ||
width{NcursesView::getWidth()} {} | ||
|
||
void MapView::draw(const MapRequest &req) {} | ||
|
||
void MapView::draw(const NotificationRequest &req) {} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#ifndef PATHOS_MAP_VIEW | ||
#define PATHOS_MAP_VIEW | ||
|
||
#include <vector> | ||
|
||
#include "view/curses/NcursesView.h" | ||
|
||
namespace Pathos { | ||
|
||
class MapRequest; | ||
class NotificationRequest; | ||
class NcursesInstance; | ||
|
||
class MapView : public NcursesView { | ||
std::vector<std::vector<char>> map; | ||
size_t height, width; | ||
|
||
public: | ||
MapView(NcursesInstance *curses); | ||
|
||
void draw(const MapRequest &req) override; | ||
void draw(const NotificationRequest &req) override; | ||
}; | ||
|
||
} // namespace Pathos | ||
|
||
#endif // PATHOS_MAP_VIEW |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include "view/curses/NcursesInstance.h" | ||
|
||
#include <ncurses.h> | ||
#include <string> | ||
|
||
using namespace Pathos; | ||
|
||
NcursesInstance::NcursesInstance() { | ||
initscr(); | ||
updateBounds(); | ||
raw(); | ||
} | ||
|
||
NcursesInstance::~NcursesInstance() { endwin(); } | ||
|
||
void NcursesInstance::move(size_t y, size_t x) { wmove(stdscr, y, x); } | ||
|
||
void NcursesInstance::movePrint(size_t y, size_t x, std::string s) { | ||
mvprintw(y, x, "%s", s.c_str()); | ||
} | ||
|
||
void NcursesInstance::print(std::string s) { printw("%s", s.c_str()); } | ||
|
||
void NcursesInstance::refresh() { refresh(); } | ||
|
||
void NcursesInstance::updateBounds() { getmaxyx(stdscr, height, width); } |
Oops, something went wrong.