Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c6cdebfc84 | ||
|
|
aa5ca11829 | ||
|
|
c0c25360cb | ||
|
|
9b3e642475 |
Generated
+19
-10
@@ -7,6 +7,7 @@
|
||||
<option name="/Default/RiderDebugger/RiderRestoreDecompile/RestoreDecompileSetting/@EntryValue" value="false" type="bool" />
|
||||
<option name="/Default/Housekeeping/GlobalSettingsUpgraded/IsUpgraded/@EntryValue" value="true" type="bool" />
|
||||
<option name="/Default/Housekeeping/FeatureSuggestion/FeatureSuggestionManager/DisabledSuggesters/=SwitchToGoToActionSuggester/@EntryIndexedValue" value="true" type="bool" />
|
||||
<option name="/Default/Housekeeping/FeatureSuggestion/FeatureSuggestionManager/DisabledSuggesters/=SwitchToGoToActionSuggester/@EntryIndexRemoved" />
|
||||
</component>
|
||||
<component name="CMakePresetLoader">{
|
||||
"useNewFormat": true
|
||||
@@ -30,12 +31,11 @@
|
||||
</component>
|
||||
<component name="ChangeListManager">
|
||||
<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$/CMakeLists.txt" beforeDir="false" afterPath="$PROJECT_DIR$/CMakeLists.txt" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/Highscores.txt" beforeDir="false" afterPath="$PROJECT_DIR$/Highscores.txt" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/ScoreManager.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/ScoreManager.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/main.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/main.cpp" afterDir="false" />
|
||||
<change beforePath="$PROJECT_DIR$/userinterface.cpp" beforeDir="false" afterPath="$PROJECT_DIR$/userinterface.cpp" afterDir="false" />
|
||||
</list>
|
||||
<option name="SHOW_DIALOG" value="false" />
|
||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||
@@ -49,6 +49,18 @@
|
||||
<component name="Git.Settings">
|
||||
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
|
||||
</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">
|
||||
<option name="ide" value="CLion" />
|
||||
<option name="majorVersion" value="2024" />
|
||||
@@ -75,7 +87,7 @@
|
||||
"RunOnceActivity.west.config.association.type.startup.service": "true",
|
||||
"cf.first.check.clang-format": "false",
|
||||
"cidr.known.project.marker": "true",
|
||||
"git-widget-placeholder": "Flexible-cube-count",
|
||||
"git-widget-placeholder": "Zeit__zaeler",
|
||||
"last_opened_file_path": "C:/Desktop/StudiumME/3.Sem/Prog3/B/MatrixPybind",
|
||||
"node.js.detected.package.eslint": "true",
|
||||
"node.js.detected.package.tslint": "true",
|
||||
@@ -86,11 +98,6 @@
|
||||
}
|
||||
}]]></component>
|
||||
<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">
|
||||
<method v="2">
|
||||
<option name="com.jetbrains.cidr.execution.CidrBuildBeforeRunTaskProvider$BuildBeforeRunTask" enabled="true" />
|
||||
@@ -118,6 +125,8 @@
|
||||
<workItem from="1763652636624" duration="1226000" />
|
||||
<workItem from="1763653877709" duration="28000" />
|
||||
<workItem from="1763895078693" duration="5675000" />
|
||||
<workItem from="1764526482502" duration="8000" />
|
||||
<workItem from="1764526493477" duration="4519000" />
|
||||
</task>
|
||||
<servers />
|
||||
</component>
|
||||
|
||||
@@ -17,6 +17,9 @@ 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
|
||||
${CMAKE_CURRENT_LIST_DIR}/ScoreManager.cpp
|
||||
)
|
||||
|
||||
set(INCLUDE_DIRS
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
11.34
|
||||
@@ -0,0 +1,43 @@
|
||||
#include "ScoreManager.h"
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
|
||||
ScoreManager::ScoreManager(const std::string& filename) : highscoreFile(filename)
|
||||
{
|
||||
std::cout << "test";
|
||||
loadHighscore();
|
||||
}
|
||||
|
||||
void ScoreManager::loadHighscore() {
|
||||
std::ifstream file(highscoreFile);
|
||||
if (file.is_open()) {
|
||||
int value;
|
||||
if (file >> value) {
|
||||
if (value > 0) highScore = value;
|
||||
}
|
||||
file.close();
|
||||
} else {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
void ScoreManager::incrementScore() {
|
||||
currentScore++;
|
||||
}
|
||||
|
||||
void ScoreManager::resetScore() {
|
||||
currentScore = 0;
|
||||
}
|
||||
|
||||
void ScoreManager::saveHighScore() {
|
||||
if (highScore == std::numeric_limits<int>::max()) return;
|
||||
std::ofstream file(highscoreFile);
|
||||
|
||||
if (file.is_open()) {
|
||||
file << highScore;
|
||||
file.close();
|
||||
} else {
|
||||
std::cerr << "Error: Could not write to highscore file" << std::endl;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
#include <string>
|
||||
#include <limits>
|
||||
|
||||
class ScoreManager {
|
||||
public:
|
||||
ScoreManager(const std::string& filename);
|
||||
|
||||
void incrementScore();
|
||||
void resetScore();
|
||||
void saveHighScore();
|
||||
int getCurrentScore() const { return currentScore; }
|
||||
int getHighScore() const { return (highScore == std::numeric_limits<int>::max()) ? 0 : highScore; }
|
||||
|
||||
private:
|
||||
int currentScore = 0;
|
||||
int highScore = std::numeric_limits<int>::max();
|
||||
std::string highscoreFile;
|
||||
void loadHighscore();
|
||||
};
|
||||
@@ -3,12 +3,6 @@
|
||||
|
||||
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<Vec3> cubePositions;
|
||||
//std::cout<<(fieldSize[0])<<std::endl;
|
||||
@@ -48,7 +42,6 @@ std::vector<int> calculateFieldSize(int pairs)
|
||||
|
||||
std::vector<Color> getColors(int pairs)
|
||||
{
|
||||
if (pairs >10) pairs = 10;
|
||||
std::vector<Color> returnColors;
|
||||
Color colors[] = {
|
||||
{230, 25, 75, 255}, // Red
|
||||
|
||||
@@ -1,13 +1,20 @@
|
||||
#include "gamecube.h"
|
||||
#include "createCube.h"
|
||||
#include "userinterface.h"
|
||||
#include <algorithm>
|
||||
#include <ctime>
|
||||
#include <iostream>
|
||||
|
||||
#include "ScoreManager.h"
|
||||
|
||||
// -----------------------------------------------------------
|
||||
// 3D Memory Game – Hauptprogramm
|
||||
// -----------------------------------------------------------
|
||||
int main()
|
||||
{
|
||||
UserInterface userInterface;
|
||||
ScoreManager score("Highscores.txt");
|
||||
|
||||
//CHRIS WAR HIER
|
||||
//AXIOM WAR HIER
|
||||
// Zufall initialisieren
|
||||
@@ -24,7 +31,26 @@ int main()
|
||||
camera.fovy = 45.0f;
|
||||
camera.projection = CAMERA_PERSPECTIVE;
|
||||
|
||||
int cubePairs = 3; //Cube count => 2*cubePairs
|
||||
//TODO: Hier die Zeit abrufen.
|
||||
double currentScoreTime = 0.0;
|
||||
double startTime = 0.0;
|
||||
double highScoreTime = 43.4;
|
||||
|
||||
//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);
|
||||
|
||||
// Nur 3 Farben für 3 Paare
|
||||
@@ -73,7 +99,13 @@ 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)
|
||||
{
|
||||
c.FlipForward();
|
||||
score.incrementScore();
|
||||
currentScoreTurns = score.getCurrentScore() / 2;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -94,6 +126,7 @@ int main()
|
||||
// Matching-Logik
|
||||
if (first && second)
|
||||
{
|
||||
//currentScoreTurns = score.getCurrentScore();
|
||||
Color col1 = first->GetColor();
|
||||
Color col2 = second->GetColor();
|
||||
|
||||
@@ -115,9 +148,17 @@ int main()
|
||||
if (!gameWon)
|
||||
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
|
||||
// -----------------------------------------------------------
|
||||
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(RAYWHITE);
|
||||
BeginMode3D(camera);
|
||||
@@ -127,11 +168,22 @@ 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;
|
||||
score.saveHighScore();
|
||||
userInterface.showScore(currentScoreTime, highScoreTime, currentScoreTurns, highScoreTurns);
|
||||
}
|
||||
else
|
||||
DrawText("Flip 2 cubes - find matching pairs!", 10, 10, 20, DARKGRAY);
|
||||
|
||||
|
||||
EndDrawing();
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
#define RAYGUI_IMPLEMENTATION
|
||||
#include "raygui.h"
|
||||
+5994
File diff suppressed because it is too large
Load Diff
@@ -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);
|
||||
|
||||
}
|
||||
|
||||
@@ -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
|
||||
Reference in New Issue
Block a user