Added user interface

This commit is contained in:
Legaeli 2025-11-25 11:24:28 +01:00
parent 9b3e642475
commit c0c25360cb
6 changed files with 6124 additions and 3 deletions

View File

@ -17,6 +17,8 @@ set(SRC_FILES
${CMAKE_CURRENT_LIST_DIR}/gamecube.cpp
${CMAKE_CURRENT_LIST_DIR}/gamematrix.cpp
${CMAKE_CURRENT_LIST_DIR}/createCube.cpp
${CMAKE_CURRENT_LIST_DIR}/userinterface.cpp
${CMAKE_CURRENT_LIST_DIR}/raygui_impl.cpp
)
set(INCLUDE_DIRS

View File

@ -1,5 +1,6 @@
#include "gamecube.h"
#include "createCube.h"
#include "userinterface.h"
#include <algorithm>
#include <ctime>
@ -8,6 +9,7 @@
// -----------------------------------------------------------
int main()
{
UserInterface userInterface;
//CHRIS WAR HIER
//AXIOM WAR HIER
// Zufall initialisieren
@ -24,8 +26,23 @@ int main()
camera.fovy = 45.0f;
camera.projection = CAMERA_PERSPECTIVE;
int cubePairs = 7;
if (cubePairs > 10 || cubePairs <= 1) cubePairs = 3;
//TODO: Hier die Zeit abrufen.
double currentScoreTime = 11.42;
double highScoreTime = 15.41;
//TODO: Hier die Anzahl der Züge abrufen.
int currentScoreTurns = 7;
int highScoreTurns = 3;
if (currentScoreTime <= highScoreTime) highScoreTime = currentScoreTime;
if (currentScoreTime <= highScoreTurns) highScoreTurns = currentScoreTurns;
int cubePairs = userInterface.getCubeCount();
if (cubePairs <= 0) {
userInterface.showMenu(currentScoreTime, highScoreTime, currentScoreTurns, highScoreTurns);
cubePairs = userInterface.getCubeCount();
}
std::vector<Vec3> positions =createCubes(cubePairs);
// Nur 3 Farben für 3 Paare
@ -119,6 +136,8 @@ int main()
// -----------------------------------------------------------
// Zeichnen
// -----------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
BeginMode3D(camera);
@ -128,8 +147,17 @@ int main()
EndMode3D();
if (gameWon)
if (gameWon) {
DrawText("Congrats! You found all pairs!", 150, 260, 30, DARKBLUE);
//TODO: Neue Scores zuweisen, current genügen.
currentScoreTime = 17.3;
currentScoreTurns = 10;
if (currentScoreTime <= highScoreTime) highScoreTime = currentScoreTime;
if (currentScoreTurns <= highScoreTurns) highScoreTurns = currentScoreTurns;
userInterface.showScore(currentScoreTime, highScoreTime, currentScoreTurns, highScoreTurns);
}
else
DrawText("Flip 2 cubes - find matching pairs!", 10, 10, 20, DARKGRAY);

2
raygui_impl.cpp Normal file
View File

@ -0,0 +1,2 @@
#define RAYGUI_IMPLEMENTATION
#include "raygui.h"

5994
raylib/raygui.h Normal file

File diff suppressed because it is too large Load Diff

75
userinterface.cpp Normal file
View File

@ -0,0 +1,75 @@
#include "userinterface.h"
#include "raylib.h"
#include "raygui.h"
#include <iostream>
#include <cstring>
#include <format>
int UserInterface::getCubeCount() {
return cubeCount;
};
void UserInterface::showMenu(double &currentScoreTime, double &highScoreTime, int &currentScoreTurns, int &highScoreTurns) {
char textInput[3] = "3";
menuOpen = true;
Rectangle inputBox = {300, 250, 200, 50};
while (menuOpen && !WindowShouldClose()) {
BeginDrawing();
ClearBackground(RAYWHITE);
showScore(currentScoreTime, highScoreTime, currentScoreTurns, highScoreTurns);
if (wrongInput) {
DrawText("Falsche Eingabe.\nWie viele Würfelpaare? (2-10)", 220, 180, 20, DARKGRAY);
} else {
DrawText("Wie viele Würfelpaare? (2-10)", 220, 180, 20, DARKGRAY);
}
GuiTextBox(inputBox, textInput, 3, true);
if (IsKeyPressed(KEY_ENTER)) {
if (!(std::atoi(textInput) > 10 || std::atoi(textInput) <= 1)) {
menuOpen = false;
cubeCount = std::atoi(textInput);
} else {
wrongInput = true;
}
}
EndDrawing();
}
}
void UserInterface::showScore(double &currentScoreTime, double &highScoreTime, int &currentScoreTurns, int &highScoreTurns) {
Color currentScoreTimeColor = RED;
Color highScoreTimeColor = GREEN;
Color currentScoreTurnsColor = RED;
Color highScoreTurnsColor = GREEN;
if (currentScoreTime <= highScoreTime) {
currentScoreTimeColor = GREEN;
} else if (currentScoreTime < highScoreTime) {
currentScoreTimeColor = RED;
}
if (currentScoreTurns <= highScoreTurns) {
currentScoreTurnsColor = GREEN;
} else if (currentScoreTurns > highScoreTurns) {
currentScoreTurnsColor = RED;
}
if (!menuOpen) {
std::string currentTimeOutput = std::format("Deine Zeit: {:.2f}", currentScoreTime);
DrawText(currentTimeOutput.c_str(), 220, 100, 20, currentScoreTimeColor);
std::string currentTurnsOutput = "Deine Züge: " + std::to_string(currentScoreTurns);
DrawText(currentTurnsOutput.c_str(), 440, 100, 20, currentScoreTurnsColor);
}
std::string highTimeOutput = std::format("Beste Zeit: {:.2f}", highScoreTime);
DrawText(highTimeOutput.c_str(), 220, 120, 20, highScoreTimeColor);
std::string highTurnsOutput = "Wenigste Züge: " + std::to_string(highScoreTurns);
DrawText(highTurnsOutput.c_str(), 440, 120, 20, highScoreTurnsColor);
}

20
userinterface.h Normal file
View File

@ -0,0 +1,20 @@
#pragma once
class UserInterface {
public:
int getCubeCount();
void showMenu(double &currentScoreTime, double &highScoreTime, int &currentScoreTurns, int &highScoreTurns);
void showScore(double &currentScoreTime, double &highScoreTime, int &currentScoreTurns, int &highScoreTurns);
bool menuOpen = false;
private:
int cubeCount = 0;
bool wrongInput = false;
};
#ifndef USERINTERFACE_H
#define USERINTERFACE_H
#endif //USERINTERFACE_H