From 43121b4661210ba2b398cd0734d04dad7c073c1c Mon Sep 17 00:00:00 2001 From: "jeremy.mouyon" Date: Thu, 6 Jun 2024 13:04:28 +0200 Subject: [PATCH] fix swap --- Qwirkle/QwirkleClassLibrary/Games/Game.cs | 12 ++++++++++++ Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs | 8 ++------ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs index 194c1bb..732fdb2 100644 --- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -409,18 +409,21 @@ namespace QwirkleClassLibrary.Games if (cellUsed.Count != 0) { OnSwapTiles(new SwapTilesNotifiedEventArgs("You can't swap tiles after placing some !")); + ReSwap(tilesToSwap); return false; } if (tilesToSwap.Count == 0) { OnSwapTiles(new SwapTilesNotifiedEventArgs("You must select at least one tile to swap !")); + ReSwap(tilesToSwap); return false; } if (bag!.TilesBag!.Count < tilesToSwap.Count) { OnSwapTiles(new SwapTilesNotifiedEventArgs("Not enough tiles in the bag to swap !")); + ReSwap(tilesToSwap); return false; } @@ -437,6 +440,15 @@ namespace QwirkleClassLibrary.Games return true; } + private void ReSwap(List tilesToSwap) + { + foreach (var t in tilesToSwap) + { + players[GetPlayingPlayerPosition()].AddTileToPlayer(t); + } + + } + /// /// Extension of IsMoveCorrect to check beyond the surrounding cells of the cell where the tile is placed /// diff --git a/Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs b/Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs index 63c0983..92c4fd9 100644 --- a/Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs +++ b/Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs @@ -94,9 +94,11 @@ public partial class Gameboard : ContentPage if (game.PlayerSwapping) { + game.SwapTilesNotified += Game_SwapTilesNotified; game.SwapTiles(game.GetPlayingPlayer(), tilesSwap); tilesSwap.Clear(); game.PlayerSwapping = false; + game.SwapTilesNotified -= Game_SwapTilesNotified; } else { @@ -169,18 +171,12 @@ public partial class Gameboard : ContentPage private void OnButtonSwapClicked(object sender, EventArgs e) { game.PlaceTileNotified += Game_PlaceTileNotified; - game.SwapTilesNotified += Game_SwapTilesNotified; if (game.CellsUsed.Count == 0 && !game.PlayerSwapping) { - //DisplayAlert("Swap system", "\r\nWelcome to the swap system! To use the system, take the tiles you wish to swap and place them in the bag (you will not see the tiles disappear). Then, click on the skip button. /!\\ Attention, during the swap phase, you cannot play /!\\", "Copy !"); AnswerSwap(); - - - } - game.SwapTilesNotified -= Game_SwapTilesNotified; game.PlaceTileNotified -= Game_PlaceTileNotified; }