|
|
@ -22,27 +22,43 @@ namespace QwirkleClassLibrary
|
|
|
|
public ReadOnlyCollection<Player> PlayerList => players.AsReadOnly();
|
|
|
|
public ReadOnlyCollection<Player> PlayerList => players.AsReadOnly();
|
|
|
|
private readonly List<Player> players = new();
|
|
|
|
private readonly List<Player> players = new();
|
|
|
|
|
|
|
|
|
|
|
|
public ReadOnlyCollection<Score> ScoreList => scores.AsReadOnly();
|
|
|
|
|
|
|
|
private readonly List<Score> scores = new();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ReadOnlyCollection<Cell> CellsUsed => cellUsed.AsReadOnly();
|
|
|
|
public ReadOnlyCollection<Cell> CellsUsed => cellUsed.AsReadOnly();
|
|
|
|
private readonly List<Cell> cellUsed = new();
|
|
|
|
private readonly List<Cell> cellUsed = new();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public event EventHandler<AddPlayerNotifiedEventArgs>? PlayerAddNotified;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void OnPlayerNotified(AddPlayerNotifiedEventArgs args)
|
|
|
|
|
|
|
|
=> PlayerAddNotified?.Invoke(this, args);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public event EventHandler<NextPlayerNotifiedEventArgs>? NextPlayerNotified;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected virtual void OnNextPlayer(NextPlayerNotifiedEventArgs args)
|
|
|
|
|
|
|
|
=> NextPlayerNotified?.Invoke(this, args);
|
|
|
|
|
|
|
|
|
|
|
|
public Game()
|
|
|
|
public Game()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
bag = CreateTileBag(3);
|
|
|
|
bag = CreateTileBag(3);
|
|
|
|
board = CreateBoard();
|
|
|
|
board = CreateBoard();
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public bool AddPlayerInGame(string? playerTag)
|
|
|
|
public bool AddPlayerInGame(string? playerTag)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (string.IsNullOrWhiteSpace(playerTag) == true || this.GameRunning == true)
|
|
|
|
if (string.IsNullOrWhiteSpace(playerTag) == true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR : The name is null or white space."));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(this.GameRunning == true)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR : The game is running."));
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (players.Count >= 4)
|
|
|
|
if (players.Count >= 4)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR : The game is full."));
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -50,19 +66,22 @@ namespace QwirkleClassLibrary
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (p.NameTag == playerTag)
|
|
|
|
if (p.NameTag == playerTag)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR : Name alreay taken"));
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
players.Add(CreatePlayer(playerTag));
|
|
|
|
players.Add(CreatePlayer(playerTag));
|
|
|
|
scores.Add(new Score(players[players.Count - 1]));
|
|
|
|
//scores.Add(new Score(players[players.Count-1]));
|
|
|
|
|
|
|
|
OnPlayerNotified(new AddPlayerNotifiedEventArgs("Player was correctly added"));
|
|
|
|
return true;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public Player CreatePlayer(string playerTag)
|
|
|
|
public Player CreatePlayer(string playerTag)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var player = new Player(playerTag);
|
|
|
|
var player = new Player(playerTag);
|
|
|
|
|
|
|
|
|
|
|
|
return player;
|
|
|
|
return player;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -142,6 +161,7 @@ namespace QwirkleClassLibrary
|
|
|
|
if (GameRunning == true)
|
|
|
|
if (GameRunning == true)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
players[0].IsPlaying = true;
|
|
|
|
players[0].IsPlaying = true;
|
|
|
|
|
|
|
|
//OnNextPlayer(new NextPlayerNotifiedEventArgs(players[0]));
|
|
|
|
return players[0].NameTag;
|
|
|
|
return players[0].NameTag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
else
|
|
|
@ -162,6 +182,7 @@ namespace QwirkleClassLibrary
|
|
|
|
|
|
|
|
|
|
|
|
players[i].IsPlaying = false;
|
|
|
|
players[i].IsPlaying = false;
|
|
|
|
players[(i + 1) % players.Count].IsPlaying = true;
|
|
|
|
players[(i + 1) % players.Count].IsPlaying = true;
|
|
|
|
|
|
|
|
OnNextPlayer(new NextPlayerNotifiedEventArgs(players[i]));
|
|
|
|
|
|
|
|
|
|
|
|
return players[GetPlayingPlayerPosition()].NameTag;
|
|
|
|
return players[GetPlayingPlayerPosition()].NameTag;
|
|
|
|
}
|
|
|
|
}
|
|
|
|