11 Commits
Author SHA1 Message Date
PapiBigSzill c874f8b517 Menu für 3, 6 Paare hingefügt 2025-12-01 13:00:03 +01:00
bhattial100541 bc4f4f743d some changes 2025-12-01 12:09:43 +01:00
Sladoje f954d09a29 added timer in main.cpp 2025-12-01 11:58:51 +01:00
Sladoje f79648ea47 Merge branch 'main' into project_tester 2025-11-17 12:33:25 +01:00
Sladoje b8f8b1c18d test funktioniert 2025-11-17 12:30:07 +01:00
bakeevato99733 1e1a9ab8d9 Merge branch 'main' into project_developer 2025-11-17 12:26:16 +01:00
bakeevato99733 54a44f9e53 fehlerkorrektur (namespace, gamecube) 2025-11-17 12:08:36 +01:00
bhattial100541 e72d51f3b2 hi 2025-11-13 13:08:02 +01:00
bhattial100541 2170001875 adding requirements 2025-11-03 13:04:14 +01:00
bhattial100541 a2d77869a1 adding requirements 2025-11-03 13:03:48 +01:00
bhattial100541 93ea5ae8d1 Add requirements.txt 2025-11-03 11:59:18 +00:00
10 changed files with 389 additions and 107 deletions
Vendored
BIN
View File
Binary file not shown.
+1
View File
@@ -0,0 +1 @@
.idea/
+8
View File
@@ -0,0 +1,8 @@
# Default ignored files
/shelf/
/workspace.xml
# Editor-based HTTP Client requests
/httpRequests/
# Datasource local storage ignored files
/dataSources/
/dataSources.local.xml
Generated
+4
View File
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings" defaultProject="true" />
</project>
+25 -11
View File
@@ -17,9 +17,9 @@ set(SRC_FILES
src/gamematrix.cpp src/gamematrix.cpp
) )
#set(INCLUDE_DIRS set(INCLUDE_DIRS
# ${CMAKE_CURRENT_LIST_DIR}/linux ${CMAKE_CURRENT_LIST_DIR}/includes
#) )
add_executable(${EXECUTABLE_NAME} ${SRC_FILES}) add_executable(${EXECUTABLE_NAME} ${SRC_FILES})
#target_include_directories(${EXECUTABLE_NAME} PRIVATE ${INCLUDE_DIRS}) #target_include_directories(${EXECUTABLE_NAME} PRIVATE ${INCLUDE_DIRS})
@@ -29,16 +29,30 @@ target_include_directories(Prog3B PRIVATE
) )
target_link_libraries(${EXECUTABLE_NAME} PRIVATE target_link_libraries(${EXECUTABLE_NAME} PRIVATE
#${CMAKE_CURRENT_LIST_DIR}/windows/libgamematrix.a #${CMAKE_CURRENT_LIST_DIR}/windows/libgamematrix.a
${CMAKE_CURRENT_LIST_DIR}/windows/libraylib.a ${CMAKE_CURRENT_LIST_DIR}/mac_arm/libraylib.a
opengl32
gdi32
m
winmm
) )
# Checks if OSX and links appropriate frameworks (Only required on MacOS) # Checks if OSX and links appropriate frameworks (Only required on MacOS)
if (APPLE) if (APPLE)
target_link_libraries(Prog3B "-framework IOKit") target_link_libraries(Prog3B PRIVATE "-framework IOKit"
target_link_libraries(Prog3B "-framework Cocoa") "-framework Cocoa"
target_link_libraries(Prog3B "-framework OpenGL") "-framework OpenGL"
)
endif() endif()
add_executable(tests
${CMAKE_CURRENT_LIST_DIR}/src/tests.cpp
${CMAKE_CURRENT_LIST_DIR}/src/gamematrix.cpp
)
target_include_directories(tests PRIVATE ${INCLUDE_DIRS})
target_link_libraries(tests PRIVATE)
#if (APPLE)
#target_link_libraries(Prog3B PRIVATE "-framework IOKit")
#target_link_libraries(Prog3B PRIVATE "-framework Cocoa")
#target_link_libraries(Prog3B PRIVATE "-framework OpenGL")
#endif()
Submodule
+1
Submodule Prog3b_651 added at 2170001875
+20
View File
@@ -0,0 +1,20 @@
Projekt: .wuerfelmemory
Datum: 03.11.2025
Team(Rollen):Projektleiter: Alina.B
Architekt: Alex.S
Entwickler: Tomila.B
Tester: Elisa.S
1.Projektziel:
| Funktion | Eingabe | Ausgabe | Kurzbeschreibung |
|---------------|------------------------------------|-----------------------|----------------------------------------|
| matmul | 4x4 Matrix A, 4x4 Matrix B | 4x4 Matrix | |
| translate | 3D Vektor | 4x4 Matrix | |
| rot3D | Winkel in °, Rotationsachse (x/y/z)| 4x4 Matrix | |
Dokumentation:
+3 -3
View File
@@ -39,11 +39,11 @@ void gamecube::Draw() const
rlPushMatrix(); rlPushMatrix();
// Matrizen für Rotation und Translation erzeugen // Matrizen für Rotation und Translation erzeugen
auto matrix_a = gameMatrix::translate({ position.x, position.y, position.z}); auto matrix_a = Matrix3D::gameMatrix::translate({ position.x, position.y, position.z});
auto matrix_b = gameMatrix::rot3D(rotation, 'y'); auto matrix_b = Matrix3D::gameMatrix::rot3D(rotation, 'y');
// Matrizen multiplizieren (Translation * Rotation) // Matrizen multiplizieren (Translation * Rotation)
auto model = gameMatrix::matmul(matrix_a, matrix_b); auto model = Matrix3D::gameMatrix::matmul(matrix_a, matrix_b);
// transform for raylib matrix // transform for raylib matrix
float f[16]; float f[16];
+321 -87
View File
@@ -1,14 +1,210 @@
#include "gamecube.h" #include "gamecube.h"
#include <algorithm> #include <algorithm>
#include <ctime> #include <ctime>
#include <vector>
#include "raylib.h" // Stellen Sie sicher, dass raylib.h hier oder in gamecube.h inkludiert ist
// ----------------------------------------------------------- // -----------------------------------------------------------
// 3D Memory Game – Hauptprogramm // 3D Memory Game – Hauptprogramm
// ----------------------------------------------------------- // -----------------------------------------------------------
enum GameScreen {MENU = 0, GAMEPLAY};
void SetupGame(std::vector<gamecube>& cubes, int pairs)
{
cubes.clear();
Color colors[] = {RED, GREEN, BLUE, YELLOW, ORANGE, PURPLE, WHITE, SKYBLUE};
std::vector<Vec3> positions;
int count = pairs * 2;
int cols = 3;
int rows = 2;
if (count > 6) {
cols = 4;
rows = 3;
}
int index = 0;
// Generiert Positionen basierend auf der Größe
for (int r = 0; r < rows && index < count; ++r) {
for (int c = 0; c < cols && index < count; ++c) {
// Zentriert die Würfel um (0,0,0)
positions.push_back({(float)c * 2.0f - (cols -1 ), 0.0f, (float)r * 2.0f - (rows -1)});
index++;
}
}
std::vector<Color> colorPool;
for (int i = 0; i < pairs; i++) {
colorPool.push_back(colors[i]);
colorPool.push_back(colors[i]);
}
// Fisher-Yates Shuffle
for (int i= colorPool.size() -1; i > 0; --i) {
int j = rand() % (i + 1);
std::swap(colorPool[i], colorPool[j]);
}
// Würfel erstellen
for (int i = 0; i < count; i++)
cubes.emplace_back(positions[i], colorPool[i]);
}
int main() int main()
{ {
// Zufall initialisieren // Zufall initialisieren#include "gamecube.h"
//#include <algorithm>
//#include <ctime>
//
//// -----------------------------------------------------------
//// 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);
//
// 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))
// {
// 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)
// {
// 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);
//
// EndDrawing();
// }
//
// CloseWindow();
// return 0;
//}
srand(time(NULL)); srand(time(NULL));
double startTime = 0.0;
double endTime = 0.0;
bool timerStarted = false;
GameScreen currentScreen = MENU;
int selectedPairs = 3;
// 1. SPIELSPEZIFISCHE VARIABLEN HIER DEKLARIEREN (ohne Initialisierung)
std::vector<gamecube> cubes;
gamecube* first = nullptr;
gamecube* second = nullptr;
float flipSpeed = 5.0f; // Drehgeschwindigkeit
bool gameWon = false;
// Fenster und Kamera // Fenster und Kamera
InitWindow(800, 600, "3D Memory Game with Matrix3D Library"); InitWindow(800, 600, "3D Memory Game with Matrix3D Library");
@@ -21,112 +217,150 @@ int main()
camera.fovy = 45.0f; camera.fovy = 45.0f;
camera.projection = CAMERA_PERSPECTIVE; 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 // Hauptspielschleife
// ----------------------------------------------------------- // -----------------------------------------------------------
while (!WindowShouldClose()) while (!WindowShouldClose())
{ {
// Klick-Erkennung // -------------------------------------------------------
if (!gameWon && IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) // UPDATE-LOGIK NACH ZUSTAND
// -------------------------------------------------------
switch (currentScreen)
{ {
Vector2 mouse = GetMousePosition(); case MENU:
for (auto &c : cubes)
{ {
if (!c.IsFlipped() && !c.IsMatched()) // Menü-Abfrage: Auf Tastendruck warten
{ if (IsKeyPressed(KEY_THREE)) {
Vector2 screenPos = GetWorldToScreen({c.GetPosition().x, c.GetPosition().y, c.GetPosition().z}, camera); selectedPairs = 3; // 6 Würfel
SetupGame(cubes, selectedPairs);
if (fabs(mouse.x - screenPos.x) < 40 && fabs(mouse.y - screenPos.y) < 40) gameWon = false;
c.FlipForward(); first = second = nullptr;
currentScreen = GAMEPLAY;
timerStarted = false; // Timer-Reset
} else if (IsKeyPressed(KEY_SIX)) {
selectedPairs = 6; // 12 Würfel
SetupGame(cubes, selectedPairs);
gameWon = false;
first = second = nullptr;
currentScreen = GAMEPLAY;
timerStarted = false; // Timer-Reset
} }
break;
} }
}
// Animation aller Würfel case GAMEPLAY:
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; // Timer starten
else if (!second && &c != first) second = &c; if (!timerStarted)
} {
startTime = GetTime();
timerStarted = true;
}
// Klick-Erkennung
if (!gameWon && 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();
}
}
}
// Animation aller Würfel
for (auto &c : cubes)
{
c.Update(flipSpeed);
if (c.IsFlipped() && !c.IsMatched())
{
if (!first) first = &c;
else if (!second && &c != first) second = &c;
}
}
// Matching-Logik
if (first && second)
{
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)
{
// Prüft, ob ALLE Würfel gematcht sind
gameWon = std::all_of(cubes.begin(), cubes.end(), [](const gamecube &c){ return c.IsMatched(); });
if (gameWon)
{
endTime = GetTime() - startTime;
}
}
break;
} // ENDE GAMEPLAY UPDATE
} }
// Matching-Logik
if (first && second)
{
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 // ZEICHNEN NACH ZUSTAND
// ----------------------------------------------------------- // -----------------------------------------------------------
BeginDrawing(); BeginDrawing();
ClearBackground(RAYWHITE); ClearBackground(RAYWHITE);
BeginMode3D(camera);
for (auto &c : cubes) switch (currentScreen)
c.Draw(); {
case MENU:
{
// Menü-Darstellung
DrawText("3D MEMORY SPIEL", GetScreenWidth() / 2 - MeasureText("3D MEMORY SPIEL", 50) / 2, 80, 50, DARKGRAY);
DrawText("Waehlen Sie die Spielgroesse:", 50, 200, 25, BLACK);
DrawText("Druecken Sie [3] fuer 3 Paare (6 Wuerfel)", 50, 240, 20, BLUE);
DrawText("Druecken Sie [6] fuer 6 Paare (12 Wuerfel)", 50, 280, 20, BLUE);
break;
}
EndMode3D(); case GAMEPLAY:
{
// Spiel-Darstellung
BeginMode3D(camera);
if (gameWon) for (auto &c : cubes)
DrawText("Congrats! You found all pairs!", 150, 260, 30, DARKBLUE); c.Draw();
else
DrawText("Flip 2 cubes - find matching pairs!", 10, 10, 20, DARKGRAY); EndMode3D();
if (gameWon)
{
DrawText("Congrats! You found all pairs!", 150, 260, 30, DARKBLUE);
char buffer[64];
sprintf(buffer, "Cleared in %.2f seconds", endTime);
DrawText(buffer, 150, 300, 28, DARKGREEN);
}
else
{
DrawText("Flip 2 cubes - find matching pairs!", 10, 10, 20, DARKGRAY);
char liveBuf[64];
sprintf(liveBuf, "Time: %.2f", GetTime() - startTime);
DrawText(liveBuf, 10, 40, 20, DARKGRAY);
}
break;
} // ENDE GAMEPLAY DRAW
}
EndDrawing(); EndDrawing();
} }
+6 -6
View File
@@ -31,7 +31,7 @@ Vec3 applyMatrix(const Matrix4& M, const Vec3& v) {
void testMatmulIdentity() { void testMatmulIdentity() {
Matrix4 A = identity(); Matrix4 A = identity();
Matrix4 B = identity(); Matrix4 B = identity();
Matrix4 C = gameMatrix::matmul(A, B); Matrix4 C = Matrix3D::gameMatrix::matmul(A, B);
for (int i = 0; i < 4; i++) { for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) { for (int j = 0; j < 4; j++) {
@@ -48,7 +48,7 @@ void testMatmulIdentity() {
void testTranslate() { void testTranslate() {
Vec3 pos{1,2,3}; Vec3 pos{1,2,3};
Matrix4 T = gameMatrix::translate(pos); Matrix4 T = Matrix3D::gameMatrix::translate(pos);
if (eq(T[0][3], 1) && eq(T[1][3], 2) && eq(T[2][3], 3)) if (eq(T[0][3], 1) && eq(T[1][3], 2) && eq(T[2][3], 3))
std::cout << "[OK] translate\n"; std::cout << "[OK] translate\n";
@@ -58,7 +58,7 @@ void testTranslate() {
void testRotZ90() { void testRotZ90() {
Vec3 v{1,0,0}; Vec3 v{1,0,0};
Matrix4 R = gameMatrix::rot3D(90, 'z'); Matrix4 R = Matrix3D::gameMatrix::rot3D(90, 'z');
Vec3 r = applyMatrix(R, v); Vec3 r = applyMatrix(R, v);
if (eq(r[0], 0) && eq(r[1], 1) && eq(r[2], 0)) if (eq(r[0], 0) && eq(r[1], 1) && eq(r[2], 0))
@@ -69,7 +69,7 @@ void testRotZ90() {
void testRotX180() { void testRotX180() {
Vec3 v{0,1,0}; Vec3 v{0,1,0};
Matrix4 R = gameMatrix::rot3D(180, 'x'); Matrix4 R = Matrix3D::gameMatrix::rot3D(180, 'x');
Vec3 r = applyMatrix(R, v); Vec3 r = applyMatrix(R, v);
if (eq(r[0], 0) && eq(r[1], -1) && eq(r[2], 0)) if (eq(r[0], 0) && eq(r[1], -1) && eq(r[2], 0))
@@ -80,10 +80,10 @@ void testRotX180() {
void testRotY270() { void testRotY270() {
Vec3 v{1,0,0}; Vec3 v{1,0,0};
Matrix4 R = gameMatrix::rot3D(270, 'y'); Matrix4 R = Matrix3D::gameMatrix::rot3D(270, 'y');
Vec3 r = applyMatrix(R, v); Vec3 r = applyMatrix(R, v);
if (eq(r[0], 0) && eq(r[1], 0) && eq(r[2], -1)) if (eq(r[0], 0) && eq(r[1], 0) && eq(r[2], 1))
std::cout << "[OK] rotY 270°\n"; std::cout << "[OK] rotY 270°\n";
else else
std::cout << "[FAIL] rotY 270°\n"; std::cout << "[FAIL] rotY 270°\n";