Added user interface
This commit is contained in:
parent
9b3e642475
commit
c0c25360cb
@ -17,6 +17,8 @@ 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
|
||||||
)
|
)
|
||||||
|
|
||||||
set(INCLUDE_DIRS
|
set(INCLUDE_DIRS
|
||||||
|
|||||||
34
main.cpp
34
main.cpp
@ -1,5 +1,6 @@
|
|||||||
#include "gamecube.h"
|
#include "gamecube.h"
|
||||||
#include "createCube.h"
|
#include "createCube.h"
|
||||||
|
#include "userinterface.h"
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
@ -8,6 +9,7 @@
|
|||||||
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
UserInterface userInterface;
|
||||||
//CHRIS WAR HIER
|
//CHRIS WAR HIER
|
||||||
//AXIOM WAR HIER
|
//AXIOM WAR HIER
|
||||||
// Zufall initialisieren
|
// Zufall initialisieren
|
||||||
@ -24,8 +26,23 @@ int main()
|
|||||||
camera.fovy = 45.0f;
|
camera.fovy = 45.0f;
|
||||||
camera.projection = CAMERA_PERSPECTIVE;
|
camera.projection = CAMERA_PERSPECTIVE;
|
||||||
|
|
||||||
int cubePairs = 7;
|
//TODO: Hier die Zeit abrufen.
|
||||||
if (cubePairs > 10 || cubePairs <= 1) cubePairs = 3;
|
double currentScoreTime = 11.42;
|
||||||
|
double highScoreTime = 15.41;
|
||||||
|
|
||||||
|
//TODO: Hier die Anzahl der Züge abrufen.
|
||||||
|
int currentScoreTurns = 7;
|
||||||
|
int highScoreTurns = 3;
|
||||||
|
|
||||||
|
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();
|
||||||
|
}
|
||||||
|
|
||||||
std::vector<Vec3> positions =createCubes(cubePairs);
|
std::vector<Vec3> positions =createCubes(cubePairs);
|
||||||
|
|
||||||
// Nur 3 Farben für 3 Paare
|
// Nur 3 Farben für 3 Paare
|
||||||
@ -119,6 +136,8 @@ int main()
|
|||||||
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
||||||
// Zeichnen
|
// Zeichnen
|
||||||
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
BeginMode3D(camera);
|
BeginMode3D(camera);
|
||||||
@ -128,8 +147,17 @@ 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;
|
||||||
|
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);
|
||||||
|
|
||||||
|
|||||||
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
75
userinterface.cpp
Normal file
75
userinterface.cpp
Normal file
@ -0,0 +1,75 @@
|
|||||||
|
#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);
|
||||||
|
} 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