Compare commits
26
Commits
1527b661ea
..
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
58ff9f2e63 | ||
|
|
a4b18d1207 | ||
|
|
ef779381a6 | ||
|
|
c6cdebfc84 | ||
|
|
aa5ca11829 | ||
|
|
c0c25360cb | ||
|
|
9b3e642475 | ||
|
|
9e5719f8f0 | ||
|
|
f0a7363497 | ||
|
|
edb628f7ba | ||
|
|
4ea94f1917 | ||
|
|
d06404f865 | ||
|
|
79f97d6121 | ||
|
|
784f75f4db | ||
|
|
9873b963fa | ||
|
|
7dacd91b32 | ||
|
|
4d2df95404 | ||
|
|
c002d7dd4b | ||
|
|
6b8e5f7204 | ||
|
|
480fd67817 | ||
|
|
366f7b1c37 | ||
|
|
cdc533c586 | ||
|
|
ca3f80284c | ||
|
|
35e35cad9b | ||
|
|
7c8ea0c30e | ||
|
|
9e322748dc |
@@ -1,2 +1,3 @@
|
|||||||
cmake-build-debug/
|
cmake-build-debug/
|
||||||
cmake-build-debug-mingw/
|
cmake-build-debug-mingw/
|
||||||
|
.idea/workspace.xml
|
||||||
Generated
-8
@@ -1,8 +0,0 @@
|
|||||||
# Default ignored files
|
|
||||||
/shelf/
|
|
||||||
/workspace.xml
|
|
||||||
# Editor-based HTTP Client requests
|
|
||||||
/httpRequests/
|
|
||||||
# Datasource local storage ignored files
|
|
||||||
/dataSources/
|
|
||||||
/dataSources.local.xml
|
|
||||||
Generated
-2
@@ -1,2 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module classpath="CMake" type="CPP_MODULE" version="4" />
|
|
||||||
Generated
-1
@@ -2,7 +2,6 @@
|
|||||||
<project version="4">
|
<project version="4">
|
||||||
<component name="ProjectModuleManager">
|
<component name="ProjectModuleManager">
|
||||||
<modules>
|
<modules>
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/Programmieren 3B.iml" filepath="$PROJECT_DIR$/.idea/Programmieren 3B.iml" />
|
|
||||||
<module fileurl="file://$PROJECT_DIR$/.idea/Stone_Development.iml" filepath="$PROJECT_DIR$/.idea/Stone_Development.iml" />
|
<module fileurl="file://$PROJECT_DIR$/.idea/Stone_Development.iml" filepath="$PROJECT_DIR$/.idea/Stone_Development.iml" />
|
||||||
</modules>
|
</modules>
|
||||||
</component>
|
</component>
|
||||||
|
|||||||
Generated
+43
-28
@@ -7,7 +7,6 @@
|
|||||||
<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
|
||||||
@@ -21,16 +20,19 @@
|
|||||||
<component name="CMakeRunConfigurationManager">
|
<component name="CMakeRunConfigurationManager">
|
||||||
<generated>
|
<generated>
|
||||||
<config projectName="Prog3B" targetName="Prog3B" />
|
<config projectName="Prog3B" targetName="Prog3B" />
|
||||||
|
<config projectName="Prog3B" targetName="Prog3B_tests" />
|
||||||
</generated>
|
</generated>
|
||||||
</component>
|
</component>
|
||||||
<component name="CMakeSettings">
|
<component name="CMakeSettings">
|
||||||
<configurations>
|
<configurations>
|
||||||
<configuration PROFILE_NAME="Debug-MinGW" ENABLED="true" CONFIG_NAME="Debug" TOOLCHAIN_NAME="MinGW" />
|
<configuration PROFILE_NAME="Debug" ENABLED="true" CONFIG_NAME="Debug" />
|
||||||
</configurations>
|
</configurations>
|
||||||
</component>
|
</component>
|
||||||
<component name="ChangeListManager">
|
<component name="ChangeListManager">
|
||||||
<list default="true" id="e1b17018-ef5c-443f-8959-8b1378194905" 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$/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" />
|
||||||
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
@@ -40,20 +42,33 @@
|
|||||||
<component name="ClangdSettings">
|
<component name="ClangdSettings">
|
||||||
<option name="formatViaClangd" value="false" />
|
<option name="formatViaClangd" value="false" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ExecutionTargetManager" SELECTED_TARGET="CMakeBuildProfile:Debug-MinGW" />
|
<component name="ExecutionTargetManager" SELECTED_TARGET="CMakeBuildProfile:Debug" />
|
||||||
<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">
|
<component name="HighlightingSettingsPerFile">
|
||||||
<setting file="file://$PROJECT_DIR$/main.cpp" root0="FORCE_HIGHLIGHTING" />
|
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||||
<setting file="mock://C:/Users/marce/Desktop/Prog Praktikum C++/Semester 3/Stone_Development/tests.cpp" root0="SKIP_HIGHLIGHTING" />
|
<setting file="mock:///dummy.cpp" root0="SKIP_HIGHLIGHTING" />
|
||||||
<setting file="mock://C:/Users/marce/Desktop/Prog Praktikum C++/Semester 3/Stone_Development/tests.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" />
|
||||||
|
<option name="minorVersion" value="3.4" />
|
||||||
|
<option name="productBranch" value="Classic" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectColorInfo">{
|
<component name="ProjectColorInfo">{
|
||||||
"customColor": "",
|
"customColor": "",
|
||||||
"associatedIndex": 0
|
"associatedIndex": 1
|
||||||
}</component>
|
}</component>
|
||||||
<component name="ProjectId" id="34yCUQNT5FEzK3w2FlmvvgM9a9g" />
|
<component name="ProjectId" id="35dvDDehATN0hwwCgiPHEpDQPia" />
|
||||||
<component name="ProjectViewState">
|
<component name="ProjectViewState">
|
||||||
<option name="hideEmptyMiddlePackages" value="true" />
|
<option name="hideEmptyMiddlePackages" value="true" />
|
||||||
<option name="showLibraryContents" value="true" />
|
<option name="showLibraryContents" value="true" />
|
||||||
@@ -61,7 +76,6 @@
|
|||||||
<component name="PropertiesComponent">{
|
<component name="PropertiesComponent">{
|
||||||
"keyToString": {
|
"keyToString": {
|
||||||
"CMake Application.Prog3B.executor": "Run",
|
"CMake Application.Prog3B.executor": "Run",
|
||||||
"CMake Application.Prog3B_tests.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",
|
||||||
@@ -70,43 +84,47 @@
|
|||||||
"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": "main",
|
"git-widget-placeholder": "bug__fix__branch",
|
||||||
"last_opened_file_path": "C:/Users/marce/Desktop/Prog Praktikum C++/Vorlesung/Lambda",
|
"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",
|
||||||
"settings.editor.selected.configurable": "CMakeSettings",
|
|
||||||
"vue.rearranger.settings.migration": "true"
|
"vue.rearranger.settings.migration": "true"
|
||||||
}
|
}
|
||||||
}</component>
|
}</component>
|
||||||
<component name="RunManager">
|
<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-MinGW" 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" />
|
||||||
</method>
|
</method>
|
||||||
</configuration>
|
</configuration>
|
||||||
<configuration default="true" type="CMakeRunConfiguration" factoryName="Application" REDIRECT_INPUT="false" ELEVATE="false" USE_EXTERNAL_CONSOLE="false" EMULATE_TERMINAL="false" PASS_PARENT_ENVS_2="true">
|
<configuration name="Prog3B_tests" 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_tests" CONFIG_NAME="Debug" RUN_TARGET_PROJECT_NAME="Prog3B" RUN_TARGET_NAME="Prog3B_tests">
|
||||||
<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" />
|
||||||
</method>
|
</method>
|
||||||
</configuration>
|
</configuration>
|
||||||
|
<list>
|
||||||
|
<item itemvalue="CMake Application.Prog3B" />
|
||||||
|
<item itemvalue="CMake Application.Prog3B_tests" />
|
||||||
|
</list>
|
||||||
</component>
|
</component>
|
||||||
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
|
||||||
<component name="TaskManager">
|
<component name="TaskManager">
|
||||||
<task active="true" id="Default" summary="Default task">
|
<task active="true" id="Default" summary="Default task">
|
||||||
<changelist id="e1b17018-ef5c-443f-8959-8b1378194905" name="Changes" comment="" />
|
<changelist id="db070755-9708-4a46-a9cb-e7c4dc1bfb77" name="Changes" comment="" />
|
||||||
<created>1762176441912</created>
|
<created>1763452643165</created>
|
||||||
<option name="number" value="Default" />
|
<option name="number" value="Default" />
|
||||||
<option name="presentableId" value="Default" />
|
<option name="presentableId" value="Default" />
|
||||||
<updated>1762176441912</updated>
|
<updated>1763452643165</updated>
|
||||||
<workItem from="1762176443926" duration="3810000" />
|
<workItem from="1763452645145" duration="329000" />
|
||||||
<workItem from="1762783055261" duration="74000" />
|
<workItem from="1763652636624" duration="1226000" />
|
||||||
<workItem from="1763367345575" duration="665000" />
|
<workItem from="1763653877709" duration="28000" />
|
||||||
<workItem from="1763368121506" duration="692000" />
|
<workItem from="1763895078693" duration="5675000" />
|
||||||
<workItem from="1763385066418" duration="421000" />
|
<workItem from="1764526482502" duration="8000" />
|
||||||
<workItem from="1763385896177" duration="1973000" />
|
<workItem from="1764526493477" duration="4519000" />
|
||||||
|
<workItem from="1765791349412" duration="635000" />
|
||||||
</task>
|
</task>
|
||||||
<servers />
|
<servers />
|
||||||
</component>
|
</component>
|
||||||
@@ -118,7 +136,4 @@
|
|||||||
<isAutomaticFoundErrors value="true" />
|
<isAutomaticFoundErrors value="true" />
|
||||||
<isAutomaticReloadCMake value="true" />
|
<isAutomaticReloadCMake value="true" />
|
||||||
</component>
|
</component>
|
||||||
<component name="VcsManagerConfiguration">
|
|
||||||
<option name="LAST_COMMIT_MESSAGE" value="" />
|
|
||||||
</component>
|
|
||||||
</project>
|
</project>
|
||||||
+5
-6
@@ -15,7 +15,11 @@ endif()
|
|||||||
set(SRC_FILES
|
set(SRC_FILES
|
||||||
${CMAKE_CURRENT_LIST_DIR}/main.cpp
|
${CMAKE_CURRENT_LIST_DIR}/main.cpp
|
||||||
${CMAKE_CURRENT_LIST_DIR}/gamecube.cpp
|
${CMAKE_CURRENT_LIST_DIR}/gamecube.cpp
|
||||||
tests.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
|
set(INCLUDE_DIRS
|
||||||
@@ -49,11 +53,8 @@ endif()
|
|||||||
add_executable(${EXECUTABLE_NAME} ${SRC_FILES})
|
add_executable(${EXECUTABLE_NAME} ${SRC_FILES})
|
||||||
target_include_directories(${EXECUTABLE_NAME} PRIVATE ${INCLUDE_DIRS})
|
target_include_directories(${EXECUTABLE_NAME} PRIVATE ${INCLUDE_DIRS})
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# === Bibliotheken verlinken ===
|
# === Bibliotheken verlinken ===
|
||||||
target_link_libraries(${EXECUTABLE_NAME} PRIVATE
|
target_link_libraries(${EXECUTABLE_NAME} PRIVATE
|
||||||
${CMAKE_CURRENT_LIST_DIR}/${OS_DIR}/libgamematrix.a
|
|
||||||
${CMAKE_CURRENT_LIST_DIR}/${OS_DIR}/libraylib.a
|
${CMAKE_CURRENT_LIST_DIR}/${OS_DIR}/libraylib.a
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -71,7 +72,5 @@ if(APPLE)
|
|||||||
)
|
)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
|
||||||
add_executable(Prog3B_tests tests.cpp)
|
add_executable(Prog3B_tests tests.cpp)
|
||||||
set_target_properties(Prog3B_tests PROPERTIES WIN32_EXECUTABLE OFF)
|
set_target_properties(Prog3B_tests PROPERTIES WIN32_EXECUTABLE OFF)
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
score 99
|
||||||
|
time 99999.99
|
||||||
@@ -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";
|
||||||
|
}
|
||||||
|
|
||||||
@@ -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();
|
||||||
|
};
|
||||||
@@ -0,0 +1,64 @@
|
|||||||
|
#include "createCube.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
std::vector<Vec3> createCubes(int pairs)
|
||||||
|
{
|
||||||
|
std::vector<int> fieldSize = calculateFieldSize(pairs);
|
||||||
|
std::vector<Vec3> cubePositions;
|
||||||
|
//std::cout<<(fieldSize[0])<<std::endl;
|
||||||
|
//std::cout<<(fieldSize[1]) <<std::endl;
|
||||||
|
int start_x = (fieldSize[0]/2) * -2;
|
||||||
|
int start_y = (fieldSize[1]/2) * -2;
|
||||||
|
for (int i = 0; i < fieldSize[0]; i++)
|
||||||
|
{
|
||||||
|
for (int j = 0; j < fieldSize[1]; j++)
|
||||||
|
{
|
||||||
|
cubePositions.push_back(Vec3(start_x + 2*i, 0, start_y + 2*j));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return cubePositions;
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<int> calculateFieldSize(int pairs)
|
||||||
|
{
|
||||||
|
std::vector<int> best_field = {pairs, 2};
|
||||||
|
int cube_count = pairs *2;
|
||||||
|
int test_count = 3;
|
||||||
|
while (test_count < pairs)
|
||||||
|
{
|
||||||
|
for (int i = 3; i < pairs; i++)
|
||||||
|
{
|
||||||
|
if (test_count * i == cube_count && test_count + i < best_field[0] + best_field[1])
|
||||||
|
{
|
||||||
|
best_field[1] = test_count;
|
||||||
|
best_field[0] = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
test_count++;
|
||||||
|
}
|
||||||
|
return best_field;
|
||||||
|
|
||||||
|
};
|
||||||
|
|
||||||
|
std::vector<Color> getColors(int pairs)
|
||||||
|
{
|
||||||
|
std::vector<Color> returnColors;
|
||||||
|
Color colors[] = {
|
||||||
|
{230, 25, 75, 255}, // Red
|
||||||
|
{60, 180, 75, 255}, // Green
|
||||||
|
{0, 130, 200, 255}, // Blue
|
||||||
|
{245, 130, 48, 255}, // Orange
|
||||||
|
{145, 30, 180, 255}, // Purple
|
||||||
|
{255, 225, 25, 255}, // Yellow
|
||||||
|
{70, 240, 240, 255}, // Cyan
|
||||||
|
{240, 50, 230, 255}, // Magenta
|
||||||
|
{210, 245, 60, 255}, // Lime
|
||||||
|
{250, 190, 190, 255} // Pink
|
||||||
|
};
|
||||||
|
for (int i = 0; i < pairs; i++)
|
||||||
|
{
|
||||||
|
returnColors.push_back(colors[i]);
|
||||||
|
}
|
||||||
|
std::cout << returnColors.size() << std::endl;
|
||||||
|
return returnColors;
|
||||||
|
};
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
#pragma once
|
||||||
|
#include "gamecube.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
std::vector<Vec3> createCubes(int pairs);
|
||||||
|
|
||||||
|
std::vector<Color> getColors(int pairs);
|
||||||
|
|
||||||
|
std::vector<int> calculateFieldSize(int pairs);
|
||||||
|
|
||||||
+3
-3
@@ -44,11 +44,11 @@ void gamecube::Draw() const
|
|||||||
rlPushMatrix();
|
rlPushMatrix();
|
||||||
|
|
||||||
// Matrizen für Rotation und Translation erzeugen
|
// Matrizen für Rotation und Translation erzeugen
|
||||||
auto matrix_a = gameMatrix::translate({ position.x, position.y, position.z});
|
auto matrix_a = Matrix3D::gameMatrix::translate({ position.x, position.y, position.z});
|
||||||
auto matrix_b = gameMatrix::rot3D(rotation, 'y');
|
auto matrix_b = Matrix3D::gameMatrix::rot3D(rotation, 'y');
|
||||||
|
|
||||||
// Matrizen multiplizieren (Translation * Rotation)
|
// Matrizen multiplizieren (Translation * Rotation)
|
||||||
auto model = gameMatrix::matmul(matrix_a, matrix_b);
|
auto model = Matrix3D::gameMatrix::matmul(matrix_a, matrix_b);
|
||||||
|
|
||||||
// transform for raylib matrix
|
// transform for raylib matrix
|
||||||
float f[16];
|
float f[16];
|
||||||
|
|||||||
@@ -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
|
||||||
|
};
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
#include "gamematrix.h"
|
||||||
|
|
||||||
|
|
||||||
|
using namespace Matrix3D;
|
||||||
|
|
||||||
|
///
|
||||||
|
/// @param matrix1 - First matrix
|
||||||
|
/// @param matrix2 - Second matrix
|
||||||
|
/// @return Returns the multiplication of matrix 1 and matrix 2.
|
||||||
|
std::array<std::array<double,4>,4> gameMatrix::matmul(const std::array<std::array<double,4>,4>& matrix1,
|
||||||
|
const std::array<std::array<double,4>,4>& matrix2) {
|
||||||
|
|
||||||
|
std::array<std::array<double,4>,4> matrix3 = {};
|
||||||
|
if (matrix1[0].size() != matrix2.size()) {
|
||||||
|
throw std::invalid_argument("Number of columns of matrix 1 must be equal to number of rows of matrix 2");
|
||||||
|
};
|
||||||
|
for (int i = 0; i < matrix1.size(); i++) {
|
||||||
|
std::array<double,4> temp_array = {};
|
||||||
|
for (int j = 0; j < matrix2[i].size(); j++) {
|
||||||
|
double temp = 0;
|
||||||
|
for (int k = 0; k < matrix2.size(); k++) {
|
||||||
|
temp += matrix1[i][k] * matrix2[k][j];
|
||||||
|
}
|
||||||
|
temp_array[j] = temp;
|
||||||
|
}
|
||||||
|
matrix3[i] = temp_array;
|
||||||
|
}
|
||||||
|
return matrix3;
|
||||||
|
}
|
||||||
|
|
||||||
|
///
|
||||||
|
/// @param angle_deg Rotation angle
|
||||||
|
/// @param axis Rotation axis (x, y, z)
|
||||||
|
/// @return Returns a rotation matrix based on a given angle and axis.
|
||||||
|
std::array<std::array<double,4>,4> gameMatrix::rot3D(double angle_deg, char axis) {
|
||||||
|
if (axis != 'x' && axis != 'y' && axis != 'z') {
|
||||||
|
throw std::invalid_argument("Invalid axis");
|
||||||
|
};
|
||||||
|
const auto angle_rad = angle_deg * M_PI / 180;
|
||||||
|
std::array<std::array<double,4>,4> rotationMatrix = {};
|
||||||
|
switch (axis) {
|
||||||
|
case 'x': {
|
||||||
|
std::array<std::array<double,4>,4> rMx = {{
|
||||||
|
{1, 0, 0, 0},
|
||||||
|
{0, cos(angle_rad), -sin(angle_rad), 0},
|
||||||
|
{0, sin(angle_rad), cos(angle_rad), 0},
|
||||||
|
{0, 0, 0, 1}
|
||||||
|
}};
|
||||||
|
rotationMatrix = rMx;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case 'y': {
|
||||||
|
std::array<std::array<double,4>,4> rMy = {{
|
||||||
|
{cos(angle_rad), 0, sin(angle_rad), 0},
|
||||||
|
{0, 1, 0, 0},
|
||||||
|
{-sin(angle_rad), 0, cos(angle_rad), 0},
|
||||||
|
{0, 0, 0, 1}
|
||||||
|
}};
|
||||||
|
rotationMatrix = rMy;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 'z': {
|
||||||
|
std::array<std::array<double,4>,4> rMz = {{
|
||||||
|
{cos(angle_rad), -sin(angle_rad), 0, 0},
|
||||||
|
{sin(angle_rad), cos(angle_rad), 0, 0},
|
||||||
|
{0, 0, 1, 0},
|
||||||
|
{0, 0, 0, 1}
|
||||||
|
}};
|
||||||
|
rotationMatrix = rMz;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return rotationMatrix;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
///
|
||||||
|
/// @param pos 3 point vector (x, y, z)
|
||||||
|
/// @return Returns a 4x4 translation matrix base on a given vector.
|
||||||
|
std::array<std::array<double,4>,4> gameMatrix::translate(const std::array<double, 3>& pos) {
|
||||||
|
std::array<std::array<double,4>,4> transMatrix = {{{1, 0, 0, pos[0]}, {0, 1, 0, pos[1]}, {0, 0, 1, pos[2]}, {0, 0, 0, 1}}};
|
||||||
|
return transMatrix;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
+13
-6
@@ -4,16 +4,23 @@
|
|||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
class gameMatrix
|
namespace Matrix3D {
|
||||||
{
|
class gameMatrix
|
||||||
public:
|
{
|
||||||
|
public:
|
||||||
// Matrix Multiplikation
|
// Matrix Multiplikation
|
||||||
static std::array<std::array<double,4>,4> matmul(const std::array<std::array<double,4>,4>& A,
|
static std::array<std::array<double,4>,4> matmul(const std::array<std::array<double,4>,4>& matrix1,
|
||||||
const std::array<std::array<double,4>,4>& B);
|
const std::array<std::array<double,4>,4>& matrix2);
|
||||||
|
|
||||||
// Rotationsmatrix um Achse x/y/z
|
// Rotationsmatrix um Achse x/y/z
|
||||||
static std::array<std::array<double,4>,4> rot3D(double angle_deg, char axis);
|
static std::array<std::array<double,4>,4> rot3D(double angle_deg, char axis);
|
||||||
|
|
||||||
// Verschiebung
|
// Verschiebung
|
||||||
static std::array<std::array<double,4>,4> translate(const std::array<double, 3>& pos);
|
static std::array<std::array<double,4>,4> translate(const std::array<double, 3>& pos);
|
||||||
};
|
|
||||||
|
private:
|
||||||
|
//TODO: Was für eine Rolle spielen Vec3 und Mat4???
|
||||||
|
struct Vec3 {double x,y,z;};
|
||||||
|
std::array<std::array<double,4>,4> Mat4 {};
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -1,12 +1,20 @@
|
|||||||
#include "gamecube.h"
|
#include "gamecube.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
|
||||||
@@ -17,21 +25,44 @@ int main()
|
|||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
Camera3D camera{};
|
Camera3D camera{};
|
||||||
camera.position = {6.0f, 6.0f, 6.0f};
|
camera.position = {8.0f, 8.5f, 8.0f};
|
||||||
camera.target = {0.0f, 0.0f, 0.0f};
|
camera.target = {0.0f, 0.0f, 0.0f};
|
||||||
camera.up = {0.0f, 1.0f, 0.0f};
|
camera.up = {0.0f, 1.0f, 0.0f};
|
||||||
camera.fovy = 45.0f;
|
camera.fovy = 45.0f;
|
||||||
camera.projection = CAMERA_PERSPECTIVE;
|
camera.projection = CAMERA_PERSPECTIVE;
|
||||||
|
|
||||||
// Nur 3 Farben für 3 Paare
|
GameState state = GameState::Idle;
|
||||||
Color colors[] = { RED, GREEN, BLUE };
|
|
||||||
|
|
||||||
|
//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);
|
||||||
|
|
||||||
|
// Nur x Farben für x Paare
|
||||||
|
std::vector<Color> colors= getColors(cubePairs);
|
||||||
|
|
||||||
// 6 Karten-Positionen im 3x2 Raster
|
|
||||||
std::vector<Vec3> positions = {{-2, 0, -2}, {0, 0, -2}, {2, 0, -2},{-2, 0, 0}, {0, 0, 0}, {2, 0, 0}};
|
|
||||||
|
|
||||||
// Farben doppelt in einen Pool legen und mischen
|
// Farben doppelt in einen Pool legen und mischen
|
||||||
std::vector<Color> colorPool;
|
std::vector<Color> colorPool;
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < cubePairs; i++)
|
||||||
{
|
{
|
||||||
colorPool.push_back(colors[i]);
|
colorPool.push_back(colors[i]);
|
||||||
colorPool.push_back(colors[i]);
|
colorPool.push_back(colors[i]);
|
||||||
@@ -46,7 +77,7 @@ int main()
|
|||||||
|
|
||||||
// Karten/Würfel erstellen
|
// Karten/Würfel erstellen
|
||||||
std::vector<gamecube> cubes;
|
std::vector<gamecube> cubes;
|
||||||
for (int i = 0; i < 6; i++)
|
for (int i = 0; i < cubePairs*2; i++)
|
||||||
cubes.emplace_back(positions[i], colorPool[i]);
|
cubes.emplace_back(positions[i], colorPool[i]);
|
||||||
|
|
||||||
gamecube* first = nullptr;
|
gamecube* first = nullptr;
|
||||||
@@ -60,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();
|
||||||
|
|
||||||
@@ -71,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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -80,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();
|
||||||
|
|
||||||
@@ -107,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);
|
||||||
@@ -125,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();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,2 @@
|
|||||||
|
#define RAYGUI_IMPLEMENTATION
|
||||||
|
#include "raygui.h"
|
||||||
+5994
File diff suppressed because it is too large
Load Diff
@@ -1,13 +1,53 @@
|
|||||||
#include <array>
|
#include <cassert>
|
||||||
|
#include <cmath>
|
||||||
|
#include <iostream>
|
||||||
|
#include "gamematrix.cpp"
|
||||||
|
|
||||||
int main()
|
void test_matmul_basic() {
|
||||||
{
|
std::array<std::array<double,4>,4> A = {{
|
||||||
|
{1, 0, 0, 0},
|
||||||
|
{0, 1, 0, 0},
|
||||||
|
{0, 0, 1, 0},
|
||||||
|
{0, 0, 0, 1}
|
||||||
|
}};
|
||||||
|
|
||||||
|
std::array<std::array<double,4>,4> B = {{
|
||||||
|
{2, 3, 4, 5},
|
||||||
|
{1, 1, 1, 1},
|
||||||
|
{0, 0, 0, 0},
|
||||||
|
{7, 7, 7, 7}
|
||||||
|
}};
|
||||||
|
|
||||||
|
auto C = Matrix3D::gameMatrix::matmul(A, B);
|
||||||
|
|
||||||
|
assert(C[0][0] == 2);
|
||||||
|
assert(C[0][1] == 3);
|
||||||
|
assert(C[1][0] == 1);
|
||||||
|
assert(C[3][3] == 7);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool test_matmul()
|
void test_translate_basic() {
|
||||||
{
|
std::array<double, 3> pos = {3, -2, 8};
|
||||||
|
|
||||||
|
auto T = Matrix3D::gameMatrix::translate(pos);
|
||||||
|
|
||||||
|
assert(T[0][3] == 3);
|
||||||
|
assert(T[1][3] == -2);
|
||||||
|
assert(T[2][3] == 8);
|
||||||
|
}
|
||||||
|
|
||||||
|
void test_rot3D_basic() {
|
||||||
|
auto R = Matrix3D::gameMatrix::rot3D(90, 'x');
|
||||||
|
// cos(90°) ≈ 0, sin(90°) ≈ 1
|
||||||
|
assert(std::abs(R[1][1]) < 1e-6);
|
||||||
|
assert(std::abs(R[1][2] + 1.0) < 1e-6);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
test_matmul_basic();
|
||||||
|
test_translate_basic();
|
||||||
|
test_rot3D_basic();
|
||||||
|
|
||||||
|
std::cout << "Test bestanden!\n";
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
@@ -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