85 lines
2.1 KiB
Dart
85 lines
2.1 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:flutter_svg/svg.dart';
|
|
|
|
enum ChessPieceName {
|
|
none,
|
|
whitePawn,
|
|
whiteBishop,
|
|
whiteKnight,
|
|
whiteRook,
|
|
whiteQueen,
|
|
whiteKing,
|
|
blackPawn,
|
|
blackBishop,
|
|
blackKnight,
|
|
blackRook,
|
|
blackQueen,
|
|
blackKing,
|
|
}
|
|
|
|
enum ChessColor { black, white }
|
|
|
|
Map<ChessPieceName, String> chessPiecesAssets = {
|
|
ChessPieceName.whitePawn: 'assets/pieces/white/pawn.svg',
|
|
ChessPieceName.whiteBishop: 'assets/pieces/white/bishop.svg',
|
|
ChessPieceName.whiteKnight: 'assets/pieces/white/knight.svg',
|
|
ChessPieceName.whiteRook: 'assets/pieces/white/rook.svg',
|
|
ChessPieceName.whiteQueen: 'assets/pieces/white/queen.svg',
|
|
ChessPieceName.whiteKing: 'assets/pieces/white/king.svg',
|
|
ChessPieceName.blackPawn: 'assets/pieces/black/pawn.svg',
|
|
ChessPieceName.blackBishop: 'assets/pieces/black/bishop.svg',
|
|
ChessPieceName.blackKnight: 'assets/pieces/black/knight.svg',
|
|
ChessPieceName.blackRook: 'assets/pieces/black/rook.svg',
|
|
ChessPieceName.blackQueen: 'assets/pieces/black/queen.svg',
|
|
ChessPieceName.blackKing: 'assets/pieces/black/king.svg',
|
|
};
|
|
|
|
class ChessCoordinate {
|
|
late int column;
|
|
late int row;
|
|
|
|
ChessCoordinate(this.column, this.row);
|
|
|
|
static String columnIntToColumnString(int col) {
|
|
String colStr;
|
|
|
|
colStr = String.fromCharCode(col + 96);
|
|
|
|
return colStr;
|
|
}
|
|
|
|
static int columnStringToColumnInt(String col) {
|
|
int colInt;
|
|
colInt = col.codeUnitAt(0) - 96;
|
|
return colInt;
|
|
}
|
|
}
|
|
|
|
class ChessPiece extends StatelessWidget {
|
|
final ChessColor color;
|
|
final ChessPieceName pieceName;
|
|
late final Widget pieceImage;
|
|
|
|
ChessPiece(this.pieceName, this.color, {super.key}) {
|
|
String pieceAssetUrl = chessPiecesAssets[pieceName]!;
|
|
|
|
pieceImage = SvgPicture.asset(pieceAssetUrl);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SizedBox(
|
|
child: pieceImage,
|
|
);
|
|
}
|
|
}
|
|
|
|
class ChessMove {
|
|
ChessCoordinate startSquare;
|
|
ChessCoordinate endSquare;
|
|
ChessPiece? movedPiece;
|
|
ChessPiece? pieceOnEndSquare;
|
|
|
|
ChessMove(this.startSquare, this.endSquare, this.movedPiece);
|
|
}
|