diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs
index 02c974a..2c32d3b 100644
--- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs
+++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs
@@ -317,6 +317,11 @@ namespace QwirkleClassLibrary.Games
/// bool
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 (board!.AddTileInCell(x, y, tile))
{
@@ -328,6 +333,18 @@ namespace QwirkleClassLibrary.Games
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;
+
+ }
+
///
/// Allows a player to draw tiles from the bag as soon as he has less than 6 tiles
@@ -494,9 +511,9 @@ namespace QwirkleClassLibrary.Games
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 !"));
}
var surroundingCells = new List
diff --git a/Qwirkle/QwirkleClassLibrary/Players/Player.cs b/Qwirkle/QwirkleClassLibrary/Players/Player.cs
index e9c4997..7533147 100644
--- a/Qwirkle/QwirkleClassLibrary/Players/Player.cs
+++ b/Qwirkle/QwirkleClassLibrary/Players/Player.cs
@@ -6,14 +6,23 @@ using System.Linq;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
+using QwirkleClassLibrary.Boards;
using QwirkleClassLibrary.Tiles;
namespace QwirkleClassLibrary.Players
{
public class Player : INotifyPropertyChanged
{
- public ReadOnlyCollection Tiles => playerTiles.AsReadOnly();
- private readonly List playerTiles = new();
+ private ObservableCollection playerTiles = new ObservableCollection();
+ public ObservableCollection Tiles
+ {
+ get { return playerTiles; }
+ set
+ {
+ playerTiles = value;
+ OnPropertyChanged(nameof(Tiles));
+ }
+ }
public event PropertyChangedEventHandler? PropertyChanged;
void OnPropertyChanged([CallerMemberName] string? propertyName = null)
@@ -45,7 +54,7 @@ namespace QwirkleClassLibrary.Players
public void AddTileToPlayer(Tile tile)
{
playerTiles.Add(tile);
- OnPropertyChanged();
+ OnPropertyChanged(nameof(Tiles));
}
///
@@ -57,7 +66,7 @@ namespace QwirkleClassLibrary.Players
{
if (playerTiles.Remove(tile))
{
- OnPropertyChanged();
+ OnPropertyChanged(nameof(Tiles));
return true;
}
return false;
diff --git a/Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs b/Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs
index 7e2f923..894b907 100644
--- a/Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs
+++ b/Qwirkle/QwirkleViews/Pages/GameBoard.xaml.cs
@@ -51,6 +51,6 @@ public partial class Gameboard : ContentPage
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");
}
}
\ No newline at end of file
diff --git a/Qwirkle/QwirkleViews/Pages/SetPlayers.xaml.cs b/Qwirkle/QwirkleViews/Pages/SetPlayers.xaml.cs
index 5a054e8..2bf0b20 100644
--- a/Qwirkle/QwirkleViews/Pages/SetPlayers.xaml.cs
+++ b/Qwirkle/QwirkleViews/Pages/SetPlayers.xaml.cs
@@ -46,7 +46,7 @@ public partial class SetPlayers : ContentPage
{
game.PlayerAddNotified += Game_PlayerAddNotified;
- List playerstag = [Entry1.TextIn!, Entry2.TextIn!, Entry3.TextIn!, Entry3.TextIn!];
+ List playerstag = [Entry1.TextIn!, Entry2.TextIn!, Entry3.TextIn!, Entry4.TextIn!];
if (game.AddPlayerInGame(playerstag))
{
|