added playtime functionality

This commit is contained in:
Thomas Fischer 2025-11-29 17:03:35 +01:00
parent c9dd4958c7
commit 3c7ae2a9b3

View File

@ -11,6 +11,12 @@ int main()
// Anzahl Spielzüge -> wie oft wurde ein Wuerfel geklickt // Anzahl Spielzüge -> wie oft wurde ein Wuerfel geklickt
int turnCount = 0; int turnCount = 0;
// Startzeit für timer berechnung -> aktueller Zeitpunkt in Sekunden
time_t startTime = time(nullptr);
// gespielte Zeit
int playTime = 0;
// Zufall initialisieren // Zufall initialisieren
srand(time(NULL)); srand(time(NULL));
@ -61,7 +67,11 @@ int main()
// ----------------------------------------------------------- // -----------------------------------------------------------
while (!WindowShouldClose()) while (!WindowShouldClose())
{ {
// die aktuelle Spielzeit berechnen
if (!gameWon)
{
playTime = static_cast<int>(time(nullptr) - startTime);
}
// Klick-Erkennung // Klick-Erkennung
if (!gameWon && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) if (!gameWon && IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
@ -134,11 +144,13 @@ int main()
{ {
DrawText("Congrats! You found all pairs!", 150, 260, 30, DARKBLUE); DrawText("Congrats! You found all pairs!", 150, 260, 30, DARKBLUE);
DrawText(("TurnCount: " + std::to_string(turnCount)).c_str(), 150, 290, 20, 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 else
{ {
DrawText("Flip 2 cubes - find matching pairs!", 10, 10, 20, DARKGRAY); 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(("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(); EndDrawing();
} }