generated from freudenreichan/Programmieren_3b
GameState Aufgabe
This commit is contained in:
+22
-14
@@ -3,6 +3,7 @@
|
||||
#include <ctime>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#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(); });
|
||||
|
||||
Reference in New Issue
Block a user