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__
|
#ifndef __ARGUMENTS_H__
|
||||||
#define __ARGUMENTS_H__
|
#define __ARGUMENTS_H__
|
||||||
|
#include <memory>
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "cursor.h"
|
#include "cursor.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
@ -7,6 +8,25 @@
|
|||||||
|
|
||||||
#include "constants.h"
|
#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
|
#endif
|
||||||
|
@ -12,6 +12,10 @@ game_command console_input::get_command() {
|
|||||||
|
|
||||||
if (cmd == "q")
|
if (cmd == "q")
|
||||||
return game_command_terminate;
|
return game_command_terminate;
|
||||||
|
else if (cmd == "f")
|
||||||
|
return the_world;
|
||||||
|
else if (cmd == "r")
|
||||||
|
return game_restart;
|
||||||
else if (cmd == "u")
|
else if (cmd == "u")
|
||||||
return (game_command)((tmp = get_direction(cmd)) ==
|
return (game_command)((tmp = get_direction(cmd)) ==
|
||||||
game_command_panic
|
game_command_panic
|
||||||
|
@ -1,6 +1,3 @@
|
|||||||
// TODO: Consider moving the contents of this header to their relevant
|
|
||||||
// headers
|
|
||||||
|
|
||||||
#ifndef __CONSTANTS_H__
|
#ifndef __CONSTANTS_H__
|
||||||
#define __CONSTANTS_H__
|
#define __CONSTANTS_H__
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -27,6 +24,7 @@ enum game_command {game_command_terminate = 0,
|
|||||||
attack_northeast, attack_northwest,
|
attack_northeast, attack_northwest,
|
||||||
attack_southeast, attack_southwest,
|
attack_southeast, attack_southwest,
|
||||||
up_stairs, down_stairs,
|
up_stairs, down_stairs,
|
||||||
|
the_world, game_restart,
|
||||||
game_command_pass, game_command_panic
|
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_REVISIT = 1 << 5;
|
||||||
const feature FEATURE_LOG = 1 << 6;
|
const feature FEATURE_LOG = 1 << 6;
|
||||||
const feature FEATURE_SAVE = 1 << 7;
|
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<position> position_list;
|
||||||
typedef std::vector<direction> direction_list;
|
typedef std::vector<direction> direction_list;
|
||||||
|
@ -37,6 +37,12 @@ game_command curses_input::get_command() {
|
|||||||
|
|
||||||
case '>':
|
case '>':
|
||||||
return game_command::down_stairs;
|
return game_command::down_stairs;
|
||||||
|
case 'q':
|
||||||
|
return game_command_terminate;
|
||||||
|
case 'f':
|
||||||
|
return game_command::the_world;
|
||||||
|
case 'r':
|
||||||
|
return game_restart;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
return game_command_pass;
|
return game_command_pass;
|
||||||
|
@ -12,6 +12,10 @@ game_command file_input::get_command() {
|
|||||||
|
|
||||||
if (cmd == "q")
|
if (cmd == "q")
|
||||||
return game_command_terminate;
|
return game_command_terminate;
|
||||||
|
else if (cmd == "f")
|
||||||
|
return the_world;
|
||||||
|
else if (cmd == "r")
|
||||||
|
return game_restart;
|
||||||
else if (cmd == "u")
|
else if (cmd == "u")
|
||||||
return (game_command)((tmp = get_direction(cmd)) ==
|
return (game_command)((tmp = get_direction(cmd)) ==
|
||||||
game_command_panic
|
game_command_panic
|
||||||
|
13
src/game.h
13
src/game.h
@ -4,7 +4,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include "constants.h"
|
#include "constants.h"
|
||||||
#include "display.h"
|
#include "display.h"
|
||||||
#include "cursor.h"
|
#include "input.h"
|
||||||
#include "rng.h"
|
#include "rng.h"
|
||||||
#include "characters.h"
|
#include "characters.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
@ -12,14 +12,17 @@
|
|||||||
|
|
||||||
class game final {
|
class game final {
|
||||||
private:
|
private:
|
||||||
display &out;
|
std::unique_ptr<input> ∈
|
||||||
cursor &curse;
|
std::unique_ptr<display> &out;
|
||||||
|
std::unique_ptr<logger> &log;
|
||||||
feature features;
|
feature features;
|
||||||
std::unique_ptr<RNG> rng;
|
std::unique_ptr<RNG> rng;
|
||||||
std::unique_ptr<character> player;
|
std::unique_ptr<character> player;
|
||||||
std::vector<level> levels;
|
|
||||||
public:
|
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();
|
game_status run();
|
||||||
private:
|
private:
|
||||||
int getcmd() const;
|
int getcmd() const;
|
||||||
|
29
src/main.cc
29
src/main.cc
@ -5,28 +5,23 @@
|
|||||||
#include "arguments.h"
|
#include "arguments.h"
|
||||||
|
|
||||||
// The way things are designed to work:
|
// The way things are designed to work:
|
||||||
// 1. out initializes a new display (this is a virtual one)
|
// to be filled...
|
||||||
// 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:
|
int main(int argc, char **argv) {
|
||||||
// 1. game sends all output to display and gets all input from input
|
std::unique_ptr<cursor> curse;
|
||||||
// 2. display either renders to file (console) or curse
|
std::unique_ptr<input> in;
|
||||||
// 3.
|
std::unique_ptr<display> out;
|
||||||
|
std::unique_ptr<logger> log;
|
||||||
|
|
||||||
int main(int argc, char **argv) {
|
feature enabled_features = proc_args(argc, argv, curse, in, out, 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
|
if(enabled_features & FEATURE_PANIC)
|
||||||
game game_proc(in, out, argc, argv);
|
std::cerr<<"Wrong arguments you dumbass :)"<<std::endl;
|
||||||
|
|
||||||
|
game game_proc(enabled_features, in, out, log);
|
||||||
|
|
||||||
while (game_proc.run() != game_status::terminated)
|
while (game_proc.run() != game_status::terminated)
|
||||||
out.render();
|
out->render();
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user