Newer
Older
import 'package:reversi/config/styling.dart';
import 'package:reversi/models/activity/game_board.dart';
import 'package:reversi/models/activity/game_model.dart';
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
class GameBoardDisplay extends StatelessWidget {
const GameBoardDisplay({
super.key,
required this.context,
required this.model,
required this.callback,
});
final BuildContext context;
final GameModel model;
final Function callback;
@override
Widget build(BuildContext context) {
final rows = <TableRow>[];
for (int y = 0; y < GameBoard.height; y++) {
final cells = <Column>[];
for (int x = 0; x < GameBoard.width; x++) {
PieceType pieceType = model.board.getPieceAtLocation(x, y);
String? assetImageCode = Styling.assetImageCodes[pieceType];
String assetImageName =
'assets/skins/${model.skin}_tile_${assetImageCode ?? 'empty'}.png';
Column cell = Column(
children: [
Container(
decoration: Styling.boardCellDecoration,
child: SizedBox(
child: GestureDetector(
child: AnimatedSwitcher(
duration: const Duration(milliseconds: 250),
transitionBuilder: (Widget child, Animation<double> animation) {
return ScaleTransition(
scale: animation,
child: child,
);
},
child: Image(
image: AssetImage(assetImageName),
fit: BoxFit.fill,
key: ValueKey<int>(
pieceType == PieceType.empty
? 0
: (pieceType == PieceType.black ? 1 : 2),
),
),
),
onTap: () {
callback(model, x, y);
},
),
),
)
],
);
cells.add(cell);
}
rows.add(TableRow(
children: cells,
));
}
return Table(
defaultColumnWidth: const IntrinsicColumnWidth(),
children: rows,
);
}
}