|
|
@ -5,12 +5,15 @@ using QwirkleClassLibrary.Tiles;
|
|
|
|
using QwirkleClassLibrary.Boards;
|
|
|
|
using QwirkleClassLibrary.Boards;
|
|
|
|
using QwirkleClassLibrary.Events;
|
|
|
|
using QwirkleClassLibrary.Events;
|
|
|
|
using QwirkleClassLibrary.Players;
|
|
|
|
using QwirkleClassLibrary.Players;
|
|
|
|
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
|
|
|
using static System.Formats.Asn1.AsnWriter;
|
|
|
|
|
|
|
|
|
|
|
|
namespace QwirkleClassLibrary.Games
|
|
|
|
namespace QwirkleClassLibrary.Games
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
[DataContract]
|
|
|
|
[DataContract]
|
|
|
|
public class Game : IPlayer, IRules
|
|
|
|
public class Game : IPlayer, IRules, INotifyPropertyChanged
|
|
|
|
{
|
|
|
|
{
|
|
|
|
[DataMember]
|
|
|
|
[DataMember]
|
|
|
|
private TileBag? bag = null;
|
|
|
|
private TileBag? bag = null;
|
|
|
@ -30,10 +33,15 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
private readonly List<Player> players = [];
|
|
|
|
private readonly List<Player> players = [];
|
|
|
|
|
|
|
|
|
|
|
|
[DataMember]
|
|
|
|
[DataMember]
|
|
|
|
private readonly Dictionary<string, int> scoreBoard = [];
|
|
|
|
private readonly Dictionary<string, int> scoreBoard = new Dictionary<string, int>();
|
|
|
|
|
|
|
|
|
|
|
|
public ReadOnlyDictionary<string, int> ScoreBoard => scoreBoard.AsReadOnly();
|
|
|
|
public ReadOnlyDictionary<string, int> ScoreBoard => scoreBoard.AsReadOnly();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private ObservableCollection<KeyValuePair<string, int>> observableScoreBoard = new ObservableCollection<KeyValuePair<string, int>>();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ReadOnlyObservableCollection<KeyValuePair<string, int>> ObservableScoreBoard =>
|
|
|
|
|
|
|
|
new ReadOnlyObservableCollection<KeyValuePair<string, int>>(observableScoreBoard);
|
|
|
|
|
|
|
|
|
|
|
|
[DataMember]
|
|
|
|
[DataMember]
|
|
|
|
private readonly List<Cell> cellUsed = [];
|
|
|
|
private readonly List<Cell> cellUsed = [];
|
|
|
|
|
|
|
|
|
|
|
@ -61,6 +69,14 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
|
|
|
|
|
|
|
|
public event EventHandler<SwapTilesNotifiedEventArgs>? SwapTilesNotified;
|
|
|
|
public event EventHandler<SwapTilesNotifiedEventArgs>? SwapTilesNotified;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public event PropertyChangedEventHandler? PropertyChanged;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void OnSwapTiles(SwapTilesNotifiedEventArgs args)
|
|
|
|
protected virtual void OnSwapTiles(SwapTilesNotifiedEventArgs args)
|
|
|
|
=> SwapTilesNotified?.Invoke(this, args);
|
|
|
|
=> SwapTilesNotified?.Invoke(this, args);
|
|
|
|
|
|
|
|
|
|
|
@ -104,7 +120,7 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Player pl = CreatePlayer(tag);
|
|
|
|
Player pl = CreatePlayer(tag);
|
|
|
|
players.Add(pl);
|
|
|
|
players.Add(pl);
|
|
|
|
scoreBoard.Add(pl.NameTag, 0);
|
|
|
|
SetScoreBoard(pl.NameTag, 0);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OnPlayerNotified(new AddPlayerNotifiedEventArgs("Players were correctly added."));
|
|
|
|
OnPlayerNotified(new AddPlayerNotifiedEventArgs("Players were correctly added."));
|
|
|
@ -621,7 +637,9 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
|
|
|
|
|
|
|
|
if (!scoreBoard.TryAdd(player.NameTag, score))
|
|
|
|
if (!scoreBoard.TryAdd(player.NameTag, score))
|
|
|
|
{
|
|
|
|
{
|
|
|
|
scoreBoard[player.NameTag] += score;
|
|
|
|
|
|
|
|
|
|
|
|
scoreBoard.TryGetValue(player.NameTag, out int scoreold);
|
|
|
|
|
|
|
|
SetScoreBoard(player.NameTag, score + scoreold);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return score;
|
|
|
|
return score;
|
|
|
@ -773,7 +791,8 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OnEndOfGame(new EndOfGameNotifiedEventArgs(player));
|
|
|
|
OnEndOfGame(new EndOfGameNotifiedEventArgs(player));
|
|
|
|
GameRunning = false;
|
|
|
|
GameRunning = false;
|
|
|
|
scoreBoard[player.NameTag] += 6;
|
|
|
|
scoreBoard.TryGetValue(player.NameTag, out int scoreold);
|
|
|
|
|
|
|
|
SetScoreBoard(player.NameTag, 6 + scoreold);
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -789,5 +808,25 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
board = CreateBoard();
|
|
|
|
board = CreateBoard();
|
|
|
|
GameRunning = false;
|
|
|
|
GameRunning = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void SetScoreBoard(string name, int score)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (scoreBoard.ContainsKey(name))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
scoreBoard[name] = score;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
else
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
scoreBoard.Add(name, score);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
observableScoreBoard.Clear();
|
|
|
|
|
|
|
|
foreach (var item in scoreBoard)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
observableScoreBoard.Add(item);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
OnPropertyChanged(nameof(ObservableScoreBoard));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|