From bff46e6f3dff8ffa5cfec698a96ccbfc68f89ee1 Mon Sep 17 00:00:00 2001 From: Marco Date: Thu, 22 Dec 2022 00:36:30 +0100 Subject: [PATCH] Fix that only allows the correct pieces to be allowed to move. --- lib/chess_bloc/chess_bloc.dart | 16 ++++++++-------- lib/chessapp/chess_square.dart | 11 +++++++++-- 2 files changed, 17 insertions(+), 10 deletions(-) diff --git a/lib/chess_bloc/chess_bloc.dart b/lib/chess_bloc/chess_bloc.dart index f7222ce..b3c21fc 100644 --- a/lib/chess_bloc/chess_bloc.dart +++ b/lib/chess_bloc/chess_bloc.dart @@ -101,21 +101,21 @@ class ChessBoardState { ChessPiece(ChessPieceName.blackRook, ChessColor.black); position[ChessCoordinate(1, 1)] = - ChessPiece(ChessPieceName.whiteRook, ChessColor.black); + ChessPiece(ChessPieceName.whiteRook, ChessColor.white); position[ChessCoordinate(2, 1)] = - ChessPiece(ChessPieceName.whiteKnight, ChessColor.black); + ChessPiece(ChessPieceName.whiteKnight, ChessColor.white); position[ChessCoordinate(3, 1)] = - ChessPiece(ChessPieceName.whiteBishop, ChessColor.black); + ChessPiece(ChessPieceName.whiteBishop, ChessColor.white); position[ChessCoordinate(4, 1)] = - ChessPiece(ChessPieceName.whiteQueen, ChessColor.black); + ChessPiece(ChessPieceName.whiteQueen, ChessColor.white); position[ChessCoordinate(5, 1)] = - ChessPiece(ChessPieceName.whiteKing, ChessColor.black); + ChessPiece(ChessPieceName.whiteKing, ChessColor.white); position[ChessCoordinate(6, 1)] = - ChessPiece(ChessPieceName.whiteBishop, ChessColor.black); + ChessPiece(ChessPieceName.whiteBishop, ChessColor.white); position[ChessCoordinate(7, 1)] = - ChessPiece(ChessPieceName.whiteKnight, ChessColor.black); + ChessPiece(ChessPieceName.whiteKnight, ChessColor.white); position[ChessCoordinate(8, 1)] = - ChessPiece(ChessPieceName.whiteRook, ChessColor.black); + ChessPiece(ChessPieceName.whiteRook, ChessColor.white); return ChessBoardState._(bottomColor, turnColor, position); } diff --git a/lib/chessapp/chess_square.dart b/lib/chessapp/chess_square.dart index c1d0308..355e925 100644 --- a/lib/chessapp/chess_square.dart +++ b/lib/chessapp/chess_square.dart @@ -1,7 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; -import 'package:mchess/chess_bloc/chess_events.dart'; import 'package:mchess/chess_bloc/chess_bloc.dart'; import '../connection/ws_connection.dart'; @@ -73,7 +72,15 @@ class ChessSquare extends StatelessWidget { if (ChessBloc.myColor == null) { allowDrags = 0; } else { - allowDrags = ChessBloc.myColor == state.newTurnColor ? 1 : 0; + if (containedPiece == null) { + allowDrags = 0; + } else if (containedPiece!.color == ChessBloc.myColor) { + if (ChessBloc.myColor == state.newTurnColor) { + allowDrags = 1; + } else { + allowDrags = 0; + } + } } return Draggable(