From 3c7ae2a9b33b2cbe63757b5a6e365cdb7b7b0579 Mon Sep 17 00:00:00 2001 From: fischerth80683 Date: Sat, 29 Nov 2025 17:03:35 +0100 Subject: [PATCH] added playtime functionality --- src/main.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/main.cpp b/src/main.cpp index faf5523..c421f4e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,6 +11,12 @@ int main() // Anzahl Spielzüge -> wie oft wurde ein Wuerfel geklickt int turnCount = 0; + // Startzeit für timer berechnung -> aktueller Zeitpunkt in Sekunden + time_t startTime = time(nullptr); + + // gespielte Zeit + int playTime = 0; + // Zufall initialisieren srand(time(NULL)); @@ -61,7 +67,11 @@ int main() // ----------------------------------------------------------- while (!WindowShouldClose()) { - + // die aktuelle Spielzeit berechnen + if (!gameWon) + { + playTime = static_cast(time(nullptr) - startTime); + } // Klick-Erkennung if (!gameWon && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) @@ -134,11 +144,13 @@ int main() { DrawText("Congrats! You found all pairs!", 150, 260, 30, DARKBLUE); DrawText(("TurnCount: " + std::to_string(turnCount)).c_str(), 150, 290, 20, DARKBLUE); + DrawText(("Seconds played: " + std::to_string(playTime)).c_str(), 150, 310, 20, DARKBLUE); } else { DrawText("Flip 2 cubes - find matching pairs!", 10, 10, 20, DARKGRAY); DrawText(("TurnCount: " + std::to_string(turnCount)).c_str(), 10, 30, 20, DARKGRAY); //Zeichne TurnCount + DrawText(("PlayTime: " + std::to_string(playTime)).c_str(), 10, 50, 20, DARKGRAY); //Zeichne Playtime } EndDrawing(); }