Skip to content
Snippets Groups Projects
Commit a841e10e authored by Bolla Péter's avatar Bolla Péter
Browse files

Update app.cpp

parent bd35ab93
No related branches found
No related tags found
No related merge requests found
#include "app.hpp" #include "app.hpp"
#include "widget.hpp" #include "widget.hpp"
#include "graphics.hpp"
#include <iostream>
using namespace genv; using namespace genv;
...@@ -9,10 +11,13 @@ App::App(int width, int height) { ...@@ -9,10 +11,13 @@ App::App(int width, int height) {
} }
void App::event_loop() void App::event_loop(Chess* chessboard)
{ {
Team moveteam = Light;
event ev; event ev;
int focus = -1; int focus = -1;
int of = -1;
std::vector<int> pm;
while(gin>>ev) while(gin>>ev)
{ {
if(ev.type == ev_mouse&&ev.button == btn_left){ if(ev.type == ev_mouse&&ev.button == btn_left){
...@@ -20,7 +25,94 @@ void App::event_loop() ...@@ -20,7 +25,94 @@ void App::event_loop()
if(widgets[i]->Selected(ev.pos_x,ev.pos_y)) focus = i; if(widgets[i]->Selected(ev.pos_x,ev.pos_y)) focus = i;
} }
} }
if(focus != -1) widgets[focus]->Handle(ev); if(focus != -1)
{
if(of != -1)
{
widgets[of]->Handle(ev, RELEASE);
for(int a = 0; a<pm.size(); a++)
{
widgets[pm[a]]->Handle(ev, DEACTIVATE);
}
}
/*switch(chessboard->GetSquare(focus).piece.type)
{
case Pawn:
{
std::cout<<'P';
break;
}
case Rook:{
std::cout<<'R';
break;
}
case Knight:
{
std::cout<<'N';
break;
}
case Bishop:{
std::cout<<'B';
break;
}
case King:{
std::cout<<'K';
break;
}
case Queen:{
std::cout<<'Q';
break;
}
case Empty:
{
std::cout<<'X';
break;
}
}*/
if(ev.type == ev_mouse && ev.button == btn_left && chessboard->GetSquare(focus).occupied)
{
if(chessboard->GetPiece(focus).team == moveteam)
{
widgets[focus]->Handle(ev, PRESS);
pm = chessboard->PossibleMoves(focus);
for(int a = 0; a<pm.size(); a++)
{
widgets[pm[a]]->Handle(ev, ACTIVATE);
}
}
else if(of!=-1){
if(chessboard->GetPiece(of).team != chessboard->GetPiece(focus).team)
{
if(chessboard->CanMove(of, focus) == Mov)
{
chessboard->Move(of, focus);
moveteam = (moveteam == Light) ? Dark : Light;
widgets[of]->Handle(ev, RELEASE);
widgets[focus]->Handle(ev, RELEASE);
for (int a = 0; a < pm.size(); a++) {
widgets[pm[a]]->Handle(ev, DEACTIVATE);
}
}
else if(chessboard->CanMove(of, focus) == Cap)
{
chessboard->Capture(of, focus);
moveteam = (moveteam == Light) ? Dark : Light;
widgets[of]->Handle(ev, RELEASE);
widgets[focus]->Handle(ev, RELEASE);
for (int a = 0; a < pm.size(); a++) {
widgets[pm[a]]->Handle(ev, DEACTIVATE);
}
}
}
}
}
of = focus;
focus = -1;
}
for(Widget* w:widgets) w->Draw(); for(Widget* w:widgets) w->Draw();
gout<<refresh; gout<<refresh;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment