You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
sae201_qwirkle/Qwirkle/QwirkleClassLibrary/Players/Player.cs

76 lines
2.1 KiB

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.Boards;
using QwirkleClassLibrary.Tiles;
namespace QwirkleClassLibrary.Players
{
public class Player : INotifyPropertyChanged
{
private ObservableCollection<Tile> playerTiles = new ObservableCollection<Tile>();
public ObservableCollection<Tile> Tiles
{
get { return playerTiles; }
set
{
playerTiles = value;
OnPropertyChanged(nameof(Tiles));
}
}
public event PropertyChangedEventHandler? PropertyChanged;
void OnPropertyChanged([CallerMemberName] string? propertyName = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
/// <summary>
/// Creates a player with a name
/// </summary>
/// <param name="name"></param>
/// <exception cref="ArgumentNullException"></exception>
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;
/// <summary>
/// Adds a tile to the player's hand
/// </summary>
/// <param name="tile"></param>
public void AddTileToPlayer(Tile tile)
{
playerTiles.Add(tile);
OnPropertyChanged(nameof(Tiles));
}
/// <summary>
/// Removes a tile from the player's hand
/// </summary>
/// <param name="tile"></param>
/// <returns>bool</returns>
public bool RemoveTileToPlayer(Tile tile)
{
if (playerTiles.Remove(tile))
{
OnPropertyChanged(nameof(Tiles));
return true;
}
return false;
}
}
}