Compare commits
42
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40cbab7fe9 | ||
|
|
b6d09f0e59 | ||
|
|
07641a451b | ||
|
|
f93d72a184 | ||
|
|
3258531c32 | ||
|
|
31280508ec | ||
|
|
33e70cbf41 | ||
|
|
4b097a7ee2 | ||
|
|
7e36ccf7fb | ||
|
|
925b0f69ee | ||
|
|
68aa8831b7 | ||
|
|
84b469b454 | ||
|
|
7593e4d1c8 | ||
|
|
80d968f642 | ||
|
|
a6b1c52b7d | ||
|
|
47becca88b | ||
|
|
a421249213 | ||
|
|
0821395b92 | ||
|
|
5b99ad8812 | ||
|
|
ae9c8305f5 | ||
|
|
c61b682fd4 | ||
|
|
3a4f335465 | ||
|
|
544c4503cd | ||
|
|
402962e32b | ||
|
|
5f5f4568e6 | ||
|
|
22cf057f82 | ||
|
|
29d3ea45d5 | ||
|
|
e179abd8d9 | ||
|
|
72168eaa79 | ||
|
|
1e2548ddd0 | ||
|
|
6ffded95fe | ||
|
|
3be1087eb9 | ||
|
|
5dfa867449 | ||
|
|
18f4a5b492 | ||
|
|
368576471a | ||
|
|
2d2bf6e2c4 | ||
|
|
aeb4065e1c | ||
|
|
9a91e99728 | ||
|
|
84627ca069 | ||
|
|
50ed40ee3b | ||
|
|
4b16388754 | ||
|
|
eb85ce2112 |
@@ -8,3 +8,4 @@ out/
|
||||
*.o
|
||||
*.obj
|
||||
*.log
|
||||
idea/
|
||||
+38
-10
@@ -1,56 +1,84 @@
|
||||
cmake_minimum_required(VERSION 3.28)
|
||||
project(Prog3B)
|
||||
|
||||
set(EXECUTABLE_NAME Prog3B)
|
||||
|
||||
# Generate compile_commands.json
|
||||
# -------------------------------------------------
|
||||
# Global settings
|
||||
# -------------------------------------------------
|
||||
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
|
||||
set(CMAKE_CXX_STANDARD 20)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
|
||||
# -------------------------------------------------
|
||||
# Main executable
|
||||
# -------------------------------------------------
|
||||
set(SRC_FILES
|
||||
src/main.cpp
|
||||
src/gamecube.cpp
|
||||
src/gamematrix.cpp
|
||||
)
|
||||
|
||||
add_executable(${EXECUTABLE_NAME} ${SRC_FILES})
|
||||
|
||||
target_include_directories(${EXECUTABLE_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}/includes
|
||||
${CMAKE_CURRENT_LIST_DIR}/raylib
|
||||
)
|
||||
|
||||
|
||||
# -------------------------------------------------
|
||||
# Tests executable
|
||||
# -------------------------------------------------
|
||||
set(TEST_FILES
|
||||
src/tests.cpp
|
||||
src/gamematrix.cpp
|
||||
)
|
||||
|
||||
add_executable(tests ${TEST_FILES})
|
||||
|
||||
target_include_directories(tests PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}/includes
|
||||
)
|
||||
|
||||
|
||||
# -------------------------------------------------
|
||||
# Platform specific linking
|
||||
# -------------------------------------------------
|
||||
if (WIN32)
|
||||
|
||||
message(STATUS "Configuring for Windows")
|
||||
|
||||
target_link_libraries(${EXECUTABLE_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}/windows/libraylib.a
|
||||
opengl32 gdi32 winmm
|
||||
opengl32
|
||||
gdi32
|
||||
winmm
|
||||
)
|
||||
|
||||
elseif (APPLE)
|
||||
|
||||
message(STATUS "Configuring for MacOS")
|
||||
message(STATUS "Configuring for macOS")
|
||||
|
||||
target_link_libraries(${EXECUTABLE_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}/mac_x86/libraylib.a
|
||||
"-framework IOKit"
|
||||
"-framework Cocoa"
|
||||
"-framework OpenGL"
|
||||
"-framework IOKit"
|
||||
)
|
||||
|
||||
else ()
|
||||
# --- Linux ---
|
||||
|
||||
message(STATUS "Configuring for Linux")
|
||||
|
||||
target_link_libraries(${EXECUTABLE_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_LIST_DIR}/linux/libraylib.a
|
||||
GL X11 m
|
||||
GL
|
||||
X11
|
||||
m
|
||||
pthread
|
||||
dl
|
||||
)
|
||||
|
||||
target_link_libraries(tests PRIVATE
|
||||
m
|
||||
)
|
||||
|
||||
endif ()
|
||||
@@ -0,0 +1,74 @@
|
||||
========================================================
|
||||
Projekt: gamematrix (C++ Library)
|
||||
Rolle: Architekt
|
||||
Datei: design.txt
|
||||
Datum: 03.11.2025
|
||||
Team: prog3b_652
|
||||
========================================================
|
||||
|
||||
# ----------------------------
|
||||
# 1. Projektstruktur / Namespace
|
||||
# ----------------------------
|
||||
Namespace: Matrix3D
|
||||
|
||||
Ziel: Saubere Trennung der Bibliothek, Vermeidung von Namenskonflikten.
|
||||
|
||||
Beispiel:
|
||||
namespace Matrix3D {
|
||||
// Funktionen, ggf Klasse(n)
|
||||
}
|
||||
|
||||
# ----------------------------
|
||||
# 2. Datenstrukturen / Klassen
|
||||
# ----------------------------
|
||||
Listen Sie die Klassen oder Structs auf, die verwendet werden:
|
||||
|
||||
| Name | Typ | Beschreibung |
|
||||
|--------|------------------------------------------|--------------|
|
||||
| Vec3 | struct Vec3 | 3D-Vektor (x, y, z) |
|
||||
| Mat4 | std::array<std::array<double,4>,4> | 4x4-Matrix (homogen) |
|
||||
| ______ | ________ | ___________________ |
|
||||
| ______ | ________ | ___________________ |
|
||||
|
||||
# ----------------------------
|
||||
# 3. Operatoren / Templates
|
||||
# ----------------------------
|
||||
Welche Operatoren oder Templates sollen definiert werden?
|
||||
|
||||
- Templates für unterschiedliche Datentypen? ☐ Ja ☐ Nein
|
||||
- Operatoren:
|
||||
- Mat4 * Mat4
|
||||
- Mat4 * Vec3
|
||||
|
||||
# ----------------------------
|
||||
# 4. Funktionen / Schnittstellen
|
||||
# ----------------------------
|
||||
Liste der Funktionen mit Eingabe/Ausgabe und kurzer Beschreibung:
|
||||
|
||||
| Funktion | Eingabe | Ausgabe | Kurzbeschreibung |
|
||||
|---------------|------------------------------------|-----------------------|----------------------------------------|
|
||||
| matmul | Mat4 A, Mat4 B | Mat4 | Matrixmultiplikation 4x4 |
|
||||
| translate | Vec3 pos | Mat4 | Verschiebungstransformation |
|
||||
| rot3D | double angle_deg, char axis | Mat4 | Rotation um Achse x/y/z |
|
||||
| identity (optional)| --- | Mat4 | Identitätsmatrix |
|
||||
| _____________ | __________________________________ | ____________________ | ______________________________ |
|
||||
|
||||
# ----------------------------
|
||||
# 5. Designentscheidungen / Hinweise
|
||||
# ----------------------------
|
||||
- Rückgabe der Matrizen per Wert oder Referenz? ___________
|
||||
- Verwendung von std::array oder std::vector? ___________
|
||||
- Homogene Koordinaten für Translation / Rotation (4x4)? ☐ Ja ☐ Nein
|
||||
- Weitere Designüberlegungen: ___________________________
|
||||
|
||||
# ----------------------------
|
||||
# 6. Deliverables / Milestones
|
||||
# ----------------------------
|
||||
- design.txt fertig und im Branch architect committed
|
||||
- Übergabe an Entwickler für Implementierung
|
||||
|
||||
========================================================
|
||||
Hinweis:
|
||||
- Dieses Dokument dient als Grundlage für die Implementierung.
|
||||
- Alle Designentscheidungen sollen klar nachvollziehbar sein.
|
||||
========================================================
|
||||
@@ -0,0 +1,76 @@
|
||||
========================================================
|
||||
Projekt: gamematrix (C++ Library)
|
||||
Rolle: Projektleiter
|
||||
Datei: requirements.txt
|
||||
Datum: 03.11.2025
|
||||
Team: prob3b_652
|
||||
========================================================
|
||||
|
||||
# ----------------------------
|
||||
# 1. Projektziel
|
||||
# ----------------------------
|
||||
Beschreiben Sie hier kurz das Ziel des Projekts:
|
||||
|
||||
Ziel:
|
||||
- C++-Bibliothek gamematrix.cpp erweitern. Matrizenoperationen für 3D-Transformationen bereitstellen.
|
||||
|
||||
- Integration in das bestehende Spielprojekt.
|
||||
|
||||
- Git-Workflow: Neuer Branch für diese Woche (KW25), Änderungen committen und später in den Hauptbranch mergen.
|
||||
- Vorgehensmodell: Wasserfall, alle Phasen strikt nacheinander.
|
||||
|
||||
# ----------------------------
|
||||
# 2. Funktionale Anforderungen
|
||||
# ----------------------------
|
||||
Listen Sie alle Funktionen auf, die die Bibliothek bereitstellen soll..
|
||||
Tragen Sie ein: Funktion, Eingabe, Ausgabe, kurze Beschreibung
|
||||
|
||||
| Funktion | Eingabe | Ausgabe | Kurzbeschreibung |
|
||||
|---------------|------------------------------------|-----------------------|----------------------------------------|
|
||||
| matmul | 4x4 Matrix A, 4x4 Matrix B | 4x4 Matrix |Multipliziert zwei Matrizen und gibt |
|
||||
| | | |das Ergebnis als neue Matrix zurück. |
|
||||
| | | |Prüft dabei, ob die Dimensionen |
|
||||
| | | |kompatibel sind |
|
||||
|---------------------------------------------------------------------------------------------------------------------|
|
||||
| translate | 3D Vektor | 4x4 Matrix | Verschiebt Punkte oder Objekte im Raum |
|
||||
| | | | um einen gegebenen Vektor. |
|
||||
|---------------------------------------------------------------------------------------------------------------------|
|
||||
| rot3D | Winkel in °, Rotationsachse (x/y/z)| 4x4 Matrix | Rotiert eine Matrix um eine Achse um |
|
||||
| | | |einen vorgegebenen Winkel |
|
||||
|---------------------------------------------------------------------------------------------------------------------|
|
||||
| identity (optional)| --- | 4x4 Matrix | _____________________________________ |
|
||||
| _____________ | __________________________________ | ____________________ | ______________________________ |
|
||||
| _____________ | __________________________________ | ____________________ | ______________________________ |
|
||||
|
||||
# ----------------------------
|
||||
# 3. Nicht-funktionale Anforderungen
|
||||
# ----------------------------
|
||||
(z. B. Performance, Lesbarkeit, Wartbarkeit, Python-Kompatibilität via pybind11)
|
||||
|
||||
- Jede Methode soll mit einem aussagekräftigen Kommentar versehen werden.
|
||||
- User soll aufgefordert werden zwei 4x4 Matritzen einzugeben bzw. einen Winkel in Grad.
|
||||
(Architect Aufgabe -> Die Eingabe- Methode soll Prüfen ob die Form vom Winkel bzw. Matritzen den
|
||||
Anforderungen entsprechen)
|
||||
- ____________________________________________________________
|
||||
|
||||
# ----------------------------
|
||||
# 4. Annahmen / Einschränkungen
|
||||
# ----------------------------
|
||||
|
||||
|
||||
- Wir arbeiten ausschließlich mit 4x4 Matritzen. Winkel soll in Grand eingegeben werden. ____________________________________________________________
|
||||
- Variablendeklaration ausschließlich mit double# ----------------------------
|
||||
# 5. Abnahmekriterien
|
||||
# ----------------------------
|
||||
Wie soll geprüft werden, dass die Anforderungen erfüllt sind?
|
||||
(z. B. Unit-Tests, Beispielrotationen, Matrizenmultiplikation)
|
||||
|
||||
- Beispielrotationen
|
||||
- Matritzen-Multiplikation
|
||||
-
|
||||
|
||||
========================================================
|
||||
Hinweis:
|
||||
- Diese Datei wird vom Projektleiter erstellt und gepflegt.
|
||||
- Jede Phase des Projekts soll hier dokumentiert werden.
|
||||
========================================================
|
||||
@@ -0,0 +1,44 @@
|
||||
@@ -1,43 +0,0 @@
|
||||
========================================================
|
||||
Projekt: gamematrix (C++ Library)
|
||||
Rolle: Tester
|
||||
Datei: tests.txt
|
||||
Datum: 4.10.2025
|
||||
Team: prog3b_652
|
||||
========================================================
|
||||
|
||||
# ----------------------------
|
||||
# 1. Testplan Übersicht
|
||||
# ----------------------------
|
||||
Ziel: Überprüfung der Funktionen matmul(), translate(), rot3D().
|
||||
|
||||
| Funktion | Testfall | Eingabe | Erwartetes Ergebnis | Bemerkung |
|
||||
|---------------|---------------------------|------------------------------|-----------------------------------|----------------------------|
|
||||
| matmul | Identity * Identity | 4x4 Identity Matrizen | Identity | Basisfall |
|
||||
| matmul | Beispielmatrizen | A=[[...]], B=[[...]] | C=[[...]] | Prüfen mit Handrechnung |
|
||||
| translate | Verschiebung | Vec3 {1,2,3} | Matrix mit Translation 1,2,3 | Prüfen letzte Spalte |
|
||||
| rot3D | Rotation Z 90° | angle_deg=90, axis='z' | (1,0,0) -> (0,1,0) | Prüfen Anwendung auf Vektor|
|
||||
| rot3D | Rotation X 180° | angle_deg=180, axis='x' | (0,1,0) -> (0,-1,0) | Prüfen Anwendung auf Vektor|
|
||||
| rot3D | Rotation Y 270° | angle_deg=270, axis='y' | (1,0,0) -> (0,0,-1) | Prüfen Anwendung auf Vektor|
|
||||
|
||||
|
||||
# ----------------------------
|
||||
# 2. Testdaten / Matrizen
|
||||
# ----------------------------
|
||||
- Matrizen für matmul: Identity, Beispiel A/B Matrizen
|
||||
- Vektoren für translate: Vec3 {x, y, z}
|
||||
- Vektoren für rot3D: Vec3 {1,0,0}, Vec3 {0,1,0}
|
||||
|
||||
# ----------------------------
|
||||
# 3. Abnahmekriterien
|
||||
# ----------------------------
|
||||
- Alle Unit-Tests erfolgreich
|
||||
- Keine Exceptions außer gewollt (z. B. ungültige Achse)
|
||||
- Testbericht in tests.txt dokumentiert
|
||||
|
||||
========================================================
|
||||
Hinweis:
|
||||
- Diese Datei wird vom Tester gepflegt.
|
||||
- Tester dokumentiert Input, Output, erwartetes Ergebnis und Erfolg/Fehler.
|
||||
========================================================
|
||||
|
||||
@@ -32,3 +32,4 @@ private:
|
||||
bool flippingBackward = false;
|
||||
float rotation = 0.0f;
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,150 @@
|
||||
//
|
||||
// Created by kris- on 03.11.2025.
|
||||
//
|
||||
#include <iostream>
|
||||
#include "gamematrix.h"
|
||||
|
||||
// Matrixmultiplikation
|
||||
|
||||
|
||||
// Rotationsmatrix um Achse x/y/z
|
||||
static std::array<std::array<double,4>,4> rot3D(double angle_deg, char axis);
|
||||
|
||||
// Verschiebung
|
||||
static std::array<std::array<double,4>,4> translate(const std::array<double, 3>& pos);
|
||||
|
||||
|
||||
|
||||
|
||||
//Matrixmultiplikation-Funktion
|
||||
std::array<std::array<double,4>,4> gameMatrix::matmul(
|
||||
const std::array<std::array<double,4>,4>& A,
|
||||
const std::array<std::array<double,4>,4>& B)
|
||||
|
||||
{ //Matrix-Mathematik (Matrix C = A*B)
|
||||
std::array<std::array<double,4>,4> C{};
|
||||
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (int j = 0; j < 4; ++j)
|
||||
for (int k = 0; k < 4; ++k)
|
||||
C[i][j] += A[i][k] * B[k][j];
|
||||
|
||||
|
||||
return C;
|
||||
|
||||
}
|
||||
|
||||
//Rotation 3D
|
||||
std::array<std::array<double,4>,4> gameMatrix::rot3D(double angle_deg, char axis) {
|
||||
double rad = angle_deg * M_PI / 180.0;
|
||||
|
||||
//Mathematik-Rotation
|
||||
std::array<std::array<double,4>,4> R{};
|
||||
|
||||
for (int i = 0; i < 4; ++i)
|
||||
R[i][i] = 1.0;
|
||||
|
||||
if (axis == 'x' || axis == 'X') {
|
||||
R[1][1] = cos(rad);
|
||||
R[1][2] = -sin(rad);
|
||||
R[2][1] = sin(rad);
|
||||
R[2][2] = cos(rad);
|
||||
} else if (axis == 'y' || axis == 'Y') {
|
||||
R[0][0] = cos(rad);
|
||||
R[0][2] = sin(rad);
|
||||
R[2][0] = -sin(rad);
|
||||
R[2][2] = cos(rad);
|
||||
} else if (axis == 'z' || axis == 'Z') {
|
||||
R[0][0] = cos(rad);
|
||||
R[0][1] = -sin(rad);
|
||||
R[1][0] = sin(rad);
|
||||
R[1][1] = cos(rad);
|
||||
}
|
||||
|
||||
return R;
|
||||
}
|
||||
|
||||
//Translation
|
||||
std::array<std::array<double,4>,4> gameMatrix::translate(const std::array<double,3>& pos) {
|
||||
std::array<std::array<double,4>,4> T{};
|
||||
for (int i = 0; i < 4; ++i)
|
||||
T[i][i] = 1.0; // Identitätsmatrix
|
||||
|
||||
T[0][3] = pos[0]; // x-Verschiebung
|
||||
T[1][3] = pos[1]; // y-Verschiebung
|
||||
T[2][3] = pos[2]; // z-Verschiebung
|
||||
|
||||
return T;
|
||||
}
|
||||
|
||||
|
||||
|
||||
//unnötig die main hier, aber wenn die schon mal da ist, warum auch nicht zum testen dieser .cpp-Datei
|
||||
int main()
|
||||
{
|
||||
// Part Matrix
|
||||
std::array<std::array<double,4>,4> A{};
|
||||
std::array<std::array<double,4>,4> B{};
|
||||
|
||||
std::cout << "Gib die Werte für Matrix A (4x4) ein:\n";
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
std::cout << "A[" << i << "][" << j << "] = ";
|
||||
std::cin >> A[i][j];
|
||||
}
|
||||
|
||||
std::cout << "\nGib die Werte für Matrix B (4x4) ein:\n";
|
||||
for (int i = 0; i < 4; ++i)
|
||||
for (int j = 0; j < 4; ++j) {
|
||||
std::cout << "B[" << i << "][" << j << "] = ";
|
||||
std::cin >> B[i][j];
|
||||
}
|
||||
|
||||
std::array<std::array<double,4>,4> C = gameMatrix::matmul(A, B);
|
||||
|
||||
std::cout << "\nErgebnis der Matrixmultiplikation (C = A * B):\n";
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
for (int j = 0; j < 4; ++j)
|
||||
std::cout << C[i][j] << "\t";
|
||||
std::cout << "\n";
|
||||
}
|
||||
//Ende Matrix
|
||||
|
||||
|
||||
// Rotation
|
||||
double angle;
|
||||
char axis;
|
||||
std::cout << "\nGib einen Rotationswinkel in Grad ein: ";
|
||||
std::cin >> angle;
|
||||
std::cout << "Gib die Rotationsachse (x/y/z) ein: ";
|
||||
std::cin >> axis;
|
||||
|
||||
std::array<std::array<double,4>,4> R = gameMatrix::rot3D(angle, axis);
|
||||
|
||||
std::cout << "\nRotationsmatrix R:\n";
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
for (int j = 0; j < 4; ++j)
|
||||
std::cout << R[i][j] << "\t";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
// Translation
|
||||
std::array<double,3> pos;
|
||||
std::cout << "\nGib die Translation (x y z) ein: ";
|
||||
std::cin >> pos[0] >> pos[1] >> pos[2];
|
||||
|
||||
std::array<std::array<double,4>,4> T = gameMatrix::translate(pos);
|
||||
|
||||
std::cout << "\nTranslationsmatrix T:\n";
|
||||
for (int i = 0; i < 4; ++i) {
|
||||
for (int j = 0; j < 4; ++j)
|
||||
std::cout << T[i][j] << "\t";
|
||||
std::cout << "\n";
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -25,3 +25,11 @@ public:
|
||||
);
|
||||
};
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
|
||||
+2
-5
@@ -5,13 +5,10 @@
|
||||
#include "../includes/gamematrix.h"
|
||||
|
||||
// Matrixmultiplikation
|
||||
|
||||
|
||||
// Rotationsmatrix um Achse x/y/z
|
||||
static std::array<std::array<double,4>,4> rot3D(double angle_deg, char axis);
|
||||
|
||||
//static std::array<std::array<double,4>,4> rot3D(double angle_deg, char axis);
|
||||
// Verschiebung
|
||||
static std::array<std::array<double,4>,4> translate(const std::array<double, 3>& pos);
|
||||
//static std::array<std::array<double,4>,4> translate(const std::array<double, 3>& pos);
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include <vector>
|
||||
#include <array>
|
||||
#include <stdexcept>
|
||||
#include <cmath>
|
||||
|
||||
class gameMatrix
|
||||
{
|
||||
public:
|
||||
// Matrix Multiplikation
|
||||
static std::array<std::array<double,4>,4> matmul(const std::array<std::array<double,4>,4>& A,
|
||||
const std::array<std::array<double,4>,4>& B);
|
||||
|
||||
// Rotationsmatrix um Achse x/y/z
|
||||
static std::array<std::array<double,4>,4> rot3D(double angle_deg, char axis);
|
||||
|
||||
// Verschiebung
|
||||
static std::array<std::array<double,4>,4> translate(const std::array<double, 3>& pos);
|
||||
};
|
||||
+52
-18
@@ -1,8 +1,16 @@
|
||||
#include "gamecube.h"
|
||||
#include <algorithm>
|
||||
#include <ctime>
|
||||
//Funktion innitGame
|
||||
//Anzahl der Paare(pairCount*2)
|
||||
#include <iostream>
|
||||
//enum game
|
||||
//Ab Zeile 114 if game won
|
||||
//Ab Zeile 148 checking match?
|
||||
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Initialisierung
|
||||
// -----------------------------------------------------------
|
||||
|
||||
void innitGame(int pairCount,
|
||||
std::vector<gamecube> &cubes,
|
||||
std::vector<Vec3> &positions )
|
||||
@@ -65,8 +73,6 @@ void innitGame(int pairCount,
|
||||
// -----------------------------------------------------------
|
||||
int main()
|
||||
{
|
||||
|
||||
|
||||
//NEU Counter
|
||||
int counter = 0;
|
||||
|
||||
@@ -89,7 +95,7 @@ int main()
|
||||
// Spielvariablen
|
||||
// -------------------------------------------------------
|
||||
// Nur 3 Farben für 3 Paare
|
||||
int pairCount = 6; // <-- vorerst fixe Anzahl
|
||||
int pairCount = 2; // <-- vorerst fixe Anzahl
|
||||
std::vector<Vec3> positions;
|
||||
std::vector<gamecube> cubes;
|
||||
|
||||
@@ -104,27 +110,48 @@ int main()
|
||||
float flipSpeed = 5.0f; // Drehgeschwindigkeit
|
||||
bool gameWon = false;
|
||||
|
||||
GameState state = GameState::Idle; //legen wir fest, in welchem Zustand das Spiel startet
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Hauptspielschleife
|
||||
// -----------------------------------------------------------
|
||||
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
|
||||
// Klick-Erkennung
|
||||
if (!gameWon && IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||
{
|
||||
//Neu Counter
|
||||
counter++;
|
||||
if (!gameWon
|
||||
&& (state == GameState::Idle || state == GameState::OneFlipped)
|
||||
&& IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) {
|
||||
|
||||
// nur im Idle- oder OneFlipped-Zustand wird reagiert<-------------------------------------------------
|
||||
//Wenn einer Dreht, clicken blockieren
|
||||
// ...
|
||||
|
||||
Vector2 mouse = GetMousePosition();
|
||||
|
||||
for (auto &c : cubes)
|
||||
for (auto &c : cubes) //Hier die State Logik
|
||||
{
|
||||
if (!c.IsFlipped() && !c.IsMatched())
|
||||
std::cout<<("State missing");
|
||||
if (!c.IsFlipped() && !c.IsMatched()) //<--------------- Zustandwechsel anpassen
|
||||
{
|
||||
Vector2 screenPos = GetWorldToScreen({c.GetPosition().x, c.GetPosition().y, c.GetPosition().z}, camera);
|
||||
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)
|
||||
c.FlipForward();
|
||||
if (fabs(mouse.x - screenPos.x) < 40 &&
|
||||
fabs(mouse.y - screenPos.y) < 40)
|
||||
{
|
||||
c.FlipForward(); //<-----Animation Start
|
||||
//Neu Counter
|
||||
counter++;
|
||||
|
||||
if (state == GameState::Idle) //Neu (Ü4)
|
||||
state = GameState::OneFlipped;
|
||||
else
|
||||
state = GameState::LockInput;
|
||||
|
||||
break; // 🔒 nur EIN Würfel pro Klick
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -137,8 +164,10 @@ int main()
|
||||
// Sobald ein Würfel vollständig umgedreht ist → merken
|
||||
if (c.IsFlipped() && !c.IsMatched())
|
||||
{
|
||||
if (!first) first = &c;
|
||||
else if (!second && &c != first) second = &c;
|
||||
if (!first)
|
||||
first = &c;
|
||||
else if (!second && &c != first)
|
||||
second = &c;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +179,9 @@ int main()
|
||||
Color col1 = first->GetColor();
|
||||
Color col2 = second->GetColor();
|
||||
|
||||
if (col1.r == col2.r && col1.g == col2.g && col1.b == col2.b)
|
||||
if (col1.r == col2.r &&
|
||||
col1.g == col2.g &&
|
||||
col1.b == col2.b)
|
||||
{
|
||||
first->SetMatched(true);
|
||||
second->SetMatched(true);
|
||||
@@ -163,9 +194,12 @@ int main()
|
||||
|
||||
|
||||
first = second = nullptr;
|
||||
state = GameState::Idle; //neu
|
||||
}
|
||||
|
||||
// Gewinnprüfung
|
||||
// -----------------------------
|
||||
// WIN CHECK
|
||||
// -----------------------------
|
||||
if (!gameWon)
|
||||
gameWon = std::all_of(cubes.begin(), cubes.end(), [](const gamecube &c){ return c.IsMatched(); });
|
||||
|
||||
|
||||
+211
@@ -0,0 +1,211 @@
|
||||
//
|
||||
// Created by gamer on 14.12.2025.
|
||||
//
|
||||
#include "gamecube.h"
|
||||
#include <algorithm>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// GameState – Zustandsmaschine
|
||||
// -----------------------------------------------------------
|
||||
enum class GameState
|
||||
{
|
||||
Idle, // kein Würfel offen
|
||||
OneFlipped, // ein Würfel offen
|
||||
LockInput, // Animation läuft
|
||||
CheckingMatch // Vergleich
|
||||
};
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Initialisierung
|
||||
// -----------------------------------------------------------
|
||||
void innitGame(int pairCount,
|
||||
std::vector<gamecube> &cubes,
|
||||
std::vector<Vec3> &positions)
|
||||
{
|
||||
cubes.clear();
|
||||
positions.clear();
|
||||
|
||||
int total = pairCount * 2;
|
||||
int cols = ceil(sqrt(total));
|
||||
int rows = (total + cols - 1) / cols;
|
||||
float spacing = 2.2f;
|
||||
|
||||
for (int r = 0; r < rows; r++)
|
||||
for (int c = 0; c < cols; c++)
|
||||
if ((int)positions.size() < total)
|
||||
positions.push_back({
|
||||
(c - cols / 2.0f) * spacing,
|
||||
0,
|
||||
(r - rows / 2.0f) * spacing
|
||||
});
|
||||
|
||||
std::vector<Color> colorPool;
|
||||
for (int i = 0; i < pairCount; i++)
|
||||
{
|
||||
Color col = {
|
||||
(unsigned char)(rand() % 256),
|
||||
(unsigned char)(rand() % 256),
|
||||
(unsigned char)(rand() % 256),
|
||||
255
|
||||
};
|
||||
colorPool.push_back(col);
|
||||
colorPool.push_back(col);
|
||||
}
|
||||
|
||||
for (int i = total - 1; i > 0; --i)
|
||||
std::swap(colorPool[i], colorPool[rand() % (i + 1)]);
|
||||
|
||||
for (int i = 0; i < total; i++)
|
||||
cubes.emplace_back(positions[i], colorPool[i]);
|
||||
}
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// MAIN
|
||||
// -----------------------------------------------------------
|
||||
int main()
|
||||
{
|
||||
srand(time(NULL));
|
||||
InitWindow(800, 600, "3D Memory Game – Stable Version");
|
||||
SetTargetFPS(60);
|
||||
|
||||
Camera3D camera{};
|
||||
camera.position = {6, 6, 6};
|
||||
camera.target = {0, 0, 0};
|
||||
camera.up = {0, 1, 0};
|
||||
camera.fovy = 45;
|
||||
camera.projection = CAMERA_PERSPECTIVE;
|
||||
|
||||
int pairCount = 2;
|
||||
std::vector<Vec3> positions;
|
||||
std::vector<gamecube> cubes;
|
||||
innitGame(pairCount, cubes, positions);
|
||||
|
||||
gamecube *first = nullptr;
|
||||
gamecube *second = nullptr;
|
||||
|
||||
float flipSpeed = 5.0f;
|
||||
bool gameWon = false;
|
||||
int counter = 0;
|
||||
|
||||
GameState state = GameState::Idle;
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// GAME LOOP
|
||||
// -----------------------------------------------------------
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
// -----------------------------
|
||||
// INPUT (nur wenn erlaubt)
|
||||
// -----------------------------
|
||||
if (!gameWon &&
|
||||
(state == GameState::Idle || state == GameState::OneFlipped) &&
|
||||
IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||
{
|
||||
Vector2 mouse = GetMousePosition();
|
||||
|
||||
for (auto &c : cubes)
|
||||
{
|
||||
if (!c.IsFlipped() && !c.IsMatched())
|
||||
{
|
||||
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)
|
||||
{
|
||||
c.FlipForward();
|
||||
counter++;
|
||||
|
||||
if (state == GameState::Idle)
|
||||
state = GameState::OneFlipped;
|
||||
else
|
||||
state = GameState::LockInput;
|
||||
|
||||
break; // 🔒 nur EIN Würfel pro Klick
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// UPDATE – Animation
|
||||
// -----------------------------
|
||||
for (auto &c : cubes)
|
||||
{
|
||||
c.Update(flipSpeed);
|
||||
|
||||
if (c.IsFlipped() && !c.IsMatched())
|
||||
{
|
||||
if (!first)
|
||||
first = &c;
|
||||
else if (!second && &c != first)
|
||||
second = &c;
|
||||
}
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// Animation beendet → Vergleich
|
||||
// -----------------------------
|
||||
if (state == GameState::LockInput && first && second)
|
||||
state = GameState::CheckingMatch;
|
||||
|
||||
// -----------------------------
|
||||
// MATCHING
|
||||
// -----------------------------
|
||||
if (state == GameState::CheckingMatch)
|
||||
{
|
||||
Color a = first->GetColor();
|
||||
Color b = second->GetColor();
|
||||
|
||||
if (a.r == b.r && a.g == b.g && a.b == b.b)
|
||||
{
|
||||
first->SetMatched(true);
|
||||
second->SetMatched(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
first->FlipBackward();
|
||||
second->FlipBackward();
|
||||
}
|
||||
|
||||
first = second = nullptr;
|
||||
state = GameState::Idle;
|
||||
}
|
||||
|
||||
// -----------------------------
|
||||
// WIN CHECK
|
||||
// -----------------------------
|
||||
if (!gameWon)
|
||||
gameWon = std::all_of(
|
||||
cubes.begin(),
|
||||
cubes.end(),
|
||||
[](const gamecube &c)
|
||||
{ return c.IsMatched(); });
|
||||
|
||||
// -----------------------------
|
||||
// DRAW
|
||||
// -----------------------------
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
BeginMode3D(camera);
|
||||
|
||||
for (auto &c : cubes)
|
||||
c.Draw();
|
||||
|
||||
EndMode3D();
|
||||
|
||||
if (gameWon)
|
||||
DrawText("Congrats! You found all pairs!", 140, 260, 30, DARKBLUE);
|
||||
else
|
||||
DrawText("Flip 2 cubes - find matching pairs!", 10, 10, 20, DARKGRAY);
|
||||
|
||||
DrawText(TextFormat("Moves: %i", counter / 2), 10, 40, 20, DARKGRAY);
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
CloseWindow();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,163 @@
|
||||
#include "gamecube.h"
|
||||
#include <algorithm>
|
||||
#include <ctime>
|
||||
//Funktion innitGame
|
||||
//Anzahl der Paare(pairCount*2)
|
||||
void innitGame()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
// -----------------------------------------------------------
|
||||
// 3D Memory Game – Hauptprogramm
|
||||
// -----------------------------------------------------------
|
||||
int main()
|
||||
{
|
||||
|
||||
|
||||
//NEU Counter
|
||||
int counter = 0;
|
||||
|
||||
|
||||
// Zufall initialisieren
|
||||
srand(time(NULL));
|
||||
|
||||
// Fenster und Kamera
|
||||
InitWindow(800, 600, "3D Memory Game with Matrix3D Library");
|
||||
SetTargetFPS(60);
|
||||
|
||||
Camera3D camera{};
|
||||
camera.position = {6.0f, 6.0f, 6.0f};
|
||||
camera.target = {0.0f, 0.0f, 0.0f};
|
||||
camera.up = {0.0f, 1.0f, 0.0f};
|
||||
camera.fovy = 45.0f;
|
||||
camera.projection = CAMERA_PERSPECTIVE;
|
||||
|
||||
|
||||
|
||||
|
||||
// Nur 3 Farben für 3 Paare <----------------------------------------------------------
|
||||
Color colors[] = { RED, GREEN, BLUE };
|
||||
|
||||
// 6 Karten-Positionen im 3x2 Raster
|
||||
std::vector<Vec3> positions = {{-2, 0, -2}, {0, 0, -2}, {2, 0, -2},{-2, 0, 0}, {0, 0, 0}, {2, 0, 0}};
|
||||
|
||||
// Farben doppelt in einen Pool legen und mischen
|
||||
std::vector<Color> colorPool;
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
colorPool.push_back(colors[i]);
|
||||
colorPool.push_back(colors[i]);
|
||||
}
|
||||
|
||||
// Fisher-Yates Shuffle mit rand()
|
||||
for (int i = colorPool.size() - 1; i > 0; --i)
|
||||
{
|
||||
int j = rand() % (i + 1); // Zufallsindex von 0 bis i
|
||||
std::swap(colorPool[i], colorPool[j]);
|
||||
}
|
||||
|
||||
// Karten/Würfel erstellen
|
||||
std::vector<gamecube> cubes;
|
||||
for (int i = 0; i < 6; i++)
|
||||
cubes.emplace_back(positions[i], colorPool[i]); //<------------------------------------------------------------
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
gamecube* first = nullptr;
|
||||
gamecube* second = nullptr;
|
||||
float flipSpeed = 5.0f; // Drehgeschwindigkeit
|
||||
bool gameWon = false;
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Hauptspielschleife
|
||||
// -----------------------------------------------------------
|
||||
while (!WindowShouldClose())
|
||||
{
|
||||
// Klick-Erkennung
|
||||
if (!gameWon && IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||
{
|
||||
//Neu Counter
|
||||
counter++;
|
||||
|
||||
Vector2 mouse = GetMousePosition();
|
||||
|
||||
for (auto &c : cubes)
|
||||
{
|
||||
if (!c.IsFlipped() && !c.IsMatched())
|
||||
{
|
||||
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)
|
||||
c.FlipForward();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Animation aller Würfel
|
||||
for (auto &c : cubes)
|
||||
{
|
||||
c.Update(flipSpeed);
|
||||
|
||||
// Sobald ein Würfel vollständig umgedreht ist → merken
|
||||
if (c.IsFlipped() && !c.IsMatched())
|
||||
{
|
||||
if (!first) first = &c;
|
||||
else if (!second && &c != first) second = &c;
|
||||
}
|
||||
}
|
||||
|
||||
// Matching-Logik
|
||||
if (first && second)
|
||||
{
|
||||
//counter hier macht umdrehungen
|
||||
|
||||
Color col1 = first->GetColor();
|
||||
Color col2 = second->GetColor();
|
||||
|
||||
if (col1.r == col2.r && col1.g == col2.g && col1.b == col2.b)
|
||||
{
|
||||
first->SetMatched(true);
|
||||
second->SetMatched(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
first->FlipBackward();
|
||||
second->FlipBackward();
|
||||
}
|
||||
|
||||
|
||||
first = second = nullptr;
|
||||
}
|
||||
|
||||
// Gewinnprüfung
|
||||
if (!gameWon)
|
||||
gameWon = std::all_of(cubes.begin(), cubes.end(), [](const gamecube &c){ return c.IsMatched(); });
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// Zeichnen
|
||||
// -----------------------------------------------------------
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
BeginMode3D(camera);
|
||||
|
||||
for (auto &c : cubes)
|
||||
c.Draw();
|
||||
|
||||
EndMode3D();
|
||||
if (gameWon)
|
||||
DrawText("Congrats! You found all pairs!", 150, 260, 30, DARKBLUE);
|
||||
else
|
||||
DrawText("Flip 2 cubes - find matching pairs!", 10, 10, 20, DARKGRAY);
|
||||
//Neu Counter
|
||||
DrawText(TextFormat("Counter: %i",counter/2),10,40,20,DARKGRAY); //counter//2 da sonst doppelt
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
CloseWindow();
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
project(prog3b_652)
|
||||
|
||||
set(CMAKE_CXX_STANDARD 17)
|
||||
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
||||
|
||||
add_executable(prog3b main.cpp)
|
||||
+122
@@ -0,0 +1,122 @@
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <thread>
|
||||
#include <chrono>
|
||||
#include <cstdlib>
|
||||
|
||||
// =====================
|
||||
// Datei einlesen
|
||||
// =====================
|
||||
void readFile(const std::string& filename, std::vector<int>& data)
|
||||
{
|
||||
std::ifstream file(filename);
|
||||
int value;
|
||||
while (file >> value)
|
||||
data.push_back(value);
|
||||
}
|
||||
|
||||
// =====================
|
||||
// Serielle Auswertung
|
||||
// =====================
|
||||
int countSerial(const std::vector<int>& messungen)
|
||||
{
|
||||
if (messungen.size() < 2)
|
||||
return 0;
|
||||
|
||||
int increases = 0;
|
||||
for (size_t i = 1; i < messungen.size(); ++i)
|
||||
if (messungen[i] > messungen[i - 1])
|
||||
++increases;
|
||||
|
||||
return increases;
|
||||
}
|
||||
|
||||
// =====================
|
||||
// Parallele Auswertung
|
||||
// =====================
|
||||
int countParallel(const std::vector<int>& messungen, int numThreads)
|
||||
{
|
||||
if (messungen.size() < 2)
|
||||
return 0;
|
||||
|
||||
int totalComparisons = messungen.size() - 1;
|
||||
if (numThreads > totalComparisons)
|
||||
numThreads = totalComparisons;
|
||||
|
||||
std::vector<int> results(numThreads, 0);
|
||||
std::vector<std::thread> threads;
|
||||
|
||||
int base = totalComparisons / numThreads;
|
||||
int remainder = totalComparisons % numThreads;
|
||||
|
||||
int idx = 1;
|
||||
|
||||
for (int t = 0; t < numThreads; ++t)
|
||||
{
|
||||
int startIdx = idx;
|
||||
int count = base + (t < remainder ? 1 : 0);
|
||||
int endIdx = idx + count - 1;
|
||||
idx = endIdx + 1;
|
||||
|
||||
threads.emplace_back([&, t, startIdx, endIdx]()
|
||||
{
|
||||
int localCount = 0;
|
||||
for (int i = startIdx; i <= endIdx; ++i)
|
||||
if (messungen[i] > messungen[i - 1])
|
||||
++localCount;
|
||||
|
||||
results[t] = localCount;
|
||||
});
|
||||
}
|
||||
|
||||
for (auto& th : threads)
|
||||
th.join();
|
||||
|
||||
int total = 0;
|
||||
for (int r : results)
|
||||
total += r;
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
// =====================
|
||||
// main
|
||||
// =====================
|
||||
int main()
|
||||
{
|
||||
std::vector<int> messungen;
|
||||
|
||||
// ===== Variante A: Datei =====
|
||||
readFile("measurements.txt", messungen);
|
||||
|
||||
// ===== Variante B: künstliche Daten (statt Datei) =====
|
||||
/*
|
||||
int value = 0;
|
||||
for (size_t i = 0; i < 100000000; ++i)
|
||||
messungen.push_back(value += (rand() % 3 - 1));
|
||||
*/
|
||||
|
||||
// ===== Seriell =====
|
||||
auto start = std::chrono::steady_clock::now();
|
||||
int serialResult = countSerial(messungen);
|
||||
auto end = std::chrono::steady_clock::now();
|
||||
|
||||
std::chrono::duration<double> serialTime = end - start;
|
||||
std::cout << "Seriell: " << serialResult
|
||||
<< " | Took: " << serialTime.count() << " s\n";
|
||||
|
||||
// ===== Parallel =====
|
||||
int numThreads = std::thread::hardware_concurrency();
|
||||
if (numThreads == 0) numThreads = 4;
|
||||
|
||||
start = std::chrono::steady_clock::now();
|
||||
int parallelResult = countParallel(messungen, numThreads);
|
||||
end = std::chrono::steady_clock::now();
|
||||
|
||||
std::chrono::duration<double> parallelTime = end - start;
|
||||
std::cout << "Parallel: " << parallelResult
|
||||
<< " | Took: " << parallelTime.count() << " s\n";
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user