Skip to content
Snippets Groups Projects
Commit 6a85c986 authored by Benoît Harrault's avatar Benoît Harrault
Browse files

Fix end game display, minor fixes.

parent ca81e4e0
No related branches found
No related tags found
1 merge request!9Resolve "Fix end game display"
Pipeline #5962 passed
org.gradle.jvmargs=-Xmx1536M
android.useAndroidX=true
android.enableJetifier=true
app.versionName=0.0.8
app.versionCode=8
app.versionName=0.0.9
app.versionCode=9
Fix end game display.
Correction sur affichage de fin de partie.
import 'package:awale/ui/widgets/game/game_player.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
......@@ -15,6 +16,13 @@ class GameLayout extends StatelessWidget {
builder: (BuildContext context, GameState gameState) {
final Game currentGame = gameState.currentGame;
var screenSize = MediaQuery.of(context).size;
const totalMargins = 9 * 4;
final availableHeight = screenSize.height - totalMargins;
final double baseSize = availableHeight / 10;
return Container(
alignment: AlignmentDirectional.topCenter,
padding: const EdgeInsets.all(4),
......@@ -23,10 +31,32 @@ class GameLayout extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
const SizedBox(height: 8),
const GameBoardWidget(),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
currentGame.isFinished
? GameEndWidget(
playerIndex: 0,
widgetSize: baseSize,
)
: GamePlayerWidget(
playerIndex: 0,
widgetSize: baseSize,
),
GameBoardWidget(houseSize: baseSize),
currentGame.isFinished
? GameEndWidget(
playerIndex: 1,
widgetSize: baseSize,
)
: GamePlayerWidget(
playerIndex: 1,
widgetSize: baseSize,
),
],
),
const SizedBox(height: 8),
// const Expanded(child: SizedBox.shrink()),
currentGame.isFinished ? const GameEndWidget() : const SizedBox.shrink(),
],
),
);
......
......@@ -2,42 +2,33 @@ import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:awale/cubit/game_cubit.dart';
import 'package:awale/models/game/game.dart';
import 'package:awale/ui/widgets/game/game_house.dart';
import 'package:awale/ui/widgets/game/game_player.dart';
import 'package:awale/ui/widgets/game/game_score.dart';
class GameBoardWidget extends StatelessWidget {
const GameBoardWidget({super.key});
const GameBoardWidget({
super.key,
required this.houseSize,
});
final double houseSize;
@override
Widget build(BuildContext context) {
return Center(
child: BlocBuilder<GameCubit, GameState>(
builder: (BuildContext context, GameState gameState) {
final Game currentGame = gameState.currentGame;
final Color borderColor = Theme.of(context).colorScheme.onSurface;
var screenSize = MediaQuery.of(context).size;
const totalMargins = 9 * 4;
final availableHeight = screenSize.height - totalMargins;
final double houseHeight = availableHeight / 10;
final double houseWidth = houseHeight;
Widget house(int houseIndex) {
return SizedBox(
width: houseSize,
height: houseSize,
child: GameHouseWidget(cellIndex: houseIndex),
);
}
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
currentGame.isFinished
? const SizedBox.shrink()
: SizedBox(
width: houseWidth,
height: houseHeight,
child: const GamePlayerWidget(playerIndex: 0),
),
Container(
return Container(
margin: const EdgeInsets.all(2),
padding: const EdgeInsets.all(2),
decoration: BoxDecoration(
......@@ -53,103 +44,28 @@ class GameBoardWidget extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
width: 2 * houseWidth,
height: houseHeight,
width: 2 * houseSize,
height: houseSize,
child: const GameScoreWidget(playerIndex: 1),
),
Table(
defaultColumnWidth: const IntrinsicColumnWidth(),
children: [
TableRow(children: [
SizedBox(
width: houseWidth,
height: houseHeight,
child: const GameHouseWidget(cellIndex: 0),
),
SizedBox(
width: houseWidth,
height: houseHeight,
child: const GameHouseWidget(cellIndex: 11),
),
]),
TableRow(children: [
SizedBox(
width: houseWidth,
height: houseHeight,
child: const GameHouseWidget(cellIndex: 1),
),
SizedBox(
width: houseWidth,
height: houseHeight,
child: const GameHouseWidget(cellIndex: 10),
),
]),
TableRow(children: [
SizedBox(
width: houseWidth,
height: houseHeight,
child: const GameHouseWidget(cellIndex: 2),
),
SizedBox(
width: houseWidth,
height: houseHeight,
child: const GameHouseWidget(cellIndex: 9),
),
]),
TableRow(children: [
SizedBox(
width: houseWidth,
height: houseHeight,
child: const GameHouseWidget(cellIndex: 3),
),
SizedBox(
width: houseWidth,
height: houseHeight,
child: const GameHouseWidget(cellIndex: 8),
),
]),
TableRow(children: [
SizedBox(
width: houseWidth,
height: houseHeight,
child: const GameHouseWidget(cellIndex: 4),
),
SizedBox(
width: houseWidth,
height: houseHeight,
child: const GameHouseWidget(cellIndex: 7),
),
]),
TableRow(children: [
SizedBox(
width: houseWidth,
height: houseHeight,
child: const GameHouseWidget(cellIndex: 5),
),
SizedBox(
width: houseWidth,
height: houseHeight,
child: const GameHouseWidget(cellIndex: 6),
),
]),
TableRow(children: [house(0), house(11)]),
TableRow(children: [house(1), house(10)]),
TableRow(children: [house(2), house(9)]),
TableRow(children: [house(3), house(8)]),
TableRow(children: [house(4), house(7)]),
TableRow(children: [house(5), house(6)]),
],
),
SizedBox(
width: 2 * houseWidth,
height: houseHeight,
width: 2 * houseSize,
height: houseSize,
child: const GameScoreWidget(playerIndex: 0),
),
],
),
),
currentGame.isFinished
? const SizedBox.shrink()
: SizedBox(
width: houseWidth,
height: houseHeight,
child: const GamePlayerWidget(playerIndex: 1),
),
],
);
},
),
......
......@@ -3,10 +3,16 @@ import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:awale/cubit/game_cubit.dart';
import 'package:awale/models/game/game.dart';
import 'package:awale/ui/widgets/actions/button_game_quit.dart';
class GameEndWidget extends StatelessWidget {
const GameEndWidget({super.key});
const GameEndWidget({
super.key,
required this.playerIndex,
required this.widgetSize,
});
final int playerIndex;
final double widgetSize;
@override
Widget build(BuildContext context) {
......@@ -14,49 +20,61 @@ class GameEndWidget extends StatelessWidget {
builder: (BuildContext context, GameState gameState) {
final Game currentGame = gameState.currentGame;
const Image imageWinner = Image(
image: AssetImage('assets/ui/game_win.png'),
fit: BoxFit.fill,
);
const Image imageLoser = Image(
image: AssetImage('assets/ui/game_fail.png'),
fit: BoxFit.fill,
);
const Image imageDraw = Image(
image: AssetImage('assets/ui/game_draw.png'),
final String playerImageAsset =
currentGame.scores[playerIndex] == currentGame.scores[1 - playerIndex]
? 'assets/ui/game_draw.png'
: (currentGame.scores[playerIndex] > currentGame.scores[1 - playerIndex]
? 'assets/ui/game_win.png'
: 'assets/ui/game_fail.png');
final Image playerImage = Image(
image: AssetImage(playerImageAsset),
fit: BoxFit.fill,
height: widgetSize,
);
final Image player1 = currentGame.scores[0] == currentGame.scores[1]
? imageDraw
: (currentGame.scores[0] > currentGame.scores[1] ? imageWinner : imageLoser);
final Image player2 = currentGame.scores[0] == currentGame.scores[1]
? imageDraw
: (currentGame.scores[1] > currentGame.scores[0] ? imageWinner : imageLoser);
return Container(
return RotatedBox(
quarterTurns: 1 + 2 * playerIndex,
child: Container(
margin: const EdgeInsets.all(2),
padding: const EdgeInsets.all(2),
height: widgetSize,
child: Table(
defaultColumnWidth: const IntrinsicColumnWidth(),
children: [
TableRow(
children: [
Column(
children: [player1],
children: [playerImage],
),
Column(
children: [
currentGame.animationInProgress ? imageWinner : const QuitGameButton()
currentGame.animationInProgress
? Image(
image: const AssetImage('assets/ui/placeholder.png'),
fit: BoxFit.fill,
height: widgetSize,
)
: ElevatedButton(
child: Image(
image: const AssetImage('assets/ui/button_back.png'),
fit: BoxFit.fill,
height: widgetSize,
),
onPressed: () {
BlocProvider.of<GameCubit>(context).quitGame();
},
)
],
),
Column(
children: [player2],
children: [playerImage],
),
],
),
],
),
),
);
},
);
......
......@@ -10,9 +10,11 @@ class GamePlayerWidget extends StatelessWidget {
const GamePlayerWidget({
super.key,
required this.playerIndex,
required this.widgetSize,
});
final int playerIndex;
final double widgetSize;
@override
Widget build(BuildContext context) {
......@@ -37,6 +39,8 @@ class GamePlayerWidget extends StatelessWidget {
width: 6,
),
),
width: widgetSize,
height: widgetSize,
child: GameSeedsWidget(seedsCount: seedsCount),
);
},
......
......@@ -3,7 +3,7 @@ description: Awale game
publish_to: "none"
version: 0.0.8+8
version: 0.0.9+9
environment:
sdk: "^3.0.0"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment