From f954d09a29e1b05bb821ced6fe75e36a18acc3bf Mon Sep 17 00:00:00 2001 From: Sladoje Date: Mon, 1 Dec 2025 11:58:51 +0100 Subject: [PATCH] added timer in main.cpp --- src/main.cpp | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 287251d..38190c8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -9,6 +9,10 @@ int main() { // Zufall initialisieren srand(time(NULL)); + double startTime = 0.0; + double endTime = 0.0; + bool timerStarted = false; + // Fenster und Kamera InitWindow(800, 600, "3D Memory Game with Matrix3D Library"); @@ -57,6 +61,11 @@ int main() // ----------------------------------------------------------- while (!WindowShouldClose()) { + if (!timerStarted) + { + startTime = GetTime(); + timerStarted = true; + } // Klick-Erkennung if (!gameWon && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { @@ -109,8 +118,13 @@ int main() // Gewinnprüfung if (!gameWon) + { gameWon = std::all_of(cubes.begin(), cubes.end(), [](const gamecube &c){ return c.IsMatched(); }); - + if (gameWon) + { + endTime = GetTime() - startTime; + } + } // ----------------------------------------------------------- // Zeichnen // ----------------------------------------------------------- @@ -124,10 +138,20 @@ int main() EndMode3D(); if (gameWon) + { DrawText("Congrats! You found all pairs!", 150, 260, 30, DARKBLUE); - else - DrawText("Flip 2 cubes - find matching pairs!", 10, 10, 20, DARKGRAY); + char buffer[64]; + sprintf(buffer, "Cleared in %.2f seconds", endTime); + DrawText(buffer, 150, 300, 28, DARKGREEN); + } + else + { + DrawText("Flip 2 cubes - find matching pairs!", 10, 10, 20, DARKGRAY); + char liveBuf[64]; + sprintf(liveBuf, "Time: %.2f", GetTime() - startTime); + DrawText(liveBuf, 10, 40, 20, DARKGRAY); + } EndDrawing(); }