using System; using System.Collections.Generic; using System.Collections.ObjectModel; using System.ComponentModel; using System.Linq; using System.Runtime.CompilerServices; using System.Text; using System.Threading.Tasks; using QwirkleClassLibrary.Tiles; namespace QwirkleClassLibrary.Players { public class Player : INotifyPropertyChanged { public ReadOnlyCollection Tiles => playerTiles.AsReadOnly(); private readonly List playerTiles = new(); public event PropertyChangedEventHandler? PropertyChanged; void OnPropertyChanged([CallerMemberName] string? propertyName = null) => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); /// /// Creates a player with a name /// /// /// public Player(string name) { if (name == null || string.IsNullOrEmpty(name)) { throw new ArgumentNullException(name); } NameTag = name; } public string NameTag { get; } public bool IsPlaying { get; set; } = false; /// /// Adds a tile to the player's hand /// /// public void AddTileToPlayer(Tile tile) { playerTiles.Add(tile); OnPropertyChanged(); } /// /// Removes a tile from the player's hand /// /// /// bool public bool RemoveTileToPlayer(Tile tile) { if (playerTiles.Remove(tile)) { OnPropertyChanged(); return true; } return false; } } }