diff --git a/.idea/.gitignore b/.idea/.gitignore deleted file mode 100644 index 13566b8..0000000 --- a/.idea/.gitignore +++ /dev/null @@ -1,8 +0,0 @@ -# Default ignored files -/shelf/ -/workspace.xml -# Editor-based HTTP Client requests -/httpRequests/ -# Datasource local storage ignored files -/dataSources/ -/dataSources.local.xml diff --git a/.idea/.name b/.idea/.name deleted file mode 100644 index ed8527b..0000000 --- a/.idea/.name +++ /dev/null @@ -1 +0,0 @@ -Prog3B \ No newline at end of file diff --git a/.idea/Programmieren_3b.iml b/.idea/Programmieren_3b.iml deleted file mode 100644 index f08604b..0000000 --- a/.idea/Programmieren_3b.iml +++ /dev/null @@ -1,2 +0,0 @@ - - \ No newline at end of file diff --git a/.idea/editor.xml b/.idea/editor.xml deleted file mode 100644 index b0d69ef..0000000 --- a/.idea/editor.xml +++ /dev/null @@ -1,483 +0,0 @@ - - - - - \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml deleted file mode 100644 index 0b76fe5..0000000 --- a/.idea/misc.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml deleted file mode 100644 index 1e3bc79..0000000 --- a/.idea/modules.xml +++ /dev/null @@ -1,8 +0,0 @@ - - - - - - - - \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml deleted file mode 100644 index 35eb1dd..0000000 --- a/.idea/vcs.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/includes/gamematrix.h b/includes/gamematrix.h index 7a644d6..7a5e064 100644 --- a/includes/gamematrix.h +++ b/includes/gamematrix.h @@ -14,6 +14,6 @@ public: // Rotationsmatrix um Achse x/y/z static std::array,4> rot3D(double angle_deg, char axis); - // Verschiebung + // std::array,4> static std::array,4> translate(const std::array& pos); }; diff --git a/includes/gametimer.h b/includes/gametimer.h new file mode 100644 index 0000000..480ed74 --- /dev/null +++ b/includes/gametimer.h @@ -0,0 +1,14 @@ +#pragma once +#include + +class Timer { +public: + void start(); + void stop(); + long long elapsedMs() const; + +private: + std::chrono::time_point startTime; + std::chrono::time_point endTime; + bool running = false; +}; diff --git a/raylib/menu.h b/raylib/menu.h new file mode 100644 index 0000000..87e497b --- /dev/null +++ b/raylib/menu.h @@ -0,0 +1,19 @@ + +#ifndef MENU_H +#define MENU_H + +#pragma once +#include "raylib.h" + +enum MenuResult { + MENU_NONE, + MENU_SELECT_3, + MENU_SELECT_6, + MENU_SELECT_9 +}; + +MenuResult DrawMenu(); + +#endif //MENU_H + + diff --git a/src/gametimer.cpp b/src/gametimer.cpp new file mode 100644 index 0000000..fdaa9de --- /dev/null +++ b/src/gametimer.cpp @@ -0,0 +1,22 @@ +#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::high_resolution_clock::now() - startTime + ).count(); + } + return std::chrono::duration_cast( + endTime - startTime + ).count(); +} diff --git a/src/main.cpp b/src/main.cpp index 7ceea07..e9f6cd2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,19 +1,24 @@ #include "gamecube.h" +#include "gametimer.h" #include #include +#include // ----------------------------------------------------------- // 3D Memory Game – Hauptprogramm // ----------------------------------------------------------- int main() { - // Zufall initialisieren - srand(time(NULL)); - // Fenster und Kamera InitWindow(800, 600, "3D Memory Game with Matrix3D Library"); SetTargetFPS(60); + Timer timer; + timer.start(); + + // Zufall initialisieren + srand(time(NULL)); + Camera3D camera{}; camera.position = {6.0f, 6.0f, 6.0f}; camera.target = {0.0f, 0.0f, 0.0f}; @@ -25,6 +30,7 @@ int main() // Nur 3 Farben für 3 Paare Color colors[] = { RED, GREEN, BLUE, YELLOW, PINK }; + // 6 Karten-Positionen im 3x2 Raster std::vector positions = {{-2, 0, -2}, {0, 0, -2}, {2, 0, -2},{-2, 0, 0}, {0, 0, 0}, {2, 0, 0},{2,0,-4},{0,0,-4},{-2,0,-4},{-4,0,-2}}; @@ -54,11 +60,27 @@ int main() float flipSpeed = 5.0f; // Drehgeschwindigkeit bool gameWon = false; - // ----------------------------------------------------------- - // Hauptspielschleife - // ----------------------------------------------------------- - while (!WindowShouldClose()) - { + enum GameState { MENU, GAME }; + GameState state = MENU; + + int pairCount = 3; + + while (!WindowShouldClose()) { + + if (state == MENU) { + MenuResult res = DrawMenu(); + + switch (res) { + case MENU_SELECT_3: pairCount = 3; state = GAME; break; + case MENU_SELECT_6: pairCount = 6; state = GAME; break; + case MENU_SELECT_9: pairCount = 9; state = GAME; break; + default: break; + } + + continue; + } + + // === GAME === // Klick-Erkennung if (!gameWon && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { @@ -110,9 +132,15 @@ int main() } // Gewinnprüfung - if (!gameWon) - gameWon = std::all_of(cubes.begin(), cubes.end(), [](const gamecube &c){ return c.IsMatched(); }); + // Gewinnprüfung + if (!gameWon) { + gameWon = std::all_of(cubes.begin(), cubes.end(), + [](const gamecube &c){ return c.IsMatched(); }); + if (gameWon) + timer.stop(); + } + // <--- NEU // ----------------------------------------------------------- // Zeichnen // ----------------------------------------------------------- @@ -130,6 +158,24 @@ int main() else 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(); } diff --git a/src/menu.cpp b/src/menu.cpp new file mode 100644 index 0000000..9128be2 --- /dev/null +++ b/src/menu.cpp @@ -0,0 +1,32 @@ +#include "menu.h" + +MenuResult DrawMenu() { + Rectangle b1 = { 250, 180, 300, 50 }; + Rectangle b2 = { 250, 260, 300, 50 }; + Rectangle b3 = { 250, 340, 300, 50 }; + + BeginDrawing(); + ClearBackground(RAYWHITE); + + DrawText("Wähle Anzahl Paare:", 200, 100, 30, DARKGRAY); + + DrawRectangleRec(b1, LIGHTGRAY); + DrawText("3 Paare", 340, 195, 20, BLACK); + + DrawRectangleRec(b2, LIGHTGRAY); + DrawText("6 Paare", 340, 275, 20, BLACK); + + DrawRectangleRec(b3, LIGHTGRAY); + DrawText("9 Paare", 340, 355, 20, BLACK); + + EndDrawing(); + + Vector2 m = GetMousePosition(); + if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { + if (CheckCollisionPointRec(m, b1)) return MENU_SELECT_3; + if (CheckCollisionPointRec(m, b2)) return MENU_SELECT_6; + if (CheckCollisionPointRec(m, b3)) return MENU_SELECT_9; + } + + return MENU_NONE; +}