added: list of arguments
edit: future framework of main
This commit is contained in:
2
src/arguments.cc
Normal file
2
src/arguments.cc
Normal file
@ -0,0 +1,2 @@
|
||||
#include "arguments.h"
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
|
@ -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
|
||||
|
13
src/game.h
13
src/game.h
@ -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> ∈
|
||||
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;
|
||||
|
29
src/main.cc
29
src/main.cc
@ -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)
|
||||
// to be filled...
|
||||
|
||||
// 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) {
|
||||
std::unique_ptr<cursor> curse;
|
||||
std::unique_ptr<input> in;
|
||||
std::unique_ptr<display> out;
|
||||
std::unique_ptr<logger> log;
|
||||
|
||||
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);
|
||||
feature enabled_features = proc_args(argc, argv, curse, in, out, log);
|
||||
|
||||
// binds display to the game
|
||||
game game_proc(in, out, argc, argv);
|
||||
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;
|
||||
}
|
||||
|
Reference in New Issue
Block a user