From c67dbcc62afd729af3d620b68fb85da044869473 Mon Sep 17 00:00:00 2001 From: Peisong Xiao Date: Thu, 4 Jul 2024 19:58:19 -0400 Subject: [PATCH] moving repo --- src/arguments.h | 12 ++++++++++++ src/cursor.h | 18 +++++++++++++++++- src/display.h | 4 ++-- src/game.h | 8 ++++++-- src/input.h | 11 +++++++++++ src/log.h | 2 +- src/main.cc | 33 +++++++++++++++++++++------------ 7 files changed, 70 insertions(+), 18 deletions(-) create mode 100644 src/arguments.h create mode 100644 src/input.h diff --git a/src/arguments.h b/src/arguments.h new file mode 100644 index 0000000..7b72410 --- /dev/null +++ b/src/arguments.h @@ -0,0 +1,12 @@ +#ifndef __ARGUMENTS_H__ +#define __ARGUMENTS_H__ +#include "log.h" +#include "cursor.h" +#include "display.h" +#include "input.h" + +#include "constants.h" + +feature proc_args(int argc, char ** argv, cursor &curse, input &in, logger& log); + +#endif diff --git a/src/cursor.h b/src/cursor.h index bf04ec4..a43b650 100644 --- a/src/cursor.h +++ b/src/cursor.h @@ -1,7 +1,23 @@ #ifndef __CURSOR_H__ #define __CURSOR_H__ +#include #include +#include "position.h" -class cursor; +class cursor{ +private: +public: + cursor(); + + ~cursor(); + + int getcmd() const; + + void show() const; + + void print_char(const position &pos) const; + + void print_str(const position &head, const std::string str) const; +}; #endif diff --git a/src/display.h b/src/display.h index fe49468..2f5fce3 100644 --- a/src/display.h +++ b/src/display.h @@ -16,10 +16,10 @@ class display final { private: std::vector contents; - cursor &curs; + cursor &curse; public: display(); - display(cursor &s); + display(cursor&new_curse,int argc, char **argv); void clear(); // use this instead of overloading for clarity diff --git a/src/game.h b/src/game.h index d7854f4..a227c34 100644 --- a/src/game.h +++ b/src/game.h @@ -4,6 +4,7 @@ #include #include "constants.h" #include "display.h" +#include "cursor.h" #include "rng.h" #include "characters.h" #include "map.h" @@ -11,14 +12,17 @@ class game final { private: - display &d; + display &out; + cursor &curse; feature features; std::unique_ptr rng; std::unique_ptr player; std::vector levels; public: - game(display &new_display, int argc, char **argv); + game(cursor&new_curse,display &new_display, int argc, char **argv); game_status run(); +private: + int getcmd() const; }; #endif diff --git a/src/input.h b/src/input.h new file mode 100644 index 0000000..4a50f77 --- /dev/null +++ b/src/input.h @@ -0,0 +1,11 @@ +#ifndef __INPUT_H__ +#define __INPUT_H__ +#include +#include "cursor.h" + +class input{ + public: + input(cursor &new_curse); +}; + +#endif diff --git a/src/log.h b/src/log.h index a5eede2..f55bda9 100644 --- a/src/log.h +++ b/src/log.h @@ -1,6 +1,6 @@ #ifndef __LOG_H__ #define __LOG_H__ -class log; +class logger; #endif diff --git a/src/main.cc b/src/main.cc index b05715f..365285d 100644 --- a/src/main.cc +++ b/src/main.cc @@ -1,23 +1,32 @@ #include "game.h" #include "cursor.h" #include "display.h" +#include "input.h" +#include "arguments.h" // The way things are designed to work: -// 1. initializes a new ncurses wrapper c -// Note: This is done the first thing in main because ncurses -// are from procedural programming and may break otherwise (unlikely) -// 2. bind c to a new display c (that handles all output) -// 3. bind d to g for graphics +// 1. out initializes a new display (this is a virtual one) +// 2. out initializes output based on given args +// This is when curse is initialized (curse.init()) +// 3. game_proc binds output to out and curses (if needed) + +// Notes: +// 1. game sends all output to display and gets all input from input +// 2. display either renders to file (console) or curse +// 3. int main(int argc, char **argv) { - cursor c; - // binds a ncurses cursor to display - display d(c); - // binds display to the game - game g(d, argc, argv); + logger log; + cursor curse; + input in(curse); + feature enabled_features = proc_args(argc,argv,curse,in,log); + display out(curse, enabled_features); - while (g.run() != game_status::terminated) - d.render(); + // binds display to the game + game game_proc(in, out, argc, argv); + + while (game_proc.run() != game_status::terminated) + out.render(); return 0; }