Compare commits
No commits in common. "main" and "Zeit_zaeler" have entirely different histories.
main
...
Zeit_zaele
46
.idea/workspace.xml
generated
46
.idea/workspace.xml
generated
@ -7,6 +7,7 @@
|
|||||||
<option name="/Default/RiderDebugger/RiderRestoreDecompile/RestoreDecompileSetting/@EntryValue" value="false" type="bool" />
|
<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/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/@EntryIndexedValue" value="true" type="bool" />
|
||||||
|
<option name="/Default/Housekeeping/FeatureSuggestion/FeatureSuggestionManager/DisabledSuggesters/=SwitchToGoToActionSuggester/@EntryIndexRemoved" />
|
||||||
</component>
|
</component>
|
||||||
<component name="CMakePresetLoader">{
|
<component name="CMakePresetLoader">{
|
||||||
"useNewFormat": true
|
"useNewFormat": true
|
||||||
@ -31,8 +32,10 @@
|
|||||||
<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 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$/gamecube.h" beforeDir="false" afterPath="$PROJECT_DIR$/gamecube.h" 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$/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>
|
</list>
|
||||||
<option name="SHOW_DIALOG" value="false" />
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@ -73,27 +76,27 @@
|
|||||||
<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">{
|
<component name="PropertiesComponent"><![CDATA[{
|
||||||
"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": "bug__fix__branch",
|
"git-widget-placeholder": "Zeit__zaeler",
|
||||||
"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 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">
|
||||||
@ -124,7 +127,6 @@
|
|||||||
<workItem from="1763895078693" duration="5675000" />
|
<workItem from="1763895078693" duration="5675000" />
|
||||||
<workItem from="1764526482502" duration="8000" />
|
<workItem from="1764526482502" duration="8000" />
|
||||||
<workItem from="1764526493477" duration="4519000" />
|
<workItem from="1764526493477" duration="4519000" />
|
||||||
<workItem from="1765791349412" duration="635000" />
|
|
||||||
</task>
|
</task>
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
@ -1,2 +1 @@
|
|||||||
score 99
|
11.34
|
||||||
time 99999.99
|
|
||||||
@ -1,35 +1,27 @@
|
|||||||
#include "ScoreManager.h"
|
#include "ScoreManager.h"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <limits>
|
||||||
|
|
||||||
ScoreManager::ScoreManager(const std::string& filename) : highscoreFile(filename) {
|
ScoreManager::ScoreManager(const std::string& filename) : highscoreFile(filename)
|
||||||
|
{
|
||||||
|
std::cout << "test";
|
||||||
loadHighscore();
|
loadHighscore();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScoreManager::loadHighscore() {
|
void ScoreManager::loadHighscore() {
|
||||||
std::ifstream file(highscoreFile);
|
std::ifstream file(highscoreFile);
|
||||||
|
if (file.is_open()) {
|
||||||
if (!file.is_open()) {
|
int value;
|
||||||
std::cout << "No highscore file found, creating new file.\n";
|
if (file >> value) {
|
||||||
highScore = 9999;
|
if (value > 0) highScore = value;
|
||||||
bestTime = 99999.99;
|
}
|
||||||
return;
|
file.close();
|
||||||
}
|
} else {
|
||||||
|
;
|
||||||
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() {
|
void ScoreManager::incrementScore() {
|
||||||
currentScore++;
|
currentScore++;
|
||||||
}
|
}
|
||||||
@ -38,35 +30,14 @@ void ScoreManager::resetScore() {
|
|||||||
currentScore = 0;
|
currentScore = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScoreManager::saveHighScore(int finalScore, double finalTime) {
|
void ScoreManager::saveHighScore() {
|
||||||
bool updated = false;
|
if (highScore == std::numeric_limits<int>::max()) return;
|
||||||
|
|
||||||
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);
|
std::ofstream file(highscoreFile);
|
||||||
if (!file.is_open()) {
|
|
||||||
std::cerr << "❌ ERROR: Can't write highscore file\n";
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
file << "score " << highScore << "\n";
|
if (file.is_open()) {
|
||||||
file << "time " << bestTime << "\n";
|
file << highScore;
|
||||||
file.close();
|
file.close();
|
||||||
|
} else {
|
||||||
std::cout << "✅ Highscore updated!\n";
|
std::cerr << "Error: Could not write to highscore file" << std::endl;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -3,23 +3,18 @@
|
|||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
class ScoreManager {
|
class ScoreManager {
|
||||||
public:
|
public:
|
||||||
ScoreManager(const std::string& filename);
|
ScoreManager(const std::string& filename);
|
||||||
|
|
||||||
void incrementScore();
|
void incrementScore();
|
||||||
void resetScore();
|
void resetScore();
|
||||||
void saveHighScore(int finalScore, double finalTime);
|
void saveHighScore();
|
||||||
|
int getCurrentScore() const { return currentScore; }
|
||||||
|
int getHighScore() const { return (highScore == std::numeric_limits<int>::max()) ? 0 : highScore; }
|
||||||
|
|
||||||
int getCurrentScore() const { return currentScore; }
|
private:
|
||||||
int getHighScore() const { return highScore; }
|
int currentScore = 0;
|
||||||
double getBestTime() const { return bestTime; }
|
int highScore = std::numeric_limits<int>::max();
|
||||||
|
std::string highscoreFile;
|
||||||
private:
|
void loadHighscore();
|
||||||
int currentScore = 0;
|
};
|
||||||
int highScore = std::numeric_limits<int>::max();
|
|
||||||
double bestTime = std::numeric_limits<double>::max();
|
|
||||||
|
|
||||||
std::string highscoreFile;
|
|
||||||
|
|
||||||
void loadHighscore();
|
|
||||||
};
|
|
||||||
@ -32,11 +32,3 @@ 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
|
|
||||||
};
|
|
||||||
47
main.cpp
47
main.cpp
@ -31,13 +31,10 @@ int main()
|
|||||||
camera.fovy = 45.0f;
|
camera.fovy = 45.0f;
|
||||||
camera.projection = CAMERA_PERSPECTIVE;
|
camera.projection = CAMERA_PERSPECTIVE;
|
||||||
|
|
||||||
GameState state = GameState::Idle;
|
|
||||||
|
|
||||||
|
|
||||||
//TODO: Hier die Zeit abrufen.
|
//TODO: Hier die Zeit abrufen.
|
||||||
double currentScoreTime = 0.0;
|
double currentScoreTime = 0.0;
|
||||||
double startTime = 0.0;
|
double startTime = 0.0;
|
||||||
double highScoreTime = score.getBestTime();
|
double highScoreTime = 43.4;
|
||||||
|
|
||||||
//TODO: Hier die Anzahl der Züge abrufen.
|
//TODO: Hier die Anzahl der Züge abrufen.
|
||||||
int currentScoreTurns = 0;
|
int currentScoreTurns = 0;
|
||||||
@ -56,7 +53,7 @@ int main()
|
|||||||
|
|
||||||
std::vector<Vec3> positions =createCubes(cubePairs);
|
std::vector<Vec3> positions =createCubes(cubePairs);
|
||||||
|
|
||||||
// Nur x Farben für x Paare
|
// Nur 3 Farben für 3 Paare
|
||||||
std::vector<Color> colors= getColors(cubePairs);
|
std::vector<Color> colors= getColors(cubePairs);
|
||||||
|
|
||||||
|
|
||||||
@ -91,11 +88,7 @@ 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();
|
||||||
|
|
||||||
@ -107,26 +100,12 @@ int main()
|
|||||||
|
|
||||||
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();
|
score.incrementScore();
|
||||||
currentScoreTurns = score.getCurrentScore() / 2;
|
currentScoreTurns = score.getCurrentScore() / 2;
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -135,19 +114,17 @@ 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 (state == GameState::LockInput && first && second)
|
if (c.IsFlipped() && !c.IsMatched())
|
||||||
{
|
|
||||||
if (first->GetRotationY() == 180.0f && second->GetRotationY() == 180.0f)
|
|
||||||
{
|
{
|
||||||
state = GameState::CheckingMatch;
|
if (!first) first = &c;
|
||||||
|
else if (!second && &c != first) second = &c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Matching-Logik
|
// Matching-Logik
|
||||||
if (state == GameState::CheckingMatch && first && second)
|
if (first && second)
|
||||||
{
|
{
|
||||||
//currentScoreTurns = score.getCurrentScore();
|
//currentScoreTurns = score.getCurrentScore();
|
||||||
Color col1 = first->GetColor();
|
Color col1 = first->GetColor();
|
||||||
@ -165,8 +142,6 @@ int main()
|
|||||||
}
|
}
|
||||||
|
|
||||||
first = second = nullptr;
|
first = second = nullptr;
|
||||||
state = GameState::Idle;
|
|
||||||
std::cout <<"unlock";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Gewinnprüfung
|
// Gewinnprüfung
|
||||||
@ -202,7 +177,7 @@ int main()
|
|||||||
|
|
||||||
if (currentScoreTime <= highScoreTime) highScoreTime = currentScoreTime;
|
if (currentScoreTime <= highScoreTime) highScoreTime = currentScoreTime;
|
||||||
if (currentScoreTurns <= highScoreTurns) highScoreTurns = currentScoreTurns;
|
if (currentScoreTurns <= highScoreTurns) highScoreTurns = currentScoreTurns;
|
||||||
score.saveHighScore(currentScoreTurns, currentScoreTime);
|
score.saveHighScore();
|
||||||
userInterface.showScore(currentScoreTime, highScoreTime, currentScoreTurns, highScoreTurns);
|
userInterface.showScore(currentScoreTime, highScoreTime, currentScoreTurns, highScoreTurns);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user