2022-11-12 21:55:45 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-09-04 19:39:51 +00:00
|
|
|
import 'package:mchess/chess/chess_square_outer_dragtarget.dart';
|
2022-12-25 15:16:23 +00:00
|
|
|
import '../utils/chess_utils.dart';
|
2022-11-12 21:55:45 +00:00
|
|
|
|
2022-11-13 01:42:10 +00:00
|
|
|
class ChessSquare extends StatelessWidget {
|
2022-11-12 21:55:45 +00:00
|
|
|
final ChessCoordinate coordinate;
|
2022-11-13 12:09:36 +00:00
|
|
|
final ChessPiece? containedPiece;
|
2022-11-12 21:55:45 +00:00
|
|
|
static const double pieceWidth = 200;
|
|
|
|
static const double pieceHeight = 200;
|
|
|
|
|
2022-11-13 12:09:36 +00:00
|
|
|
final Color color;
|
2022-11-12 21:55:45 +00:00
|
|
|
|
2023-08-19 01:45:03 +00:00
|
|
|
const ChessSquare._({
|
|
|
|
required this.coordinate,
|
|
|
|
required this.containedPiece,
|
|
|
|
required this.color,
|
|
|
|
});
|
|
|
|
|
|
|
|
factory ChessSquare(
|
|
|
|
ChessCoordinate coord, ChessPiece? piece, bool wasPartOfLastMove) {
|
|
|
|
Color lightSquaresColor =
|
|
|
|
wasPartOfLastMove ? Colors.green.shade200 : Colors.brown.shade50;
|
|
|
|
Color darkSquaresColor =
|
|
|
|
wasPartOfLastMove ? Colors.green.shade300 : Colors.brown.shade400;
|
2022-11-13 12:09:36 +00:00
|
|
|
|
|
|
|
Color squareColor;
|
|
|
|
|
|
|
|
if (coord.row % 2 == 0) {
|
|
|
|
if (coord.column % 2 == 0) {
|
2023-08-19 01:45:03 +00:00
|
|
|
squareColor = darkSquaresColor;
|
2022-11-13 12:09:36 +00:00
|
|
|
} else {
|
2023-08-19 01:45:03 +00:00
|
|
|
squareColor = lightSquaresColor;
|
2022-11-13 12:09:36 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (coord.column % 2 == 0) {
|
2023-08-19 01:45:03 +00:00
|
|
|
squareColor = lightSquaresColor;
|
2022-11-13 12:09:36 +00:00
|
|
|
} else {
|
2023-08-19 01:45:03 +00:00
|
|
|
squareColor = darkSquaresColor;
|
2022-11-13 12:09:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ChessSquare._(
|
|
|
|
coordinate: coord,
|
|
|
|
containedPiece: piece,
|
|
|
|
color: squareColor,
|
|
|
|
);
|
|
|
|
}
|
2022-11-12 21:55:45 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-09-04 19:39:51 +00:00
|
|
|
return Container(
|
|
|
|
color: color,
|
|
|
|
child: ChessSquareOuterDragTarget(
|
|
|
|
coordinate: coordinate,
|
|
|
|
containedPiece: containedPiece ?? const ChessPiece.none()),
|
2022-11-12 21:55:45 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|