diff --git a/src/cc3k.cc b/src/cc3k.cc index 495dd73..54e5466 100644 --- a/src/cc3k.cc +++ b/src/cc3k.cc @@ -24,7 +24,7 @@ game_status CC3K::run() { } if (tmp != -1) { - curr_menu = nullptr; + curr_menu.reset(); curr_game = std::make_unique((race)tmp, enabled_features, in, out, rng); @@ -45,7 +45,7 @@ game_status CC3K::run() { gresult = curr_game->run(); if (gresult.status == restart) { - curr_game = nullptr; + curr_game.reset(); curr_menu = std::make_unique(enabled_features); out->clear(); curr_menu->print(out, rng->get_init_seed()); @@ -70,7 +70,18 @@ game_status CC3K::run() { case dead: case won: case escaped: + curr_game.reset(); gresult.run(in); + + if (gresult.status == restart) { + curr_menu = std::make_unique(enabled_features); + out->clear(); + curr_menu->print(out, rng->get_init_seed()); + out->render(); + gresult.status = main_menu; + return main_menu; + } + return terminated; default: diff --git a/src/characters.cc b/src/characters.cc index cb1be92..7a842ea 100644 --- a/src/characters.cc +++ b/src/characters.cc @@ -37,7 +37,7 @@ void character::insert_effect(std::unique_ptr effect) { effects.push_back(std::move(effect)); for (int i = effects.size() - 1; i > 0 && - effect->get_priority() < effects[i - 1]->get_priority(); --i) + effects[i]->get_priority() < effects[i - 1]->get_priority(); --i) std::swap(effects[i], effects[i - 1]); } diff --git a/src/cursor.cc b/src/cursor.cc index c010ca6..9a299dc 100644 --- a/src/cursor.cc +++ b/src/cursor.cc @@ -31,7 +31,6 @@ void cursor::show() const { } void cursor::clear() const { - // ::clear(); } void cursor::print_char(const position &pos, const char ch, diff --git a/src/output/curses_output.cc b/src/output/curses_output.cc index bee3adf..4effa37 100644 --- a/src/output/curses_output.cc +++ b/src/output/curses_output.cc @@ -9,8 +9,10 @@ void curses_output::render() { curse->show(); } +std::string BLANK(DISPLAY_BUFFER_SIZE, ' '); + void curses_output::clear() { - curse->clear(); + print_str({0, 0}, BLANK, A_NORMAL); } void curses_output::print_char(const position &pos, const char ch, diff --git a/src/result.cc b/src/result.cc index f60245b..764439f 100644 --- a/src/result.cc +++ b/src/result.cc @@ -1,5 +1,6 @@ #include "result.h" +#include "constants.h" const char *WIN_SCREEN = "+-----------------------------------------------------------------------------+\ @@ -23,23 +24,113 @@ const char *WIN_SCREEN = | |\ | |\ | |\ +| Winner! |\ | |\ | |\ -| |\ -| > |\ -| |\ +| > |\ | |\ | |\ +| Press 'r' to restart and any other key to quit. |\ | |\ +-----------------------------------------------------------------------------+"; -const position &MSG_START = {11, 24}; +const char *ESC_SCREEN = + "+-----------------------------------------------------------------------------+\ +| |\ +| |\ +| |\ +| __ |\ +| _/o \\ |\ +| /_ | | / |\ +| W\\ / |//// |\ +| \\ \\ __________||//|/ |\ +| \\ \\/ /|/-//- |\ +| | ----- // -- |\ +| | ----- /- |\ +| | ----- / |\ +| \\ / |\ +| \\_/ \\___/ |\ +| \\ // |\ +| ||| |\ +| ||| |\ +| Z_>> |\ +| |\ +| |\ +| |\ +| Chicken! |\ +| |\ +| > |\ +| |\ +| |\ +| Press 'r' to restart and any other key to quit. |\ +| |\ ++-----------------------------------------------------------------------------+"; + + +const char *LOSE_SCREEN = + "+-----------------------------------------------------------------------------+\ +| |\ +| _ /) |\ +| / )/ ) |\ +| |/)\\) |\ +| /\\_ |\ +| \\__|= |\ +| ( ) |\ +| __)(__ |\ +| _____/ \\\\_____ |\ +| | || |\ +| | _ ___ _ || |\ +| | | \\ | | \\ || |\ +| | | | | | | || |\ +| | |_/ | |_/ || |\ +| | | \\ | | || |\ +| | | \\ | | || |\ +| | | \\. _|_. | . || |\ +| | || |\ +| * | * ** * ** |** ** |\ +| \\))...../.,(//,,..,,\\||(,,.,\\\\,.((// |\ +| |\ +| Loser! |\ +| |\ +| > |\ +| |\ +| |\ +| Press 'r' to restart and any other key to quit. |\ +| |\ ++-----------------------------------------------------------------------------+"; + +const position &MSG_START = {4, 24}; +const int MAX_MSG_LEN = 71; +const std::string DOTS = "..."; void game_result::run(input *in) { - in->get_command(); + if (in->get_command() == game_restart) + status = restart; } void game_result::print(output *out) { - out->print_str({0, 0}, WIN_SCREEN); - out->print_str(MSG_START, msg, COLOR_PAIR(COLOR_YELLOW)); + if (msg.length() > MAX_MSG_LEN) { + msg.resize(MAX_MSG_LEN - DOTS.length()); + msg += DOTS; + } + + switch (status) { + case won: + out->print_str({0, 0}, WIN_SCREEN); + out->print_str(MSG_START, msg, COLOR_PAIR(COLOR_YELLOW)); + break; + + case escaped: + out->print_str({0, 0}, ESC_SCREEN); + out->print_str(MSG_START, msg, COLOR_PAIR(COLOR_GREEN)); + break; + + case dead: + out->print_str({0, 0}, LOSE_SCREEN); + out->print_str(MSG_START, msg, COLOR_PAIR(COLOR_RED)); + break; + + default: + break; + } }