Fix two bugs
1. Fix the bug that made black move first in a new game when the old game was ended during blacks turn. 2. Fix bug that offered the promotion dialog to the player when a pawn was moved on the last rank from any square Also, a late initializer error was fixed because the wrong move variable was used when a pawn reached the last rank.
This commit is contained in:
parent
da986c8d9b
commit
105b6e7565
@ -83,8 +83,12 @@ class ChessSquare extends StatelessWidget {
|
||||
}
|
||||
},
|
||||
builder: (context, candidateData, rejectedData) {
|
||||
var maxDrags =
|
||||
kDebugMode ? 1 : (ChessBloc.turnColor == ChessBloc.myColor ? 1 : 0);
|
||||
var maxDrags = kDebugMode
|
||||
? 1
|
||||
: ((ChessBloc.turnColor == ChessBloc.myColor) &&
|
||||
(containedPiece?.color == ChessBloc.turnColor)
|
||||
? 1
|
||||
: 0);
|
||||
|
||||
return Container(
|
||||
color: color,
|
||||
|
@ -36,6 +36,7 @@ class ChessBloc extends Bloc<ChessEvent, ChessBoardState> {
|
||||
}
|
||||
|
||||
void initBoard(InitBoard event, Emitter<ChessBoardState> emit) {
|
||||
turnColor = ChessColor.white;
|
||||
ChessPosition.getInstance().resetToStartingPosition();
|
||||
emit(ChessBoardState(ChessColor.white, ChessColor.white,
|
||||
ChessPosition.getInstance().currentPosition));
|
||||
|
@ -16,6 +16,14 @@ class PromotionBloc extends Bloc<PromotionEvent, PromotionState> {
|
||||
PawnMovedToPromotionField event,
|
||||
Emitter<PromotionState> emit,
|
||||
) {
|
||||
switch (event.colorMoved) {
|
||||
case ChessColor.white:
|
||||
if (event.move.from.row != 7) return;
|
||||
break;
|
||||
case ChessColor.black:
|
||||
if (event.move.from.row != 2) return;
|
||||
break;
|
||||
}
|
||||
move = event.move;
|
||||
emit(PromotionState(
|
||||
showPromotionDialog: true, colorMoved: event.colorMoved));
|
||||
|
Loading…
Reference in New Issue
Block a user