fix swap
continuous-integration/drone/push Build is passing Details

old_branch_before_remy
Jérémy Mouyon 11 months ago
parent e6d13ff00b
commit 43121b4661

@ -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<Tile> tilesToSwap)
{
foreach (var t in tilesToSwap)
{
players[GetPlayingPlayerPosition()].AddTileToPlayer(t);
}
}
/// <summary>
/// Extension of IsMoveCorrect to check beyond the surrounding cells of the cell where the tile is placed
/// </summary>

@ -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;
}

Loading…
Cancel
Save