ScoreManager Score Part
This commit is contained in:
parent
c0c25360cb
commit
aa5ca11829
22
.idea/workspace.xml
generated
22
.idea/workspace.xml
generated
@ -30,9 +30,9 @@
|
|||||||
</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$/Highscores.txt" afterDir="false" />
|
||||||
<change afterPath="$PROJECT_DIR$/createCube.h" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/ScoreManager.cpp" afterDir="false" />
|
||||||
<change beforePath="$PROJECT_DIR$/.idea/editor.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/editor.xml" afterDir="false" />
|
<change afterPath="$PROJECT_DIR$/ScoreManager.h" 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$/CMakeLists.txt" beforeDir="false" afterPath="$PROJECT_DIR$/CMakeLists.txt" 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" />
|
||||||
@ -49,6 +49,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" />
|
||||||
@ -75,7 +87,7 @@
|
|||||||
"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": "main",
|
||||||
"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",
|
||||||
@ -118,6 +130,8 @@
|
|||||||
<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" />
|
||||||
</task>
|
</task>
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@ -19,6 +19,7 @@ set(SRC_FILES
|
|||||||
${CMAKE_CURRENT_LIST_DIR}/createCube.cpp
|
${CMAKE_CURRENT_LIST_DIR}/createCube.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/userinterface.cpp
|
${CMAKE_CURRENT_LIST_DIR}/userinterface.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/raygui_impl.cpp
|
${CMAKE_CURRENT_LIST_DIR}/raygui_impl.cpp
|
||||||
|
${CMAKE_CURRENT_LIST_DIR}/ScoreManager.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
set(INCLUDE_DIRS
|
set(INCLUDE_DIRS
|
||||||
|
|||||||
0
Highscores.txt
Normal file
0
Highscores.txt
Normal file
44
ScoreManager.cpp
Normal file
44
ScoreManager.cpp
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
#include "ScoreManager.h"
|
||||||
|
#include <fstream>
|
||||||
|
#include <iostream>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
|
ScoreManager::ScoreManager(const std::string& filename) : highscoreFile(filename)
|
||||||
|
{
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
20
ScoreManager.h
Normal file
20
ScoreManager.h
Normal file
@ -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();
|
||||||
|
};
|
||||||
20
main.cpp
20
main.cpp
@ -3,6 +3,7 @@
|
|||||||
#include "userinterface.h"
|
#include "userinterface.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
#include "ScoreManager.h"
|
||||||
|
|
||||||
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
||||||
// 3D Memory Game – Hauptprogramm
|
// 3D Memory Game – Hauptprogramm
|
||||||
@ -10,6 +11,8 @@
|
|||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
UserInterface userInterface;
|
UserInterface userInterface;
|
||||||
|
ScoreManager score("Highscores.txt");
|
||||||
|
|
||||||
//CHRIS WAR HIER
|
//CHRIS WAR HIER
|
||||||
//AXIOM WAR HIER
|
//AXIOM WAR HIER
|
||||||
// Zufall initialisieren
|
// Zufall initialisieren
|
||||||
@ -31,8 +34,8 @@ int main()
|
|||||||
double highScoreTime = 15.41;
|
double highScoreTime = 15.41;
|
||||||
|
|
||||||
//TODO: Hier die Anzahl der Züge abrufen.
|
//TODO: Hier die Anzahl der Züge abrufen.
|
||||||
int currentScoreTurns = 7;
|
int currentScoreTurns = 0;
|
||||||
int highScoreTurns = 3;
|
int highScoreTurns = score.getHighScore();
|
||||||
|
|
||||||
if (currentScoreTime <= highScoreTime) highScoreTime = currentScoreTime;
|
if (currentScoreTime <= highScoreTime) highScoreTime = currentScoreTime;
|
||||||
if (currentScoreTime <= highScoreTurns) highScoreTurns = currentScoreTurns;
|
if (currentScoreTime <= highScoreTurns) highScoreTurns = currentScoreTurns;
|
||||||
@ -91,7 +94,13 @@ 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)
|
||||||
|
{
|
||||||
c.FlipForward();
|
c.FlipForward();
|
||||||
|
score.incrementScore();
|
||||||
|
currentScoreTurns = score.getCurrentScore() / 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -112,6 +121,7 @@ int main()
|
|||||||
// Matching-Logik
|
// Matching-Logik
|
||||||
if (first && second)
|
if (first && second)
|
||||||
{
|
{
|
||||||
|
//currentScoreTurns = score.getCurrentScore();
|
||||||
Color col1 = first->GetColor();
|
Color col1 = first->GetColor();
|
||||||
Color col2 = second->GetColor();
|
Color col2 = second->GetColor();
|
||||||
|
|
||||||
@ -151,9 +161,9 @@ int main()
|
|||||||
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.
|
//TODO: Neue Scores zuweisen, current genügen.
|
||||||
currentScoreTime = 17.3;
|
//currentScoreTime = 17.3;
|
||||||
currentScoreTurns = 10;
|
//currentScoreTurns = 10;
|
||||||
|
score.saveHighScore();
|
||||||
if (currentScoreTime <= highScoreTime) highScoreTime = currentScoreTime;
|
if (currentScoreTime <= highScoreTime) highScoreTime = currentScoreTime;
|
||||||
if (currentScoreTurns <= highScoreTurns) highScoreTurns = currentScoreTurns;
|
if (currentScoreTurns <= highScoreTurns) highScoreTurns = currentScoreTurns;
|
||||||
userInterface.showScore(currentScoreTime, highScoreTime, currentScoreTurns, highScoreTurns);
|
userInterface.showScore(currentScoreTime, highScoreTime, currentScoreTurns, highScoreTurns);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user