generated from freudenreichan/Programmieren_3b
GameState Aufgabe
This commit is contained in:
parent
0e28bbbf41
commit
3e4d49fe26
@ -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")
|
||||
|
||||
17
includes/gamestate.h
Normal file
17
includes/gamestate.h
Normal file
@ -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
|
||||
36
src/main.cpp
36
src/main.cpp
@ -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(); });
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user