Fix that only allows the correct pieces to be allowed to move.

This commit is contained in:
Marco 2022-12-22 00:36:30 +01:00
parent 0356268b32
commit bff46e6f3d
2 changed files with 17 additions and 10 deletions

View File

@ -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);
}

View File

@ -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<ChessMove>(