moving repo

This commit is contained in:
2024-07-05 00:46:02 -04:00
parent 325a1d1350
commit 7aed073fa6
11 changed files with 95 additions and 31 deletions

View File

@ -7,6 +7,6 @@
#include "constants.h"
feature proc_args(int argc, char ** argv, cursor &curse, input &in, logger& log);
feature proc_args(int argc, char **argv, cursor &curse, input &in, logger &log);
#endif

12
src/arguments.h.orig Normal file
View File

@ -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

View File

@ -30,6 +30,9 @@ enum game_command {game_command_terminate = 0,
game_command_pass, game_command_panic
};
// TODO: added a few colors for cursor
enum curse_color {};
enum stat_name {HP, ATK, DEF, hostile};
const int LAYER_CNT = 4; // TODO: update as you go

30
src/cursor.cc Normal file
View File

@ -0,0 +1,30 @@
#include "cursor.h"
#include "constants.h"
cursor::cursor() {
initscr();
}
cursor::~cursor() {
endwin();
}
int cursor::getcmd() const {
return getch();
}
void cursor::show() const {
refresh();
}
void cursor::print_char(const position &pos, const char ch) const {
}
bool check_terminal_size() {
int max_x;
int max_y;
getmaxyx(stdscr, max_y, max_x);
return max_x >= DISPLAY_WIDTH && max_y >= DISPLAY_HEIGHT;
}

View File

@ -20,9 +20,13 @@ public:
void show() const;
void print_char(const position &pos) const;
void print_char(const position &pos, const char ch) const;
void print_str(const position &head, const std::string str) const;
};
// IMPORTANT: this will fail when terminal size changes
// checks if terminal size fits the minimum requirements
bool check_terminal_size();
#endif

View File

@ -16,10 +16,10 @@
class display final {
private:
std::vector<std::string> contents;
cursor &curse;
cursor &curse;
public:
display();
display(cursor&new_curse,int argc, char **argv);
display(cursor &new_curse, int argc, char **argv);
void clear();
// use this instead of overloading for clarity

View File

@ -16,17 +16,17 @@
class display final {
private:
std::vector<std::string> 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
void print(std::ostream &out) const;
void print_line(const std::string &line, const int linenum);
void render() const ;
void render() const ;
// will override any character that was there
void print_position(const position &pos, const char ch);

View File

@ -13,16 +13,16 @@
class game final {
private:
display &out;
cursor &curse;
cursor &curse;
feature features;
std::unique_ptr<RNG> rng;
std::unique_ptr<character> player;
std::vector<level> levels;
public:
game(cursor&new_curse,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;
int getcmd() const;
};
#endif

View File

@ -4,6 +4,7 @@
#include <vector>
#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> rng;
std::unique_ptr<character> player;
std::vector<level> 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

View File

@ -13,18 +13,18 @@
// Notes:
// 1. game sends all output to display and gets all input from input
// 2. display either renders to file (console) or curse
// 3.
// 3.
int main(int argc, char **argv) {
logger log;
cursor curse;
input in(curse);
feature enabled_features = proc_args(argc,argv,curse,in,log);
logger log;
cursor curse;
input in(curse);
feature enabled_features = proc_args(argc, argv, curse, in, log);
display out(curse, enabled_features);
// binds display to the game
game game_proc(in, out, argc, argv);
while (game_proc.run() != game_status::terminated)
out.render();

View File

@ -1,21 +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);
while(g.run()!=game_status::terminated)
d.render();
return 0;
logger log;
cursor curse;
input in(curse);
feature enabled_features = proc_args(argc,argv,curse,in,log);
display out(curse, enabled_features);
// binds display to the game
game game_proc(in, out, argc, argv);
while (game_proc.run() != game_status::terminated)
out.render();
return 0;
}