added timer in main.cpp
This commit is contained in:
parent
f79648ea47
commit
f954d09a29
30
src/main.cpp
30
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();
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user