diff --git a/CMakeLists.txt b/CMakeLists.txt index 1462d63..15db0de 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,6 +15,7 @@ set(SRC_FILES ${CMAKE_CURRENT_LIST_DIR}/src/main.cpp ${CMAKE_CURRENT_LIST_DIR}/src/gamecube.cpp ${CMAKE_CURRENT_LIST_DIR}/src/gamematrix.cpp + includes/gamestate.h ) #automatisch hinzufügen file(GLOB SRC_FILES "${CMAKE_CURRENT_LIST_DIR}/src/*.cpp") diff --git a/includes/gamestate.h b/includes/gamestate.h new file mode 100644 index 0000000..eb52180 --- /dev/null +++ b/includes/gamestate.h @@ -0,0 +1,17 @@ +// +// Created by Anke Bidlingmaier on 08.12.25. +// +#pragma once + +#ifndef PROG3B_GAMESTATE_H +#define PROG3B_GAMESTATE_H + +enum class GameState +{ + Idle, // kein Würfel offen, Eingabe erlaubt + OneFlipped, // ein Würfel offen + CheckingMatch, // zwei Würfel vollständig aufgeklappt, Vergleich läuft + LockInput // Würfel drehen gerade – Eingabe kurz blockiert +}; + +#endif //PROG3B_GAMESTATE_H \ No newline at end of file diff --git a/src/main.cpp b/src/main.cpp index e6d8b51..76df4f6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -3,6 +3,7 @@ #include #include #include +#include "gamestate.h" // ----------------------------------------------------------- // 3D Memory Game – Hauptprogramm mit flexibler Paaranzahl @@ -62,8 +63,7 @@ int main() gamecube* second = nullptr; float flipSpeed = 5.0f; bool gameWon = false; - - + GameState state = GameState::Idle; // ----------------------------------------------------------- @@ -71,9 +71,10 @@ int main() // ----------------------------------------------------------- while (!WindowShouldClose()) { - // Klick-Erkennung - if (!gameWon && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) + //Klick-Erkennung + if (!gameWon && state != GameState::LockInput && state != GameState::CheckingMatch && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) { + Vector2 mouse = GetMousePosition(); for (auto &c : cubes) @@ -82,8 +83,12 @@ int main() { Vector2 screenPos = GetWorldToScreen({c.GetPosition().x, c.GetPosition().y, c.GetPosition().z}, camera); - if (fabs(mouse.x - screenPos.x) < 40 && fabs(mouse.y - screenPos.y) < 40) + if (fabs(mouse.x - screenPos.x) < 40 && fabs(mouse.y - screenPos.y) < 40) { c.FlipForward(); + state = GameState::OneFlipped; + } + + } } } @@ -99,17 +104,20 @@ int main() if (!first) first = &c; else if (!second && &c != first) second = &c; } + if (first && second && first->IsFlipped() && second->IsFlipped()) { + state = GameState::LockInput; + } + if (state == GameState::LockInput) { + state = GameState::CheckingMatch; + } } // Matching-Logik - if (first && second) + if (state == GameState::CheckingMatch && first && second) { - - - Color col1 = first->GetColor(); - Color col2 = second->GetColor(); - - if (col1.r == col2.r && col1.g == col2.g && col1.b == col2.b) + if (first->GetColor().r == second->GetColor().r && + first->GetColor().g == second->GetColor().g && + first->GetColor().b == second->GetColor().b) { first->SetMatched(true); second->SetMatched(true); @@ -120,10 +128,10 @@ int main() second->FlipBackward(); } - first = second = nullptr; // Zurücksetzen für den nächsten Versuch + first = second = nullptr; + state = GameState::Idle; } - // Gewinnprüfung if (!gameWon) gameWon = std::all_of(cubes.begin(), cubes.end(), [](const gamecube &c){ return c.IsMatched(); });