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