added: list of arguments

edit: future framework of main
This commit is contained in:
2024-07-05 12:11:09 -04:00
parent 0201425cf1
commit 74de68cf0d
8 changed files with 60 additions and 26 deletions

2
src/arguments.cc Normal file
View File

@ -0,0 +1,2 @@
#include "arguments.h"

View File

@ -1,5 +1,6 @@
#ifndef __ARGUMENTS_H__
#define __ARGUMENTS_H__
#include <memory>
#include "log.h"
#include "cursor.h"
#include "display.h"
@ -7,6 +8,25 @@
#include "constants.h"
feature proc_args(int argc, char **argv, cursor &curse, input &in, logger &log);
/* Arguments
-n : Use ncurses for I/O
-r : Randomly generate maps
-m : Enabled a main menu + options
-c : Enemies chase the player (through doors and up stairs)
-i : Enable inventory
-t : Enable throw
-R : Enable revisiting levels
-S [seed] : Sets initial seed to seed
-s [file] : Enable saves
-L [file] : Enable logging to file
-I [file] : Reads commands from file. CANNOT BE USED WITH -n.
-O [file] : Outputs to file. CANNOT BE USED WITH -n.
*/
feature proc_args(int argc, char **argv,
std::unique_ptr<cursor> &curse,
std::unique_ptr<input> &in,
std::unique_ptr<display> &out,
std::unique_ptr<logger> &log);
#endif

View File

@ -12,6 +12,10 @@ game_command console_input::get_command() {
if (cmd == "q")
return game_command_terminate;
else if (cmd == "f")
return the_world;
else if (cmd == "r")
return game_restart;
else if (cmd == "u")
return (game_command)((tmp = get_direction(cmd)) ==
game_command_panic

View File

@ -1,6 +1,3 @@
// TODO: Consider moving the contents of this header to their relevant
// headers
#ifndef __CONSTANTS_H__
#define __CONSTANTS_H__
#include <vector>
@ -27,6 +24,7 @@ enum game_command {game_command_terminate = 0,
attack_northeast, attack_northwest,
attack_southeast, attack_southwest,
up_stairs, down_stairs,
the_world, game_restart,
game_command_pass, game_command_panic
};
@ -78,6 +76,8 @@ const feature FEATURE_THROW = 1 << 4;
const feature FEATURE_REVISIT = 1 << 5;
const feature FEATURE_LOG = 1 << 6;
const feature FEATURE_SAVE = 1 << 7;
const feature FEATURE_MENU = 1 << 8;
const feature FEATURE_PANIC = 1 << 29;
typedef std::vector<position> position_list;
typedef std::vector<direction> direction_list;

View File

@ -37,6 +37,12 @@ game_command curses_input::get_command() {
case '>':
return game_command::down_stairs;
case 'q':
return game_command_terminate;
case 'f':
return game_command::the_world;
case 'r':
return game_restart;
default:
return game_command_pass;

View File

@ -12,6 +12,10 @@ game_command file_input::get_command() {
if (cmd == "q")
return game_command_terminate;
else if (cmd == "f")
return the_world;
else if (cmd == "r")
return game_restart;
else if (cmd == "u")
return (game_command)((tmp = get_direction(cmd)) ==
game_command_panic

View File

@ -4,7 +4,7 @@
#include <vector>
#include "constants.h"
#include "display.h"
#include "cursor.h"
#include "input.h"
#include "rng.h"
#include "characters.h"
#include "map.h"
@ -12,14 +12,17 @@
class game final {
private:
display &out;
cursor &curse;
std::unique_ptr<input> &in;
std::unique_ptr<display> &out;
std::unique_ptr<logger> &log;
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(const feature enabled_features,
std::unique_ptr<input> &new_in,
std::unique_ptr<display> &new_out,
std::unique_ptr<logger> &new_log);
game_status run();
private:
int getcmd() const;

View File

@ -5,28 +5,23 @@
#include "arguments.h"
// The way things are designed to work:
// 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.
// to be filled...
int main(int argc, char **argv) {
logger log;
cursor curse;
input in(curse);
feature enabled_features = proc_args(argc, argv, curse, in, log);
display out(curse, enabled_features);
std::unique_ptr<cursor> curse;
std::unique_ptr<input> in;
std::unique_ptr<display> out;
std::unique_ptr<logger> log;
// binds display to the game
game game_proc(in, out, argc, argv);
feature enabled_features = proc_args(argc, argv, curse, in, out, log);
if(enabled_features & FEATURE_PANIC)
std::cerr<<"Wrong arguments you dumbass :)"<<std::endl;
game game_proc(enabled_features, in, out, log);
while (game_proc.run() != game_status::terminated)
out.render();
out->render();
return 0;
}