using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading.Tasks;
using QwirkleClassLibrary.Boards;
using QwirkleClassLibrary.Tiles;
namespace QwirkleClassLibrary.Players
{
///
/// This class is mainly used to manage the sets of tiles of players during the game.
///
[DataContract]
public class Player : INotifyPropertyChanged
{
[DataMember]
private ObservableCollection tiles = new ObservableCollection();
public ObservableCollection Tiles
{
get { return tiles; }
set
{
tiles = value;
OnPropertyChanged(nameof(Tiles));
}
}
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;
Tiles = [];
}
[DataMember]
public string NameTag { get; set; }
[DataMember]
public bool IsPlaying { get; set; } = false;
///
/// Adds a tile to the player's hand
///
///
public void AddTileToPlayer(Tile tile)
{
Tiles.Add(tile);
OnPropertyChanged(nameof(Tiles));
}
///
/// Removes a tile from the player's hand
///
///
/// bool
public bool RemoveTileToPlayer(Tile tile)
{
if (Tiles.Remove(tile))
{
OnPropertyChanged(nameof(Tiles));
return true;
}
return false;
}
}
}