Fix shit.

This commit is contained in:
Marco 2022-11-13 03:42:30 +01:00
parent f5f89a070d
commit 8ebc010e63
3 changed files with 10 additions and 34 deletions

View File

@ -1,11 +1,7 @@
import 'dart:async';
import 'package:flutter/material.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_square.dart';
class ChessBloc extends Bloc<ChessEvent, ChessBoardState> {
static final ChessBloc _instance = ChessBloc._internal();
@ -40,27 +36,14 @@ class ChessBloc extends Bloc<ChessEvent, ChessBoardState> {
));
}
FutureOr<bool> preCheckHandler(
void preCheckHandler(
PreCheckMove event,
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 {
final bool flipped;
final ChessColor turnColor;
@ -81,16 +64,8 @@ class ChessBoardState {
ChessColor turnColor = ChessColor.white;
Map<ChessCoordinate, ChessPiece> position = {};
for (int row = 1; row <= 8; row++) {
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);
}
}
}
position[ChessCoordinate(1, 1)] =
ChessPiece(ChessPieceName.blackKing, ChessColor.black);
return ChessBoardState._(flipped, turnColor, position);
}

View File

@ -31,9 +31,8 @@ class ChessBoard extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Column(
children: _buildBoard(bState.flipped),
);
print("ChessBoard's build()");
return Column(children: _buildBoard(bState.flipped));
}
Row _buildChessRow(int rowNo, bool flipped) {

View File

@ -1,4 +1,6 @@
import 'package:flutter/material.dart';
import 'package:mchess/chess_bloc/chess_events.dart';
import 'package:mchess/chess_bloc/chess_bloc.dart';
import 'chess_utils.dart';
@ -52,7 +54,7 @@ class ChessSquare extends StatelessWidget {
);
},
onWillAccept: (move) {
print('onWillAccept');
ChessBloc().add(PreCheckMove(move: move!));
return true;
},
onAccept: (move) {