IS WORK MATE
continuous-integration/drone/push Build is failing Details

test_old_branch
Jérémy Mouyon 11 months ago
parent 61690732b1
commit 87911f1ee0

@ -317,6 +317,11 @@ namespace QwirkleClassLibrary.Games
/// <returns>bool</returns> /// <returns>bool</returns>
public bool PlaceTile(Player player, Tile tile, int x, int y) public bool PlaceTile(Player player, Tile tile, int x, int y)
{ {
if(!TileInbag(player, tile))
{
OnPlaceTile(new PlaceTileNotifiedEventArgs(tile, "you cant play"));
return false;
}
if (!IsMoveCorrect(tile, x, y, board!)) return false; if (!IsMoveCorrect(tile, x, y, board!)) return false;
if (board!.AddTileInCell(x, y, tile)) if (board!.AddTileInCell(x, y, tile))
{ {
@ -328,6 +333,18 @@ namespace QwirkleClassLibrary.Games
return false; return false;
} }
public bool TileInbag(Player player, Tile tile)
{
for (int i = 0; i < player.Tiles.Count; i++)
{
Tile? t = player.Tiles[i];
if (Object.ReferenceEquals(t, tile)) return true;
}
return false;
}
/// <summary> /// <summary>
/// Allows a player to draw tiles from the bag as soon as he has less than 6 tiles /// Allows a player to draw tiles from the bag as soon as he has less than 6 tiles
@ -494,7 +511,7 @@ namespace QwirkleClassLibrary.Games
return true; return true;
} }
if (b.GetCell(x, y)!.Tile == null) if (b.GetCell(x, y)!.Tile != null)
{ {
OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " : Cell already used !")); OnPlaceTile(new PlaceTileNotifiedEventArgs(t, " : Cell already used !"));
} }

@ -6,14 +6,23 @@ using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using QwirkleClassLibrary.Boards;
using QwirkleClassLibrary.Tiles; using QwirkleClassLibrary.Tiles;
namespace QwirkleClassLibrary.Players namespace QwirkleClassLibrary.Players
{ {
public class Player : INotifyPropertyChanged public class Player : INotifyPropertyChanged
{ {
public ReadOnlyCollection<Tile> Tiles => playerTiles.AsReadOnly(); private ObservableCollection<Tile> playerTiles = new ObservableCollection<Tile>();
private readonly List<Tile> playerTiles = new(); public ObservableCollection<Tile> Tiles
{
get { return playerTiles; }
set
{
playerTiles = value;
OnPropertyChanged(nameof(Tiles));
}
}
public event PropertyChangedEventHandler? PropertyChanged; public event PropertyChangedEventHandler? PropertyChanged;
void OnPropertyChanged([CallerMemberName] string? propertyName = null) void OnPropertyChanged([CallerMemberName] string? propertyName = null)
@ -45,7 +54,7 @@ namespace QwirkleClassLibrary.Players
public void AddTileToPlayer(Tile tile) public void AddTileToPlayer(Tile tile)
{ {
playerTiles.Add(tile); playerTiles.Add(tile);
OnPropertyChanged(); OnPropertyChanged(nameof(Tiles));
} }
/// <summary> /// <summary>
@ -57,7 +66,7 @@ namespace QwirkleClassLibrary.Players
{ {
if (playerTiles.Remove(tile)) if (playerTiles.Remove(tile))
{ {
OnPropertyChanged(); OnPropertyChanged(nameof(Tiles));
return true; return true;
} }
return false; return false;

@ -51,6 +51,6 @@ public partial class Gameboard : ContentPage
private void Game_PlaceTileNotified(object? sender, PlaceTileNotifiedEventArgs args) private void Game_PlaceTileNotified(object? sender, PlaceTileNotifiedEventArgs args)
{ {
DisplayAlert("Tile place notified", args.Reason, "<3"); DisplayAlert("Tile place notified", args.Tile.ToString() + args.Reason, "<3");
} }
} }

@ -46,7 +46,7 @@ public partial class SetPlayers : ContentPage
{ {
game.PlayerAddNotified += Game_PlayerAddNotified; game.PlayerAddNotified += Game_PlayerAddNotified;
List<string> playerstag = [Entry1.TextIn!, Entry2.TextIn!, Entry3.TextIn!, Entry3.TextIn!]; List<string> playerstag = [Entry1.TextIn!, Entry2.TextIn!, Entry3.TextIn!, Entry4.TextIn!];
if (game.AddPlayerInGame(playerstag)) if (game.AddPlayerInGame(playerstag))
{ {

Loading…
Cancel
Save