fixed issue with potion output, added extras menu for player race selection
This commit is contained in:
92
src/menu.cc
92
src/menu.cc
@ -3,30 +3,21 @@
|
||||
#include "constants.h"
|
||||
|
||||
const int NORMAL_CNT = 5;
|
||||
const int EXTRA_CNT = 5;
|
||||
const int EXTRA_CNT = 10;
|
||||
|
||||
const enum race RACES[EXTRA_CNT] = {
|
||||
rshade, rdrow, rgoblin, rvampire, rtroll
|
||||
rshade, rdrow, rgoblin, rvampire, rtroll,
|
||||
rmonk, rassassin, rmr_goose, rbrawler, rt_800
|
||||
};
|
||||
|
||||
const position RACE_POS[EXTRA_CNT] = {
|
||||
{4, 9}, {4, 11}, {4, 13}, {4, 15}, {4, 17}
|
||||
{4, 9}, {4, 11}, {4, 13}, {4, 15}, {4, 17},
|
||||
{41, 9}, {41, 11}, {41, 13}, {41, 15}, {41, 17}
|
||||
};
|
||||
|
||||
menu::menu(const feature enabled_features):
|
||||
enabled_features{enabled_features},
|
||||
cur{RACE_POS[0]} {}
|
||||
|
||||
const int UP_LIMIT = 9;
|
||||
const int DOWN_LIMIT = 17;
|
||||
const int LEFT_LIMIT = 4;
|
||||
const int RIGHT_LIMIT = 4;
|
||||
const int EXTRA_UP_LIMIT = 9;
|
||||
const int EXTRA_DOWN_LIMIT = 17;
|
||||
const int EXTRA_LEFT_LIMIT = 4;
|
||||
const int EXTRA_RIGHT_LIMIT = 4;
|
||||
const int X_INCRE = 37;
|
||||
const int Y_INCRE = 2;
|
||||
curr{0} {}
|
||||
|
||||
const char *NORMAL_SCREEN =
|
||||
"+-----------------------------------------------------------------------------+\
|
||||
@ -65,15 +56,15 @@ const char *EXTRA_SCREEN =
|
||||
+-----------------------------------------------------------------------------+\
|
||||
| Choose your race: |\
|
||||
+-----------------------------------------------------------------------------+\
|
||||
| Shade | |\
|
||||
| Shade | Monk |\
|
||||
+-----------------------------------------------------------------------------+\
|
||||
| Drow | |\
|
||||
| Drow | Assassin |\
|
||||
+-----------------------------------------------------------------------------+\
|
||||
| Goblin | |\
|
||||
| Goblin | Mr. Goose |\
|
||||
+-----------------------------------------------------------------------------+\
|
||||
| Vampire | |\
|
||||
| Vampire | Tavern Brawler |\
|
||||
+-----------------------------------------------------------------------------+\
|
||||
| Troll | |\
|
||||
| Troll | T-800 |\
|
||||
+-----------------------------------------------------------------------------+\
|
||||
| |\
|
||||
| |\
|
||||
@ -83,61 +74,25 @@ const char *EXTRA_SCREEN =
|
||||
+-----------------------------------------------------------------------------+";
|
||||
|
||||
int menu::run(input *in) {
|
||||
size_t limit = enabled_features & FEATURE_EXTRA_STUFF ?
|
||||
EXTRA_CNT : NORMAL_CNT;
|
||||
|
||||
auto cmd = in->get_command();
|
||||
|
||||
int up_limit = UP_LIMIT;
|
||||
int down_limit = DOWN_LIMIT;
|
||||
int left_limit = LEFT_LIMIT;
|
||||
int right_limit = RIGHT_LIMIT;
|
||||
|
||||
if (enabled_features & FEATURE_EXTRA_STUFF) {
|
||||
up_limit = EXTRA_UP_LIMIT;
|
||||
down_limit = EXTRA_DOWN_LIMIT;
|
||||
left_limit = EXTRA_LEFT_LIMIT;
|
||||
right_limit = EXTRA_RIGHT_LIMIT;
|
||||
}
|
||||
|
||||
switch (cmd) {
|
||||
case game_command::enter: {
|
||||
if (enabled_features & FEATURE_EXTRA_STUFF) {
|
||||
for (int i = 0; i < EXTRA_CNT; ++i)
|
||||
if (cur == RACE_POS[i])
|
||||
return RACES[i];
|
||||
|
||||
return -1;
|
||||
} else {
|
||||
for (int i = 0; i < NORMAL_CNT; ++i)
|
||||
if (cur == RACE_POS[i])
|
||||
return RACES[i];
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
case game_command::enter:
|
||||
return RACES[curr];
|
||||
|
||||
case move_north: {
|
||||
if (cur.y != up_limit)
|
||||
cur.y -= Y_INCRE;
|
||||
if (curr > 0)
|
||||
--curr;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case move_south: {
|
||||
if (cur.y != down_limit)
|
||||
cur.y += Y_INCRE;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case move_east: {
|
||||
if (cur.x != left_limit)
|
||||
cur.x -= X_INCRE;
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
case move_west: {
|
||||
if (cur.x != right_limit)
|
||||
cur.x += X_INCRE;
|
||||
if (curr < limit - 1)
|
||||
++curr;
|
||||
|
||||
break;
|
||||
}
|
||||
@ -161,9 +116,9 @@ const position SEED_POS = {1, 25};
|
||||
|
||||
void menu::print(output *out, const unsigned int seed) {
|
||||
if (enabled_features & FEATURE_EXTRA_STUFF)
|
||||
out->print_str({0, 0}, NORMAL_SCREEN);
|
||||
else
|
||||
out->print_str({0, 0}, EXTRA_SCREEN);
|
||||
else
|
||||
out->print_str({0, 0}, NORMAL_SCREEN);
|
||||
|
||||
if (enabled_features & FEATURE_NCURSES)
|
||||
out->print_str(MSG_POS, MSG_NCURSES, COLOR_PAIR(COLOR_YELLOW));
|
||||
@ -173,6 +128,7 @@ void menu::print(output *out, const unsigned int seed) {
|
||||
out->print_str(SEED_POS, "Seed: " + std::to_string(seed),
|
||||
COLOR_PAIR(COLOR_BLUE));
|
||||
|
||||
out->print_str(cur, "->", COLOR_PAIR(COLOR_GREEN));
|
||||
out->print_str(RACE_POS[curr], "->",
|
||||
COLOR_PAIR(COLOR_GREEN));
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user