added menu for game init
This commit is contained in:
parent
323bd67577
commit
261c5d45eb
81
src/main.cpp
81
src/main.cpp
@ -8,6 +8,75 @@
|
|||||||
// -----------------------------------------------------------
|
// -----------------------------------------------------------
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
|
// =====================================================================
|
||||||
|
// 1) KLEINES MENÜFENSTER
|
||||||
|
// =====================================================================
|
||||||
|
|
||||||
|
InitWindow(400, 200, "Wuerfelspiel - Menu");
|
||||||
|
SetTargetFPS(60);
|
||||||
|
|
||||||
|
char input[4] = "";
|
||||||
|
int len = 0;
|
||||||
|
int numberOfCubes = 0;
|
||||||
|
bool error = false;
|
||||||
|
|
||||||
|
while (!WindowShouldClose())
|
||||||
|
{
|
||||||
|
int key = GetCharPressed();
|
||||||
|
|
||||||
|
// Zahlen erfassen
|
||||||
|
if (key >= '0' && key <= '9' && len < 3)
|
||||||
|
{
|
||||||
|
input[len++] = (char)key;
|
||||||
|
input[len] = '\0';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Backspace
|
||||||
|
if (IsKeyPressed(KEY_BACKSPACE) && len > 0)
|
||||||
|
input[--len] = '\0';
|
||||||
|
|
||||||
|
// ENTER = übernehmen
|
||||||
|
if (IsKeyPressed(KEY_ENTER))
|
||||||
|
{
|
||||||
|
numberOfCubes = atoi(input);
|
||||||
|
|
||||||
|
if (numberOfCubes > 0 && numberOfCubes % 2 == 0)
|
||||||
|
break; // gültig → Menü beenden
|
||||||
|
else
|
||||||
|
error = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Zeichnen des Menüs
|
||||||
|
BeginDrawing();
|
||||||
|
ClearBackground(RAYWHITE);
|
||||||
|
|
||||||
|
DrawText("Anzahl der Wuerfel (gerade Zahl):", 30, 40, 20, DARKGRAY);
|
||||||
|
|
||||||
|
DrawRectangle(30, 80, 200, 40, LIGHTGRAY);
|
||||||
|
DrawText(input, 40, 90, 20, BLACK);
|
||||||
|
|
||||||
|
if (error)
|
||||||
|
DrawText("Ungueltige Eingabe!", 30, 140, 20, RED);
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
}
|
||||||
|
|
||||||
|
CloseWindow(); // Menüfenster schließen
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// =====================================================================
|
||||||
|
// 2) HAUPTSPIELFENSTER
|
||||||
|
// =====================================================================
|
||||||
|
|
||||||
|
// Fenster und Kamera
|
||||||
|
InitWindow(800, 600, "3D Memory Game with Matrix3D Library");
|
||||||
|
SetTargetFPS(60);
|
||||||
|
|
||||||
// Anzahl Spielzüge -> wie oft wurde ein Wuerfel geklickt
|
// Anzahl Spielzüge -> wie oft wurde ein Wuerfel geklickt
|
||||||
int turnCount = 0;
|
int turnCount = 0;
|
||||||
|
|
||||||
@ -17,16 +86,12 @@ int main()
|
|||||||
// gespielte Zeit
|
// gespielte Zeit
|
||||||
int playTime = 0;
|
int playTime = 0;
|
||||||
|
|
||||||
// anzahl an wuerfeln -> immer gerade anzahl und groeßer null
|
// anzahl an wuerfeln -> immer gerade anzahl und groeßer null -> jetzt nutzlos, weil menu window
|
||||||
int numberOfCubes = 12;
|
//int numberOfCubes = 12;
|
||||||
|
|
||||||
// Zufall initialisieren
|
// Zufall initialisieren
|
||||||
srand(time(NULL));
|
srand(time(NULL));
|
||||||
|
|
||||||
// Fenster und Kamera
|
|
||||||
InitWindow(800, 600, "3D Memory Game with Matrix3D Library");
|
|
||||||
SetTargetFPS(60);
|
|
||||||
|
|
||||||
Camera3D camera{};
|
Camera3D camera{};
|
||||||
//camera.position = {6.0f, 6.0f, 6.0f}; // changed camera position to show all cubes if number very high
|
//camera.position = {6.0f, 6.0f, 6.0f}; // changed camera position to show all cubes if number very high
|
||||||
camera.position = {12.0f, 9.0f, 12.0f};
|
camera.position = {12.0f, 9.0f, 12.0f};
|
||||||
@ -51,9 +116,9 @@ int main()
|
|||||||
float posi_x = 0;
|
float posi_x = 0;
|
||||||
float posi_z = 0;
|
float posi_z = 0;
|
||||||
|
|
||||||
for (int i = 0; i < rows; i++)
|
for (int i = 0; i < columns; i++)
|
||||||
{
|
{
|
||||||
for (int j = 0; j < columns; j++)
|
for (int j = 0; j < rows; j++)
|
||||||
{
|
{
|
||||||
positions.push_back({posi_x, 0, posi_z});
|
positions.push_back({posi_x, 0, posi_z});
|
||||||
posi_z += 2;
|
posi_z += 2;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user