Fix shit.
This commit is contained in:
parent
f5f89a070d
commit
8ebc010e63
@ -1,11 +1,7 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||||
import 'package:mchess/chessapp/chess_board.dart';
|
import 'chess_events.dart';
|
||||||
|
|
||||||
import 'package:mchess/chessapp/chess_utils.dart';
|
import 'package:mchess/chessapp/chess_utils.dart';
|
||||||
import 'package:mchess/chessapp/chess_square.dart';
|
|
||||||
|
|
||||||
class ChessBloc extends Bloc<ChessEvent, ChessBoardState> {
|
class ChessBloc extends Bloc<ChessEvent, ChessBoardState> {
|
||||||
static final ChessBloc _instance = ChessBloc._internal();
|
static final ChessBloc _instance = ChessBloc._internal();
|
||||||
@ -40,27 +36,14 @@ class ChessBloc extends Bloc<ChessEvent, ChessBoardState> {
|
|||||||
));
|
));
|
||||||
}
|
}
|
||||||
|
|
||||||
FutureOr<bool> preCheckHandler(
|
void preCheckHandler(
|
||||||
PreCheckMove event,
|
PreCheckMove event,
|
||||||
Emitter<ChessBoardState> emit,
|
Emitter<ChessBoardState> emit,
|
||||||
) {
|
) {
|
||||||
return false;
|
print('Pretending to check a move before you drop a piece');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract class ChessEvent {}
|
|
||||||
|
|
||||||
class PieceMoved extends ChessEvent {
|
|
||||||
final ChessCoordinate startSquare;
|
|
||||||
final ChessCoordinate endSquare;
|
|
||||||
|
|
||||||
PieceMoved({required this.startSquare, required this.endSquare});
|
|
||||||
}
|
|
||||||
|
|
||||||
class PreCheckMove extends ChessEvent {}
|
|
||||||
|
|
||||||
class BoardFlippedEvent extends ChessEvent {}
|
|
||||||
|
|
||||||
class ChessBoardState {
|
class ChessBoardState {
|
||||||
final bool flipped;
|
final bool flipped;
|
||||||
final ChessColor turnColor;
|
final ChessColor turnColor;
|
||||||
@ -81,16 +64,8 @@ class ChessBoardState {
|
|||||||
ChessColor turnColor = ChessColor.white;
|
ChessColor turnColor = ChessColor.white;
|
||||||
Map<ChessCoordinate, ChessPiece> position = {};
|
Map<ChessCoordinate, ChessPiece> position = {};
|
||||||
|
|
||||||
for (int row = 1; row <= 8; row++) {
|
position[ChessCoordinate(1, 1)] =
|
||||||
for (int col = 1; col <= 8; col++) {
|
|
||||||
position[ChessCoordinate(row, col)] =
|
|
||||||
ChessPiece(ChessPieceName.none, ChessColor.white);
|
|
||||||
if (col == 1 && row == 4) {
|
|
||||||
position[ChessCoordinate(col, row)] =
|
|
||||||
ChessPiece(ChessPieceName.blackKing, ChessColor.black);
|
ChessPiece(ChessPieceName.blackKing, ChessColor.black);
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return ChessBoardState._(flipped, turnColor, position);
|
return ChessBoardState._(flipped, turnColor, position);
|
||||||
}
|
}
|
||||||
|
@ -31,9 +31,8 @@ class ChessBoard extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Column(
|
print("ChessBoard's build()");
|
||||||
children: _buildBoard(bState.flipped),
|
return Column(children: _buildBoard(bState.flipped));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Row _buildChessRow(int rowNo, bool flipped) {
|
Row _buildChessRow(int rowNo, bool flipped) {
|
||||||
|
@ -1,4 +1,6 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'package:mchess/chess_bloc/chess_events.dart';
|
||||||
import 'package:mchess/chess_bloc/chess_bloc.dart';
|
import 'package:mchess/chess_bloc/chess_bloc.dart';
|
||||||
|
|
||||||
import 'chess_utils.dart';
|
import 'chess_utils.dart';
|
||||||
@ -52,7 +54,7 @@ class ChessSquare extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
onWillAccept: (move) {
|
onWillAccept: (move) {
|
||||||
print('onWillAccept');
|
ChessBloc().add(PreCheckMove(move: move!));
|
||||||
return true;
|
return true;
|
||||||
},
|
},
|
||||||
onAccept: (move) {
|
onAccept: (move) {
|
||||||
|
Loading…
Reference in New Issue
Block a user