Compare commits
No commits in common. "2335ecbb378a6271a8b07c959a89448408ffb3ef" and "fba740c35c96640dff1784aeb385c8454f3c8da8" have entirely different histories.
2335ecbb37
...
fba740c35c
@ -1,14 +0,0 @@
|
|||||||
#pragma once
|
|
||||||
#include <chrono>
|
|
||||||
|
|
||||||
class Timer {
|
|
||||||
public:
|
|
||||||
void start();
|
|
||||||
void stop();
|
|
||||||
long long elapsedMs() const;
|
|
||||||
|
|
||||||
private:
|
|
||||||
std::chrono::time_point<std::chrono::high_resolution_clock> startTime;
|
|
||||||
std::chrono::time_point<std::chrono::high_resolution_clock> endTime;
|
|
||||||
bool running = false;
|
|
||||||
};
|
|
||||||
@ -1,22 +0,0 @@
|
|||||||
#include "gametimer.h"
|
|
||||||
|
|
||||||
void Timer::start() {
|
|
||||||
running = true;
|
|
||||||
startTime = std::chrono::high_resolution_clock::now();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Timer::stop() {
|
|
||||||
running = false;
|
|
||||||
endTime = std::chrono::high_resolution_clock::now();
|
|
||||||
}
|
|
||||||
|
|
||||||
long long Timer::elapsedMs() const {
|
|
||||||
if (running) {
|
|
||||||
return std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
||||||
std::chrono::high_resolution_clock::now() - startTime
|
|
||||||
).count();
|
|
||||||
}
|
|
||||||
return std::chrono::duration_cast<std::chrono::milliseconds>(
|
|
||||||
endTime - startTime
|
|
||||||
).count();
|
|
||||||
}
|
|
||||||
32
src/main.cpp
32
src/main.cpp
@ -1,5 +1,4 @@
|
|||||||
#include "gamecube.h"
|
#include "gamecube.h"
|
||||||
#include "gametimer.h"
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
@ -15,9 +14,6 @@ int main()
|
|||||||
InitWindow(800, 600, "3D Memory Game with Matrix3D Library");
|
InitWindow(800, 600, "3D Memory Game with Matrix3D Library");
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
Timer timer;
|
|
||||||
timer.start();
|
|
||||||
|
|
||||||
Camera3D camera{};
|
Camera3D camera{};
|
||||||
camera.position = {6.0f, 6.0f, 6.0f};
|
camera.position = {6.0f, 6.0f, 6.0f};
|
||||||
camera.target = {0.0f, 0.0f, 0.0f};
|
camera.target = {0.0f, 0.0f, 0.0f};
|
||||||
@ -112,15 +108,9 @@ int main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Gewinnprüfung
|
// Gewinnprüfung
|
||||||
// Gewinnprüfung
|
if (!gameWon)
|
||||||
if (!gameWon) {
|
gameWon = std::all_of(cubes.begin(), cubes.end(), [](const gamecube &c){ return c.IsMatched(); });
|
||||||
gameWon = std::all_of(cubes.begin(), cubes.end(),
|
|
||||||
[](const gamecube &c){ return c.IsMatched(); });
|
|
||||||
|
|
||||||
if (gameWon)
|
|
||||||
timer.stop();
|
|
||||||
}
|
|
||||||
// <--- NEU
|
|
||||||
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
||||||
// Zeichnen
|
// Zeichnen
|
||||||
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
||||||
@ -138,24 +128,6 @@ int main()
|
|||||||
else
|
else
|
||||||
DrawText("Flip 2 cubes - find matching pairs!", 10, 10, 20, DARKGRAY);
|
DrawText("Flip 2 cubes - find matching pairs!", 10, 10, 20, DARKGRAY);
|
||||||
|
|
||||||
if (gameWon)
|
|
||||||
DrawText("Congrats! You found all pairs!", 150, 260, 30, DARKBLUE);
|
|
||||||
else
|
|
||||||
DrawText("Flip 2 cubes - find matching pairs!", 10, 10, 20, DARKGRAY);
|
|
||||||
|
|
||||||
|
|
||||||
if (!gameWon) {
|
|
||||||
long long elapsed = timer.elapsedMs() / 1000; // Sekunden
|
|
||||||
std::string timeStr = "Time: " + std::to_string(elapsed) + "s";
|
|
||||||
DrawText(timeStr.c_str(), 10, 40, 20, DARKGRAY);
|
|
||||||
} else {
|
|
||||||
// Optional: Endzeit anzeigen
|
|
||||||
long long totalTime = timer.elapsedMs() / 1000;
|
|
||||||
std::string endStr = "Finished in " + std::to_string(totalTime) + " seconds!";
|
|
||||||
DrawText(endStr.c_str(), 150, 300, 25, DARKBLUE);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user