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

Merge branch '5-detect-end-game' into 'master'

Resolve "Detect end game"

Closes #5

See merge request !3
parents 0fa5cd2e 870e985a
No related branches found
No related tags found
1 merge request!3Resolve "Detect end game"
Pipeline #5923 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.2 app.versionName=0.0.3
app.versionCode=2 app.versionCode=3
assets/ui/game_draw.png

170 B

assets/ui/game_fail.png

3.56 KiB | W: | H:

assets/ui/game_fail.png

170 B | W: | H:

assets/ui/game_fail.png
assets/ui/game_fail.png
assets/ui/game_fail.png
assets/ui/game_fail.png
  • 2-up
  • Swipe
  • Onion skin
End game management.
Gestion de la fin de partie.
...@@ -37,7 +37,7 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -37,7 +37,7 @@ class GameCubit extends HydratedCubit<GameState> {
currentPlayer: state.currentGame.currentPlayer, currentPlayer: state.currentGame.currentPlayer,
scores: state.currentGame.scores, scores: state.currentGame.scores,
); );
game.dump(); // game.dump();
updateState(game); updateState(game);
} }
...@@ -108,6 +108,12 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -108,6 +108,12 @@ class GameCubit extends HydratedCubit<GameState> {
toggleCurrentPlayer(); toggleCurrentPlayer();
if (!state.currentGame.canPlay()) {
printlog('user has no more move to play');
state.currentGame.isFinished = true;
refresh();
}
state.currentGame.animationInProgress = false; state.currentGame.animationInProgress = false;
refresh(); refresh();
} }
...@@ -139,17 +145,20 @@ class GameCubit extends HydratedCubit<GameState> { ...@@ -139,17 +145,20 @@ class GameCubit extends HydratedCubit<GameState> {
if (state.currentGame.isOpponentHouse(lastCellIndex)) { if (state.currentGame.isOpponentHouse(lastCellIndex)) {
final int seedsCount = state.currentGame.board.cells[lastCellIndex]; final int seedsCount = state.currentGame.board.cells[lastCellIndex];
printlog('found $seedsCount seed(s) on final house.'); printlog('found $seedsCount seed(s) on final house');
if ([2, 3].contains(seedsCount)) { if ([2, 3].contains(seedsCount)) {
printlog('ok will earn these seeds.'); printlog('-> ok will earn these seeds');
state.currentGame.board.cells[lastCellIndex] = 0; state.currentGame.board.cells[lastCellIndex] = 0;
state.currentGame.scores[state.currentGame.currentPlayer] += seedsCount; state.currentGame.scores[state.currentGame.currentPlayer] += seedsCount;
refresh(); refresh();
// (recursively) check previous cells // (recursively) check previous cells
printlog('-> dispatch to previous cell');
animateSeedsEarning(state.currentGame.getPreviousCellIndex(lastCellIndex)); animateSeedsEarning(state.currentGame.getPreviousCellIndex(lastCellIndex));
} else {
printlog('-> nothing to do');
} }
} }
} }
......
...@@ -124,6 +124,15 @@ class Game { ...@@ -124,6 +124,15 @@ class Game {
return false; return false;
} }
bool canPlay() {
for (int cellIndex = 0; cellIndex < board.cells.length; cellIndex++) {
if (isCurrentPlayerHouse(cellIndex) && isMoveAllowed(cellIndex)) {
return true;
}
}
return false;
}
void dump() { void dump() {
printlog(''); printlog('');
printlog('## Current game dump:'); printlog('## Current game dump:');
......
...@@ -39,7 +39,7 @@ class GameBoardWidget extends StatelessWidget { ...@@ -39,7 +39,7 @@ class GameBoardWidget extends StatelessWidget {
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
GamePlayerWidget( GamePlayerWidget(
active: currentGame.currentPlayer == 0, active: !currentGame.isFinished && currentGame.currentPlayer == 0,
), ),
Container( Container(
margin: const EdgeInsets.all(2), margin: const EdgeInsets.all(2),
...@@ -95,7 +95,7 @@ class GameBoardWidget extends StatelessWidget { ...@@ -95,7 +95,7 @@ class GameBoardWidget extends StatelessWidget {
), ),
), ),
GamePlayerWidget( GamePlayerWidget(
active: currentGame.currentPlayer == 1, active: !currentGame.isFinished && currentGame.currentPlayer == 1,
), ),
], ],
); );
......
...@@ -14,10 +14,25 @@ class GameEndWidget extends StatelessWidget { ...@@ -14,10 +14,25 @@ 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 decorationImage = Image( const Image imageWinner = Image(
image: AssetImage('assets/ui/game_win.png'), image: AssetImage('assets/ui/game_win.png'),
fit: BoxFit.fill, 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'),
fit: BoxFit.fill,
);
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 Container(
margin: const EdgeInsets.all(2), margin: const EdgeInsets.all(2),
...@@ -27,18 +42,16 @@ class GameEndWidget extends StatelessWidget { ...@@ -27,18 +42,16 @@ class GameEndWidget extends StatelessWidget {
children: [ children: [
TableRow( TableRow(
children: [ children: [
const Column( Column(
children: [decorationImage], children: [player1],
), ),
Column( Column(
children: [ children: [
currentGame.animationInProgress currentGame.animationInProgress ? imageWinner : const QuitGameButton()
? decorationImage
: const QuitGameButton()
], ],
), ),
const Column( Column(
children: [decorationImage], children: [player2],
), ),
], ],
), ),
......
...@@ -3,7 +3,7 @@ description: Awale game ...@@ -3,7 +3,7 @@ description: Awale game
publish_to: "none" publish_to: "none"
version: 0.0.2+2 version: 0.0.3+3
environment: environment:
sdk: "^3.0.0" sdk: "^3.0.0"
......
<?xml version="1.0" encoding="UTF-8"?>
<svg enable-background="new 0 0 100 100" version="1.1" viewBox="0 0 93.665 93.676" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"/>
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<svg enable-background="new 0 0 100 100" version="1.1" viewBox="0 0 93.665 93.676" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"><rect x=".44662" y=".89101" width="92.772" height="91.894" ry="11.689" fill="#d11717" stroke="#fff" stroke-width=".238"/><path d="m71.624 59.304c3.5089 3.5089 3.5089 9.0561 0 12.565-1.6976 1.6976-3.9623 2.6034-6.2261 2.6034s-4.5275-0.90569-6.2261-2.6034l-12.452-12.452-12.452 12.452c-1.6976 1.6976-3.9623 2.6034-6.2261 2.6034s-4.5275-0.90569-6.2261-2.6034c-3.5089-3.5089-3.5089-9.0561 0-12.565l12.452-12.452-12.452-12.452c-3.5089-3.5089-3.5089-9.0561 0-12.565s9.0561-3.5089 12.565 0l12.452 12.452 12.452-12.452c3.5089-3.5089 9.0561-3.5089 12.565 0s3.5089 9.0561 0 12.565l-12.452 12.452z" fill="#e7e7e7" stroke-width=".20213"/></svg> <svg enable-background="new 0 0 100 100" version="1.1" viewBox="0 0 93.665 93.676" xml:space="preserve" xmlns="http://www.w3.org/2000/svg"/>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment