#include "menu.h" #include "constants.h" const int NORMAL_CNT = 5; const int EXTRA_CNT = 5; const enum race RACES[EXTRA_CNT] = { rshade, rdrow, rgoblin, rvampire, rtroll }; const position RACE_POS[EXTRA_CNT] = { {4, 9}, {4, 11}, {4, 13}, {4, 15}, {4, 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; const char *NORMAL_SCREEN = "+-----------------------------------------------------------------------------+\ | ____ ____ _____ _ __ |\ | / _\\/ _\\\\__ \\/ |/ / |\ | | / | / / || / |\ | | \\_ | \\_ _\\ || \\ |\ | \\____/\\____//____/\\_|\\_\\ |\ +-----------------------------------------------------------------------------+\ | Choose your race | |\ +-----------------------------------------------------------------------------+\ | Shade | |\ +-----------------------------------------------------------------------------+\ | Drow | |\ +-----------------------------------------------------------------------------+\ | Goblin | |\ +-----------------------------------------------------------------------------+\ | Vampire | |\ +-----------------------------------------------------------------------------+\ | Troll | |\ +-----------------------------------------------------------------------------+\ | |\ | |\ | |\ | |\ | |\ +-----------------------------------------------------------------------------+"; const char *EXTRA_SCREEN = "+-----------------------------------------------------------------------------+\ | ____ ____ _____ _ __ |\ | / _\\/ _\\\\__ \\/ |/ / |\ | | / | / / || / |\ | | \\_ | \\_ _\\ || \\ |\ | \\____/\\____//____/\\_|\\_\\ |\ +-----------------------------------------------------------------------------+\ | Choose your race | |\ +-----------------------------------------------------------------------------+\ | Shade | |\ +-----------------------------------------------------------------------------+\ | Drow | |\ +-----------------------------------------------------------------------------+\ | Goblin | |\ +-----------------------------------------------------------------------------+\ | Vampire | |\ +-----------------------------------------------------------------------------+\ | Troll | |\ +-----------------------------------------------------------------------------+\ | |\ | |\ | |\ | |\ | |\ +-----------------------------------------------------------------------------+"; int menu::run(input *in) { 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 move_north: { if (cur.y != up_limit) cur.y -= Y_INCRE; 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; break; } case game_command_terminate: return -2; default: break; } return -1; } void menu::print(display *out) { if (enabled_features & FEATURE_EXTRA_STUFF) out->print_str({0, 0}, NORMAL_SCREEN); else out->print_str({0, 0}, EXTRA_SCREEN); out->print_str(cur, "->", COLOR_PAIR(COLOR_BLUE)); }