From 12fcde6a3b69a8ae69db7b0c3c4a25e4ca6e0acb Mon Sep 17 00:00:00 2001 From: Peisong Xiao Date: Thu, 18 Jul 2024 13:59:58 -0400 Subject: [PATCH] fixed issue with potion output, added extras menu for player race selection --- src/item.cc | 11 ++++++ src/item.h | 17 ++++++++++ src/menu.cc | 92 ++++++++++++++------------------------------------- src/menu.h | 2 +- src/pc.cc | 22 ++++++++---- src/potion.cc | 2 +- 6 files changed, 70 insertions(+), 76 deletions(-) create mode 100644 src/item.cc create mode 100644 src/item.h diff --git a/src/item.cc b/src/item.cc new file mode 100644 index 0000000..e4d7594 --- /dev/null +++ b/src/item.cc @@ -0,0 +1,11 @@ +#include "item.h" + +item::item(const position &pos): pos{pos} {} + +position item::get_pos() const { + return pos; +} + +void item::set_pos(const position &npos) { + pos = npos; +} diff --git a/src/item.h b/src/item.h new file mode 100644 index 0000000..2fb1477 --- /dev/null +++ b/src/item.h @@ -0,0 +1,17 @@ +#ifndef __ITEM_H__ +#define __ITEM_H__ + +#include "position.h" +#include "output.h" + +class item { +protected: + position pos; +public: + item(const position &pos); + position get_pos() const; + void set_pos(const position &npos); + virtual void print(output *out) const = 0; +}; + +#endif diff --git a/src/menu.cc b/src/menu.cc index edd18f4..5430d69 100644 --- a/src/menu.cc +++ b/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)); } diff --git a/src/menu.h b/src/menu.h index 24fdf3b..dad7de1 100644 --- a/src/menu.h +++ b/src/menu.h @@ -11,7 +11,7 @@ enum race : int; class menu final { private: const feature enabled_features; - position cur; + size_t curr; public: menu(const feature enabled_features); int run(input *in); diff --git a/src/pc.cc b/src/pc.cc index 572e23b..4952d55 100644 --- a/src/pc.cc +++ b/src/pc.cc @@ -7,6 +7,10 @@ #include "player/troll.h" #include "player/vampire.h" #include "player/t_800.h" +#include "player/assassin.h" +#include "player/monk.h" +#include "player/brawler.h" +#include "player/mr_goose.h" std::unique_ptr init_player(RNG *rng, const feature enabled_features, const enum race &r) { @@ -15,27 +19,33 @@ std::unique_ptr init_player(RNG *rng, switch (r) { case rgoblin: return make_unique(rng, enabled_features); - break; case rdrow: return make_unique(rng, enabled_features); - break; case rshade: return make_unique(rng, enabled_features); - break; case rtroll: return make_unique(rng, enabled_features); - break; case rvampire: return make_unique(rng, enabled_features); - break; case rt_800: return make_unique(rng, enabled_features); - break; + + case rassassin: + return make_unique(rng, enabled_features); + + case rmonk: + return make_unique(rng, enabled_features); + + case rbrawler: + return make_unique(rng, enabled_features); + + case rmr_goose: + return make_unique(rng, enabled_features); default: break; diff --git a/src/potion.cc b/src/potion.cc index 5cbabbe..5914954 100644 --- a/src/potion.cc +++ b/src/potion.cc @@ -14,7 +14,7 @@ int potion::get_duration() const { } void potion::print(output *out) const { - out->print_char(pos, 'P', COLOR_PAIR(COLOR_GREEN)); + out->print_char(this->get_pos(), 'P', COLOR_PAIR(COLOR_GREEN)); } size_t get_potion_at(const position &pos, const potion_list &plist) {