78 lines
2.6 KiB
C++
78 lines
2.6 KiB
C++
#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);
|
|
|
|
}
|
|
|