Skip to content

Commit

Permalink
fix: Game: added drawEndGameLoopGraphics
Browse files Browse the repository at this point in the history
- drawEndGameLoopGraphics() is a helper function that draws items needed
for game-over screen.
  • Loading branch information
tcoyvwac committed Oct 13, 2019
1 parent d798895 commit fc2369a
Showing 1 changed file with 26 additions and 8 deletions.
34 changes: 26 additions & 8 deletions src/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -297,23 +297,41 @@ make_end_screen_display_data(gamestatus_t world_gamestatus) {
return esdd;
};

void endlessGameLoop() {
std::string drawEndGameLoopGraphics(gamestatus_t world_gamestatus) {
// Graphical Output has a specific ordering...
using namespace Graphics;
using namespace Gameboard::Graphics;
std::ostringstream str_os;
// 1. Clear screen
clearScreen();

// 2. Draw Game Title Art
DrawAlways(str_os, AsciiArt2048);

// 3. Draw Scoreboard of ending current game session
const auto scdd = make_scoreboard_display_data();
DrawAlways(str_os, DataSuppliment(scdd, GameScoreBoardOverlay));

// 4 Draw snapshot of ending 2048 session's gameboard
DrawAlways(str_os, DataSuppliment(gamePlayBoard, GameBoardTextOutput));

// 5. Draw "You win!" or "You Lose" prompt, only if not in endless mode.
const auto esdd = make_end_screen_display_data(world_gamestatus);
DrawAlways(str_os, DataSuppliment(esdd, GameEndScreenOverlay));

return str_os.str();
}

void endlessGameLoop() {
auto loop_again{true};
gamestatus_t world_gamestatus{};

while (loop_again) {
std::tie(loop_again, world_gamestatus) = soloGameLoop(world_gamestatus);
}

const auto scdd = make_scoreboard_display_data();
clearScreen();
DrawAlways(std::cout, AsciiArt2048);
DrawAlways(std::cout, DataSuppliment(scdd, GameScoreBoardOverlay));
DrawAlways(std::cout, DataSuppliment(gamePlayBoard, GameBoardTextOutput));
const auto esdd = make_end_screen_display_data(world_gamestatus);
DrawAlways(std::cout, DataSuppliment(esdd, GameEndScreenOverlay));
DrawAlways(std::cout,
DataSuppliment(world_gamestatus, drawEndGameLoopGraphics));
}

void saveEndGameStats(Scoreboard::Score finalscore) {
Expand Down

0 comments on commit fc2369a

Please sign in to comment.