1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 16:37:35 +00:00

Chess: Added ability to resign and flip the board

This patch adds options to the app's menubar to resign the game and
flip the board.
This commit is contained in:
AnicJov 2020-12-04 13:17:00 +01:00 committed by Andreas Kling
parent 694f68ab86
commit 01b62cc7f4
5 changed files with 76 additions and 0 deletions

View file

@ -288,3 +288,24 @@ void ChessWidget::maybe_input_engine_move()
update();
});
}
void ChessWidget::flip_board()
{
m_side = Chess::opposing_colour(m_side);
update();
}
void ChessWidget::resign()
{
if (m_engine && m_board.turn() != m_side) {
GUI::MessageBox::show(window(), "You can only resign on your turn.", "Resign", GUI::MessageBox::Type::Information);
return;
}
board().set_resigned(m_board.turn());
set_drag_enabled(false);
update();
const String msg = m_board.result_to_string(m_board.game_result());
GUI::MessageBox::show(window(), msg, "Game Over", GUI::MessageBox::Type::Information);
}