mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 09:48:11 +00:00
Chess: Add pawn promotion to any piece
This commit is contained in:
parent
9d40472721
commit
abd1f7e563
7 changed files with 144 additions and 5 deletions
|
@ -25,6 +25,7 @@
|
|||
*/
|
||||
|
||||
#include "ChessWidget.h"
|
||||
#include "PromotionDialog.h"
|
||||
#include <AK/String.h>
|
||||
#include <LibGUI/MessageBox.h>
|
||||
#include <LibGUI/Painter.h>
|
||||
|
@ -114,7 +115,14 @@ void ChessWidget::mouseup_event(GUI::MouseEvent& event)
|
|||
|
||||
auto target_square = mouse_to_square(event);
|
||||
|
||||
if (board().apply_move({ m_moving_square, target_square })) {
|
||||
Chess::Move move = { m_moving_square, target_square };
|
||||
if (board().is_promotion_move(move)) {
|
||||
auto promotion_dialog = PromotionDialog::construct(*this);
|
||||
if (promotion_dialog->exec() == PromotionDialog::ExecOK)
|
||||
move.promote_to = promotion_dialog->selected_piece();
|
||||
}
|
||||
|
||||
if (board().apply_move(move)) {
|
||||
if (board().game_result() != Chess::Result::NotFinished) {
|
||||
set_drag_enabled(false);
|
||||
update();
|
||||
|
@ -198,6 +206,11 @@ Chess::Square ChessWidget::mouse_to_square(GUI::MouseEvent& event) const
|
|||
}
|
||||
}
|
||||
|
||||
RefPtr<Gfx::Bitmap> ChessWidget::get_piece_graphic(const Chess::Piece& piece) const
|
||||
{
|
||||
return m_pieces.get(piece).value();
|
||||
}
|
||||
|
||||
void ChessWidget::reset()
|
||||
{
|
||||
m_board = Chess();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue