From e0f147b888e3bb88aa3aeeaaee30a30bba23e14b Mon Sep 17 00:00:00 2001
From: "hamar.janos" <hamar.janos@hallgato.ppke.hu>
Date: Thu, 16 May 2024 11:02:36 +0200
Subject: [PATCH] menu

---
 4.0.2.pro       |  46 +++++++++++++++++++++
 application.cpp | 107 ++++++++++++++++++++++++++++++++++++++++++++++++
 main.cpp        |   5 ---
 3 files changed, 153 insertions(+), 5 deletions(-)
 create mode 100644 4.0.2.pro

diff --git a/4.0.2.pro b/4.0.2.pro
new file mode 100644
index 0000000..dccf5d4
--- /dev/null
+++ b/4.0.2.pro
@@ -0,0 +1,46 @@
+TEMPLATE = app
+CONFIG += console c++11
+CONFIG -= app_bundle
+CONFIG -= qt
+
+SOURCES += \
+        application.cpp \
+        bishop.cpp \
+        dropdown.cpp \
+        king.cpp \
+        knight.cpp \
+        konyvtar.cpp \
+        main.cpp \
+        graphics/graphics.cpp \
+        pawn.cpp \
+        puppets.cpp \
+        queen.cpp \
+        rook.cpp
+
+
+INCLUDEPATH += $$PWD/.
+DEPENDPATH += $$PWD/.
+
+win32:CONFIG(release, debug|release): LIBS += -L$$PWD/./ -llibSDL2.dll
+else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/./ -llibSDL2.dll
+else:unix: LIBS += -L$$PWD/./ -llibSDL2.dll
+
+win32:CONFIG(release, debug|release): LIBS += -L$$PWD/./ -llibSDL2_ttf.dll
+else:win32:CONFIG(debug, debug|release): LIBS += -L$$PWD/./ -llibSDL2_ttf.dll
+else:unix: LIBS += -L$$PWD/./ -llibSDL2_ttf.dll
+
+
+INCLUDEPATH += $$PWD/SDL2
+DEPENDPATH += $$PWD/SDL2
+
+HEADERS += \
+    application.hpp \
+    bishop.hpp \
+    dropdown.hpp \
+    king.hpp \
+    knight.hpp \
+    konyvtar.hpp \
+    pawn.hpp \
+    puppets.hpp \
+    queen.hpp \
+    rook.hpp
diff --git a/application.cpp b/application.cpp
index 0d59104..1b75e71 100644
--- a/application.cpp
+++ b/application.cpp
@@ -9,6 +9,111 @@ Application::Application()
     gout.open(641, 641);
 }
 
+void Application::event_loop()
+{
+    event ev;
+    int focus = -1, szam =1;
+    bool in_game = false; // Új változó a játék állapotának nyomon követésére
+
+    while(gin >> ev)
+    {
+        if (!in_game) // Amíg nincs a játékban, ellenőrizzük a "Play" gombot
+        {
+            // Play gomb megrajzolása
+            gout << move_to(270, 300) << color(0, 255, 0) << box(100, 50);
+            gout << move_to(295, 330) << color(0, 0, 0) << text("Play");
+            if(ev.type == ev_mouse && ev.button == btn_left)
+            {
+                if(ev.pos_x >= 270 && ev.pos_x <= 370 && ev.pos_y >= 300 && ev.pos_y <= 350)
+                {
+                    in_game = true; // Ha a "Play" gombra kattintunk, belépünk a játékba
+                    background(); // Újra megrajzoljuk a hátteret a táblával
+                }
+            }
+            gout << refresh;
+            continue;
+        }
+
+        // Eredeti eseménykezelés a játékhoz
+        if(ev.type == ev_mouse && ev.button == btn_left)
+        {
+            focus = -1;
+            for (size_t i = 0; i < puppets.size(); ++i)
+            {
+                if(puppets[i]->select(ev.pos_x,ev.pos_y))
+                {
+                    focus = i;
+                }
+            }
+        }
+        for(Puppets * w : puppets)
+        {
+            w->draw();
+        }
+        if(focus != -1)
+        {
+            if(szam % 2 == 0)       // ha páros akkor a fekete lép
+            {
+                if(puppets[focus]->getColor() == false)
+                {
+                    szam += 1;
+                }
+                else
+                {
+                    focus = -1;
+                }
+            }
+            else                    //ha páratlan akkor a fehér lép
+            {
+                if(puppets[focus]->getColor() == true)
+                {
+                    szam += 1;
+                }
+                else
+                {
+                    focus = -1;
+                }
+            }
+        }
+
+        if(focus != -1)
+        {
+            puppets[focus]->handle(ev);
+            for (size_t i = 0; i < puppets.size(); ++i)
+            {
+                puppets[i]->Pos_steps();
+            }
+            for (size_t i = 0; i < puppets.size(); ++i)
+            {
+                if(puppets[i]->is_king())
+                {
+                    puppets[i]->sakkmatt();
+
+                }
+            }
+            for (size_t i = 0; i < puppets.size(); ++i)
+            {
+                if ((puppets[i]->getColor() && puppets[i]->getY() == 560) || (!puppets[i]->getColor() && puppets[i]->getY() == 0))
+                {
+                    if(puppets[focus]->getX() == puppets[i]->getX() and puppets[focus]->getY() == puppets[i]->getY() )
+                    {
+                        removePuppet(puppets[i]);
+                        background();
+                        for(Puppets * w : puppets)
+                        {
+                            w->draw();
+                        }
+                        break;
+                    }
+                }
+            }
+        }
+        gout << refresh;
+    }
+}
+
+
+/*
 void Application::event_loop()
 {
     event ev;
@@ -69,6 +174,7 @@ void Application::event_loop()
                 if(puppets[i]->is_king())
                 {
                     puppets[i]->sakkmatt();
+
                 }
             }
             for (size_t i = 0; i < puppets.size(); ++i)
@@ -91,6 +197,7 @@ void Application::event_loop()
         gout << refresh;
     }
 }
+*/
 void Application::background()
 {
     gout << move_to(0,0) << color(0,0,0) << box(641,641);
diff --git a/main.cpp b/main.cpp
index 8e1e463..7515cc4 100644
--- a/main.cpp
+++ b/main.cpp
@@ -23,7 +23,6 @@ public:
     void init_pieces()
     {
         // Fehér bábuk inicializálása
-        /*
         r1_1 = new Rook(this, 0, 0, true);
         kn1_1 = new Knight(this, 80, 0, true);
         b1_1 = new Bishop(this, 160, 0, true);
@@ -32,7 +31,6 @@ public:
         b1_2 = new Bishop(this, 400, 0, true);
         kn1_2 = new Knight(this, 480, 0, true);
         r1_2 = new Rook(this, 560, 0, true);
-*/
         p1_1 = new Pawn(this, 0, 80, true);
         p1_2 = new Pawn(this, 80, 80, true);
         p1_3 = new Pawn(this, 160, 80, true);
@@ -41,10 +39,8 @@ public:
         p1_6 = new Pawn(this, 400, 80, true);
         p1_7 = new Pawn(this, 480, 80, true);
         p1_8 = new Pawn(this, 560, 80, true);
-        p1_8 = new Pawn(this, 560, 150, true);
 
         // Fekete bábuk inicializálása
-        /*
         r2_1 = new Rook(this, 0, 560, false);
         kn2_1 = new Knight(this, 80, 560, false);
         b2_1 = new Bishop(this, 160, 560, false);
@@ -53,7 +49,6 @@ public:
         b2_2 = new Bishop(this, 400, 560, false);
         kn2_2 = new Knight(this, 480, 560, false);
         r2_2 = new Rook(this, 560, 560, false);
-*/
         p2_1 = new Pawn(this, 0, 480, false);
         p2_2 = new Pawn(this, 80, 480, false);
         p2_3 = new Pawn(this, 160, 480, false);
-- 
GitLab