Compare commits
7 Commits
Flexible-c
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
58ff9f2e63 | ||
|
|
a4b18d1207 | ||
|
|
ef779381a6 | ||
|
|
c6cdebfc84 | ||
|
|
aa5ca11829 | ||
|
|
c0c25360cb | ||
|
|
9b3e642475 |
65
.idea/workspace.xml
generated
65
.idea/workspace.xml
generated
@ -30,11 +30,8 @@
|
|||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="db070755-9708-4a46-a9cb-e7c4dc1bfb77" name="Changes" comment="">
|
<list default="true" id="db070755-9708-4a46-a9cb-e7c4dc1bfb77" name="Changes" comment="">
|
||||||
<change afterPath="$PROJECT_DIR$/createCube.cpp" afterDir="false" />
|
|
||||||
<change afterPath="$PROJECT_DIR$/createCube.h" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/editor.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/editor.xml" afterDir="false" />
|
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/CMakeLists.txt" beforeDir="false" afterPath="$PROJECT_DIR$/CMakeLists.txt" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/gamecube.h" beforeDir="false" afterPath="$PROJECT_DIR$/gamecube.h" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/main.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/main.cpp" afterDir="false" />
|
<change beforePath="$PROJECT_DIR$/main.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/main.cpp" afterDir="false" />
|
||||||
</list>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
@ -49,6 +46,18 @@
|
|||||||
<component name="Git.Settings">
|
<component name="Git.Settings">
|
||||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||||
</component>
|
</component>
|
||||||
|
<component name="HighlightingSettingsPerFile">
|
||||||
|
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||||
|
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||||
|
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||||
|
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||||
|
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||||
|
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||||
|
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||||
|
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||||
|
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||||
|
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||||
|
</component>
|
||||||
<component name="ProjectApplicationVersion">
|
<component name="ProjectApplicationVersion">
|
||||||
<option name="ide" value="CLion" />
|
<option name="ide" value="CLion" />
|
||||||
<option name="majorVersion" value="2024" />
|
<option name="majorVersion" value="2024" />
|
||||||
@ -64,33 +73,28 @@
|
|||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="PropertiesComponent"><![CDATA[{
|
<component name="PropertiesComponent">{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"CMake Application.Prog3B.executor": "Run",
|
"CMake Application.Prog3B.executor": "Run",
|
||||||
"RunOnceActivity.RadMigrateCodeStyle": "true",
|
"RunOnceActivity.RadMigrateCodeStyle": "true",
|
||||||
"RunOnceActivity.ShowReadmeOnStart": "true",
|
"RunOnceActivity.ShowReadmeOnStart": "true",
|
||||||
"RunOnceActivity.cidr.known.project.marker": "true",
|
"RunOnceActivity.cidr.known.project.marker": "true",
|
||||||
"RunOnceActivity.git.unshallow": "true",
|
"RunOnceActivity.git.unshallow": "true",
|
||||||
"RunOnceActivity.readMode.enableVisualFormatting": "true",
|
"RunOnceActivity.readMode.enableVisualFormatting": "true",
|
||||||
"RunOnceActivity.west.config.association.type.startup.service": "true",
|
"RunOnceActivity.west.config.association.type.startup.service": "true",
|
||||||
"cf.first.check.clang-format": "false",
|
"cf.first.check.clang-format": "false",
|
||||||
"cidr.known.project.marker": "true",
|
"cidr.known.project.marker": "true",
|
||||||
"git-widget-placeholder": "Flexible-cube-count",
|
"git-widget-placeholder": "bug__fix__branch",
|
||||||
"last_opened_file_path": "C:/Desktop/StudiumME/3.Sem/Prog3/B/MatrixPybind",
|
"last_opened_file_path": "C:/Desktop/StudiumME/3.Sem/Prog3/B/MatrixPybind",
|
||||||
"node.js.detected.package.eslint": "true",
|
"node.js.detected.package.eslint": "true",
|
||||||
"node.js.detected.package.tslint": "true",
|
"node.js.detected.package.tslint": "true",
|
||||||
"node.js.selected.package.eslint": "(autodetect)",
|
"node.js.selected.package.eslint": "(autodetect)",
|
||||||
"node.js.selected.package.tslint": "(autodetect)",
|
"node.js.selected.package.tslint": "(autodetect)",
|
||||||
"nodejs_package_manager_path": "npm",
|
"nodejs_package_manager_path": "npm",
|
||||||
"vue.rearranger.settings.migration": "true"
|
"vue.rearranger.settings.migration": "true"
|
||||||
}
|
}
|
||||||
}]]></component>
|
}</component>
|
||||||
<component name="RunManager" selected="CMake Application.Prog3B">
|
<component name="RunManager" selected="CMake Application.Prog3B">
|
||||||
<configuration default="true" type="CLionExternalRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true">
|
|
||||||
<method v="2">
|
|
||||||
<option name="CLION.EXTERNAL.BUILD" enabled="true" />
|
|
||||||
</method>
|
|
||||||
</configuration>
|
|
||||||
<configuration name="Prog3B" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="Prog3B" TARGET_NAME="Prog3B" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="Prog3B" RUN_TARGET_NAME="Prog3B">
|
<configuration name="Prog3B" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true" PROJECT_NAME="Prog3B" TARGET_NAME="Prog3B" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="Prog3B" RUN_TARGET_NAME="Prog3B">
|
||||||
<method v="2">
|
<method v="2">
|
||||||
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
|
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
|
||||||
@ -118,6 +122,9 @@
|
|||||||
<workItem from="1763652636624" duration="1226000" />
|
<workItem from="1763652636624" duration="1226000" />
|
||||||
<workItem from="1763653877709" duration="28000" />
|
<workItem from="1763653877709" duration="28000" />
|
||||||
<workItem from="1763895078693" duration="5675000" />
|
<workItem from="1763895078693" duration="5675000" />
|
||||||
|
<workItem from="1764526482502" duration="8000" />
|
||||||
|
<workItem from="1764526493477" duration="4519000" />
|
||||||
|
<workItem from="1765791349412" duration="635000" />
|
||||||
</task>
|
</task>
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@ -17,6 +17,9 @@ set(SRC_FILES
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/gamecube.cpp
|
${CMAKE_CURRENT_LIST_DIR}/gamecube.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/gamematrix.cpp
|
${CMAKE_CURRENT_LIST_DIR}/gamematrix.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/createCube.cpp
|
${CMAKE_CURRENT_LIST_DIR}/createCube.cpp
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/userinterface.cpp
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/raygui_impl.cpp
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/ScoreManager.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(INCLUDE_DIRS
|
set(INCLUDE_DIRS
|
||||||
|
|||||||
2
Highscores.txt
Normal file
2
Highscores.txt
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
score 99
|
||||||
|
time 99999.99
|
||||||
72
ScoreManager.cpp
Normal file
72
ScoreManager.cpp
Normal file
@ -0,0 +1,72 @@
|
|||||||
|
#include "ScoreManager.h"
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
ScoreManager::ScoreManager(const std::string& filename) : highscoreFile(filename) {
|
||||||
|
loadHighscore();
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScoreManager::loadHighscore() {
|
||||||
|
std::ifstream file(highscoreFile);
|
||||||
|
|
||||||
|
if (!file.is_open()) {
|
||||||
|
std::cout << "No highscore file found, creating new file.\n";
|
||||||
|
highScore = 9999;
|
||||||
|
bestTime = 99999.99;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string key;
|
||||||
|
while (file >> key) {
|
||||||
|
if (key == "score") file >> highScore;
|
||||||
|
else if (key == "time") file >> bestTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
// If file contains useless values (like old format), reset
|
||||||
|
if (highScore <= 0 || highScore > 9999) highScore = 9999;
|
||||||
|
if (bestTime <= 0 || bestTime > 99999.99) bestTime = 99999.99;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void ScoreManager::incrementScore() {
|
||||||
|
currentScore++;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScoreManager::resetScore() {
|
||||||
|
currentScore = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ScoreManager::saveHighScore(int finalScore, double finalTime) {
|
||||||
|
bool updated = false;
|
||||||
|
|
||||||
|
if (finalScore < highScore) {
|
||||||
|
highScore = finalScore;
|
||||||
|
updated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (finalTime < bestTime) {
|
||||||
|
bestTime = finalTime;
|
||||||
|
updated = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// For safety: If file was default → always write
|
||||||
|
if (highScore == 9999 && bestTime == 99999.99)
|
||||||
|
updated = true;
|
||||||
|
|
||||||
|
if (!updated) return;
|
||||||
|
|
||||||
|
std::ofstream file(highscoreFile);
|
||||||
|
if (!file.is_open()) {
|
||||||
|
std::cerr << "❌ ERROR: Can't write highscore file\n";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
file << "score " << highScore << "\n";
|
||||||
|
file << "time " << bestTime << "\n";
|
||||||
|
file.close();
|
||||||
|
|
||||||
|
std::cout << "✅ Highscore updated!\n";
|
||||||
|
}
|
||||||
|
|
||||||
25
ScoreManager.h
Normal file
25
ScoreManager.h
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
|
class ScoreManager {
|
||||||
|
public:
|
||||||
|
ScoreManager(const std::string& filename);
|
||||||
|
|
||||||
|
void incrementScore();
|
||||||
|
void resetScore();
|
||||||
|
void saveHighScore(int finalScore, double finalTime);
|
||||||
|
|
||||||
|
int getCurrentScore() const { return currentScore; }
|
||||||
|
int getHighScore() const { return highScore; }
|
||||||
|
double getBestTime() const { return bestTime; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
int currentScore = 0;
|
||||||
|
int highScore = std::numeric_limits<int>::max();
|
||||||
|
double bestTime = std::numeric_limits<double>::max();
|
||||||
|
|
||||||
|
std::string highscoreFile;
|
||||||
|
|
||||||
|
void loadHighscore();
|
||||||
|
};
|
||||||
@ -3,12 +3,6 @@
|
|||||||
|
|
||||||
std::vector<Vec3> createCubes(int pairs)
|
std::vector<Vec3> createCubes(int pairs)
|
||||||
{
|
{
|
||||||
//zwei bis zehn paare
|
|
||||||
if (pairs >10 || pairs <= 1)
|
|
||||||
{
|
|
||||||
// 6 Karten-Positionen im 3x2 Raster
|
|
||||||
return {{-2, 0, -2}, {0, 0, -2}, {2, 0, -2},{-2, 0, 0}, {0, 0, 0}, {2, 0, 0}}; // Default field
|
|
||||||
}
|
|
||||||
std::vector<int> fieldSize = calculateFieldSize(pairs);
|
std::vector<int> fieldSize = calculateFieldSize(pairs);
|
||||||
std::vector<Vec3> cubePositions;
|
std::vector<Vec3> cubePositions;
|
||||||
//std::cout<<(fieldSize[0])<<std::endl;
|
//std::cout<<(fieldSize[0])<<std::endl;
|
||||||
@ -48,7 +42,6 @@ std::vector<int> calculateFieldSize(int pairs)
|
|||||||
|
|
||||||
std::vector<Color> getColors(int pairs)
|
std::vector<Color> getColors(int pairs)
|
||||||
{
|
{
|
||||||
if (pairs >10) pairs = 10;
|
|
||||||
std::vector<Color> returnColors;
|
std::vector<Color> returnColors;
|
||||||
Color colors[] = {
|
Color colors[] = {
|
||||||
{230, 25, 75, 255}, // Red
|
{230, 25, 75, 255}, // Red
|
||||||
|
|||||||
@ -32,3 +32,11 @@ private:
|
|||||||
bool flippingBackward = false;
|
bool flippingBackward = false;
|
||||||
float rotation = 0.0f;
|
float rotation = 0.0f;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
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
|
||||||
|
};
|
||||||
95
main.cpp
95
main.cpp
@ -1,13 +1,20 @@
|
|||||||
#include "gamecube.h"
|
#include "gamecube.h"
|
||||||
#include "createCube.h"
|
#include "createCube.h"
|
||||||
|
#include "userinterface.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "ScoreManager.h"
|
||||||
|
|
||||||
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
||||||
// 3D Memory Game – Hauptprogramm
|
// 3D Memory Game – Hauptprogramm
|
||||||
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
UserInterface userInterface;
|
||||||
|
ScoreManager score("Highscores.txt");
|
||||||
|
|
||||||
//CHRIS WAR HIER
|
//CHRIS WAR HIER
|
||||||
//AXIOM WAR HIER
|
//AXIOM WAR HIER
|
||||||
// Zufall initialisieren
|
// Zufall initialisieren
|
||||||
@ -24,10 +31,32 @@ int main()
|
|||||||
camera.fovy = 45.0f;
|
camera.fovy = 45.0f;
|
||||||
camera.projection = CAMERA_PERSPECTIVE;
|
camera.projection = CAMERA_PERSPECTIVE;
|
||||||
|
|
||||||
int cubePairs = 3; //Cube count => 2*cubePairs
|
GameState state = GameState::Idle;
|
||||||
|
|
||||||
|
|
||||||
|
//TODO: Hier die Zeit abrufen.
|
||||||
|
double currentScoreTime = 0.0;
|
||||||
|
double startTime = 0.0;
|
||||||
|
double highScoreTime = score.getBestTime();
|
||||||
|
|
||||||
|
//TODO: Hier die Anzahl der Züge abrufen.
|
||||||
|
int currentScoreTurns = 0;
|
||||||
|
int highScoreTurns = score.getHighScore();
|
||||||
|
|
||||||
|
//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();
|
||||||
|
// Startzeit speichern nach Enter
|
||||||
|
startTime = currentScoreTime;
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Vec3> positions =createCubes(cubePairs);
|
std::vector<Vec3> positions =createCubes(cubePairs);
|
||||||
|
|
||||||
// Nur 3 Farben für 3 Paare
|
// Nur x Farben für x Paare
|
||||||
std::vector<Color> colors= getColors(cubePairs);
|
std::vector<Color> colors= getColors(cubePairs);
|
||||||
|
|
||||||
|
|
||||||
@ -62,7 +91,11 @@ int main()
|
|||||||
while (!WindowShouldClose())
|
while (!WindowShouldClose())
|
||||||
{
|
{
|
||||||
// Klick-Erkennung
|
// Klick-Erkennung
|
||||||
if (!gameWon && IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
//if (!gameWon && IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||||
|
if (!gameWon
|
||||||
|
&& state != GameState::LockInput
|
||||||
|
&& state != GameState::CheckingMatch
|
||||||
|
&& IsMouseButtonPressed(MOUSE_LEFT_BUTTON))
|
||||||
{
|
{
|
||||||
Vector2 mouse = GetMousePosition();
|
Vector2 mouse = GetMousePosition();
|
||||||
|
|
||||||
@ -73,7 +106,27 @@ int main()
|
|||||||
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)
|
if (fabs(mouse.x - screenPos.x) < 40 && fabs(mouse.y - screenPos.y) < 40)
|
||||||
|
{
|
||||||
|
if (state == GameState::OneFlipped && first == &c)
|
||||||
|
break;
|
||||||
|
|
||||||
c.FlipForward();
|
c.FlipForward();
|
||||||
|
|
||||||
|
if (state == GameState::Idle)
|
||||||
|
{
|
||||||
|
first = &c;
|
||||||
|
state = GameState::OneFlipped;
|
||||||
|
}else if (state == GameState::OneFlipped && first != &c)
|
||||||
|
{
|
||||||
|
second = &c;
|
||||||
|
state = GameState::LockInput;
|
||||||
|
}
|
||||||
|
|
||||||
|
score.incrementScore();
|
||||||
|
currentScoreTurns = score.getCurrentScore() / 2;
|
||||||
|
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -82,18 +135,21 @@ int main()
|
|||||||
for (auto &c : cubes)
|
for (auto &c : cubes)
|
||||||
{
|
{
|
||||||
c.Update(flipSpeed);
|
c.Update(flipSpeed);
|
||||||
|
}
|
||||||
|
|
||||||
// Sobald ein Würfel vollständig umgedreht ist → merken
|
|
||||||
if (c.IsFlipped() && !c.IsMatched())
|
if (state == GameState::LockInput && first && second)
|
||||||
{
|
{
|
||||||
if (!first) first = &c;
|
if (first->GetRotationY() == 180.0f && second->GetRotationY() == 180.0f)
|
||||||
else if (!second && &c != first) second = &c;
|
{
|
||||||
|
state = GameState::CheckingMatch;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Matching-Logik
|
// Matching-Logik
|
||||||
if (first && second)
|
if (state == GameState::CheckingMatch && first && second)
|
||||||
{
|
{
|
||||||
|
//currentScoreTurns = score.getCurrentScore();
|
||||||
Color col1 = first->GetColor();
|
Color col1 = first->GetColor();
|
||||||
Color col2 = second->GetColor();
|
Color col2 = second->GetColor();
|
||||||
|
|
||||||
@ -109,15 +165,25 @@ int main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
first = second = nullptr;
|
first = second = nullptr;
|
||||||
|
state = GameState::Idle;
|
||||||
|
std::cout <<"unlock";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gewinnprüfung
|
// Gewinnprüfung
|
||||||
if (!gameWon)
|
if (!gameWon)
|
||||||
gameWon = std::all_of(cubes.begin(), cubes.end(), [](const gamecube &c){ return c.IsMatched(); });
|
gameWon = std::all_of(cubes.begin(), cubes.end(), [](const gamecube &c){ return c.IsMatched(); });
|
||||||
|
|
||||||
|
//Zeit Berechnung
|
||||||
|
if (!gameWon)
|
||||||
|
{
|
||||||
|
currentScoreTime = GetTime() - startTime;
|
||||||
|
DrawText(TextFormat("%.2f", currentScoreTime), 10, 30, 20, DARKGRAY);
|
||||||
|
}
|
||||||
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
||||||
// Zeichnen
|
// Zeichnen
|
||||||
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
@ -127,11 +193,22 @@ int main()
|
|||||||
|
|
||||||
EndMode3D();
|
EndMode3D();
|
||||||
|
|
||||||
if (gameWon)
|
if (gameWon) {
|
||||||
DrawText("Congrats! You found all pairs!", 150, 260, 30, DARKBLUE);
|
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;
|
||||||
|
score.saveHighScore(currentScoreTurns, currentScoreTime);
|
||||||
|
userInterface.showScore(currentScoreTime, highScoreTime, currentScoreTurns, highScoreTurns);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
DrawText("Flip 2 cubes - find matching pairs!", 10, 10, 20, DARKGRAY);
|
DrawText("Flip 2 cubes - find matching pairs!", 10, 10, 20, DARKGRAY);
|
||||||
|
|
||||||
|
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
2
raygui_impl.cpp
Normal file
2
raygui_impl.cpp
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
#define RAYGUI_IMPLEMENTATION
|
||||||
|
#include "raygui.h"
|
||||||
5994
raylib/raygui.h
Normal file
5994
raylib/raygui.h
Normal file
File diff suppressed because it is too large
Load Diff
77
userinterface.cpp
Normal file
77
userinterface.cpp
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
#include "userinterface.h"
|
||||||
|
#include "raylib.h"
|
||||||
|
#include "raygui.h"
|
||||||
|
#include <iostream>
|
||||||
|
#include <cstring>
|
||||||
|
#include <format>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
int UserInterface::getCubeCount() {
|
||||||
|
return cubeCount;
|
||||||
|
};
|
||||||
|
|
||||||
|
void UserInterface::showMenu(double ¤tScoreTime, double &highScoreTime, int ¤tScoreTurns, 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);
|
||||||
|
|
||||||
|
currentScoreTime = GetTime();
|
||||||
|
} else {
|
||||||
|
wrongInput = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EndDrawing();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void UserInterface::showScore(double ¤tScoreTime, double &highScoreTime, int ¤tScoreTurns, 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
20
userinterface.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
|
||||||
|
class UserInterface {
|
||||||
|
public:
|
||||||
|
int getCubeCount();
|
||||||
|
void showMenu(double ¤tScoreTime, double &highScoreTime, int ¤tScoreTurns, int &highScoreTurns);
|
||||||
|
void showScore(double ¤tScoreTime, double &highScoreTime, int ¤tScoreTurns, int &highScoreTurns);
|
||||||
|
|
||||||
|
bool menuOpen = false;
|
||||||
|
|
||||||
|
private:
|
||||||
|
int cubeCount = 0;
|
||||||
|
bool wrongInput = false;
|
||||||
|
};
|
||||||
|
|
||||||
|
#ifndef USERINTERFACE_H
|
||||||
|
#define USERINTERFACE_H
|
||||||
|
|
||||||
|
#endif //USERINTERFACE_H
|
||||||
Loading…
x
Reference in New Issue
Block a user