46 lines
1.3 KiB
Dart
46 lines
1.3 KiB
Dart
import 'package:boardgames_app/components/checker_comp.dart';
|
|
import 'package:boardgames_app/games/checkers.dart';
|
|
import 'package:boardgames_core/core.dart';
|
|
import 'package:boardgames_core/commons.dart';
|
|
import 'package:boardgames_core/games.dart';
|
|
import 'package:flame/components.dart';
|
|
import 'package:flame/events.dart';
|
|
import 'package:flutter/material.dart';
|
|
|
|
final Paint highlight = Paint()..color = Colors.lightBlueAccent;
|
|
|
|
class EmptyCell extends PositionComponent with HasGameRef<CheckersGame>, Tappable {
|
|
Board board;
|
|
CellPosition boardPosition;
|
|
bool highlighted = false;
|
|
|
|
EmptyCell(this.board, this.boardPosition);
|
|
|
|
@override
|
|
bool onTapDown(TapDownInfo event) {
|
|
CheckerComp? selected = gameRef.getSelectedChecker();
|
|
|
|
if (selected == null) {
|
|
return true;
|
|
}
|
|
if (selected.checker.canMoveTo(boardPosition)) {
|
|
selected.selected = false;
|
|
game.makeMove(selected.checker, boardPosition);
|
|
return false;
|
|
}
|
|
return super.onTapDown(event);
|
|
}
|
|
|
|
void checkHightlight(Checker? selected) {
|
|
highlighted = selected != null && selected.canMoveTo(boardPosition);
|
|
}
|
|
|
|
@override
|
|
void render(Canvas canvas) {
|
|
if (highlighted) {
|
|
final cellSize = size.toSize().width;
|
|
canvas.drawRect(Rect.fromLTWH(0, 0, cellSize, cellSize), highlight);
|
|
}
|
|
}
|
|
}
|