For testing purposes send move to server.

This commit is contained in:
Marco 2022-11-13 14:27:00 +01:00
parent 76e141619b
commit aa3e3187c4

View File

@ -1,7 +1,9 @@
import 'dart:async'; import 'dart:async';
import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:flutter_bloc/flutter_bloc.dart';
import 'chess_events.dart'; import 'package:mchess/chess_bloc/chess_events.dart';
import 'package:mchess/chessapp/chess_utils.dart'; import 'package:mchess/chessapp/chess_utils.dart';
import 'package:mchess/connection/ws_connection.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();
@ -18,12 +20,12 @@ class ChessBloc extends Bloc<ChessEvent, ChessBoardState> {
return _instance; return _instance;
} }
FutureOr<void> moveHandler( FutureOr<void> moveHandler(PieceMoved event, Emitter<ChessBoardState> emit) {
PieceMoved event,
Emitter<ChessBoardState> emit,
) {
Map<ChessCoordinate, ChessPiece> newPosition = {}; Map<ChessCoordinate, ChessPiece> newPosition = {};
ServerConnection.getInstance().send(
"from: ${event.startSquare.toString()} to: ${event.endSquare.toString()}");
newPosition[event.endSquare] = state.position[event.startSquare]!; newPosition[event.endSquare] = state.position[event.startSquare]!;
newPosition[event.startSquare] = const ChessPiece.none(); newPosition[event.startSquare] = const ChessPiece.none();