From 0be377ab637aabd9c6b9b110a422d10da6b5d4ef Mon Sep 17 00:00:00 2001 From: Jan Grewe <jan@faked.org> Date: Sat, 3 Jun 2023 00:03:38 +0200 Subject: [PATCH] count games since reboot --- src/display.cpp | 11 ++++++----- src/display.h | 1 + src/gameoflife.cpp | 10 ++++++---- 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/src/display.cpp b/src/display.cpp index 84f5965..0c667f4 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -65,12 +65,13 @@ void fadeOutGame(int brightness) void showEvolutions(int ticks) { - char msg[15] = "Life has ended"; - char evolutions[17]; - sprintf(evolutions, "Evolutions: %d", ticks); + char msg_game[15]; + sprintf(msg_game, "Game %d ended", gameEra); + char msg_evo[12]; + sprintf(msg_evo, "Ticks: %d", ticks); indexedLayer.setFont(font3x5); - indexedLayer.drawString((matrix.getScreenWidth() / 2) - (strlen(msg) * 4) / 2, (matrix.getScreenHeight() / 2) - 2 - 5, 1, msg); - indexedLayer.drawString((matrix.getScreenWidth() / 2) - (strlen(evolutions) * 4) / 2, (matrix.getScreenHeight() / 2) + 2, 1, evolutions); + indexedLayer.drawString((matrix.getScreenWidth() / 2) - (strlen(msg_game) * 4) / 2, (matrix.getScreenHeight() / 2) - 2 - 5, 1, msg_game); + indexedLayer.drawString((matrix.getScreenWidth() / 2) - (strlen(msg_evo) * 4) / 2, (matrix.getScreenHeight() / 2) + 2, 1, msg_evo); indexedLayer.swapBuffers(); } diff --git a/src/display.h b/src/display.h index fa92192..ecb82e3 100644 --- a/src/display.h +++ b/src/display.h @@ -7,6 +7,7 @@ extern bool runGame; extern int brightnessPercent; +extern int gameEra; void setupDisplay(); void displayLoop(); diff --git a/src/gameoflife.cpp b/src/gameoflife.cpp index 89846b7..b455102 100644 --- a/src/gameoflife.cpp +++ b/src/gameoflife.cpp @@ -12,6 +12,7 @@ int arrayCopy[SCREEN_HEIGHT][SCREEN_WIDTH]; bool runGame = true; bool gameOver = false; +int gameEra = 0; int currentTick; int finalTicks; int cellsAliveNow; @@ -24,6 +25,7 @@ unsigned long currentMillis; void setupGameOfLife() { gameOver = false; + gameEra++; currentTick = 0; finalTicks = 0; cellsAliveBefore = 0; @@ -34,7 +36,7 @@ void setupGameOfLife() { addGlider(random(SCREEN_HEIGHT), random(SCREEN_WIDTH), g); } - logLine("Game of Life has been initialized"); + logLine("Initialized Game " + gameEra); } void createRandomMatrix(int (&a)[SCREEN_HEIGHT][SCREEN_WIDTH]) @@ -140,8 +142,8 @@ void gameLoop() if (currentTick % 2) { - char msg[61]; - sprintf(msg, "Cells alive now: %4d, before: %4d - No evolution since: %3d", cellsAliveNow, cellsAliveBefore, noEvolutionTicks); + char msg[66]; + sprintf(msg, "Tick: %4d, Cells now: %4d, before: %4d - No evolution since: %3d", currentTick, cellsAliveNow, cellsAliveBefore, noEvolutionTicks); logLine(msg); cellsAliveBefore = cellsAliveNow; } @@ -162,7 +164,7 @@ void gameLoop() currentMillis = millis(); showEndScreen(finalTicks); gameOver = true; - logLine("No Evolution detected anymore, ending Game of Life"); + logLine("Ending Game: " + gameEra); } } } -- GitLab