|
|
@ -1,13 +1,5 @@
|
|
|
|
using System;
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
using System.Collections.ObjectModel;
|
|
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
using System.Security.Cryptography;
|
|
|
|
using System.Collections;
|
|
|
|
|
|
|
|
using System.Collections.Immutable;
|
|
|
|
|
|
|
|
using System.Runtime.Serialization;
|
|
|
|
using System.Runtime.Serialization;
|
|
|
|
using QwirkleClassLibrary.Tiles;
|
|
|
|
using QwirkleClassLibrary.Tiles;
|
|
|
|
using QwirkleClassLibrary.Boards;
|
|
|
|
using QwirkleClassLibrary.Boards;
|
|
|
@ -21,13 +13,13 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
public class Game : IPlayer, IRules
|
|
|
|
public class Game : IPlayer, IRules
|
|
|
|
{
|
|
|
|
{
|
|
|
|
[DataMember]
|
|
|
|
[DataMember]
|
|
|
|
public TileBag? bag = null;
|
|
|
|
private TileBag? bag = null;
|
|
|
|
|
|
|
|
|
|
|
|
[DataMember]
|
|
|
|
[DataMember]
|
|
|
|
public bool GameRunning { get; set; }
|
|
|
|
public bool GameRunning { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
[DataMember]
|
|
|
|
[DataMember]
|
|
|
|
private Board board = new Board(15, 12);
|
|
|
|
private Board board = new(15, 12);
|
|
|
|
|
|
|
|
|
|
|
|
public bool PlayerSwapping { get; set; }
|
|
|
|
public bool PlayerSwapping { get; set; }
|
|
|
|
public Board Board => board;
|
|
|
|
public Board Board => board;
|
|
|
@ -35,15 +27,15 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
public ReadOnlyCollection<Player> PlayerList => players.AsReadOnly();
|
|
|
|
public ReadOnlyCollection<Player> PlayerList => players.AsReadOnly();
|
|
|
|
|
|
|
|
|
|
|
|
[DataMember]
|
|
|
|
[DataMember]
|
|
|
|
private readonly List<Player> players = new();
|
|
|
|
private readonly List<Player> players = [];
|
|
|
|
|
|
|
|
|
|
|
|
[DataMember]
|
|
|
|
[DataMember]
|
|
|
|
private readonly Dictionary<Player, int> scoreBoard = new();
|
|
|
|
private readonly Dictionary<Player, int> scoreBoard = [];
|
|
|
|
|
|
|
|
|
|
|
|
public ReadOnlyDictionary<Player, int> ScoreBoard => scoreBoard.AsReadOnly();
|
|
|
|
public ReadOnlyDictionary<Player, int> ScoreBoard => scoreBoard.AsReadOnly();
|
|
|
|
|
|
|
|
|
|
|
|
[DataMember]
|
|
|
|
[DataMember]
|
|
|
|
private readonly List<Cell> cellUsed = new();
|
|
|
|
private readonly List<Cell> cellUsed = [];
|
|
|
|
|
|
|
|
|
|
|
|
public ReadOnlyCollection<Cell> CellsUsed => cellUsed.AsReadOnly();
|
|
|
|
public ReadOnlyCollection<Cell> CellsUsed => cellUsed.AsReadOnly();
|
|
|
|
|
|
|
|
|
|
|
@ -270,7 +262,7 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (bag != null && p.Tiles.Count < 6)
|
|
|
|
if (bag != null && p.Tiles.Count < 6)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
int val = RandomNumberGenerator.GetInt32(0, bag.TilesBag.Count);
|
|
|
|
int val = RandomNumberGenerator.GetInt32(0, bag.TilesBag!.Count);
|
|
|
|
|
|
|
|
|
|
|
|
p.AddTileToPlayer(bag.TilesBag[val]);
|
|
|
|
p.AddTileToPlayer(bag.TilesBag[val]);
|
|
|
|
bag.RemoveTileInBag(bag.TilesBag[val]);
|
|
|
|
bag.RemoveTileInBag(bag.TilesBag[val]);
|
|
|
@ -362,7 +354,7 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
{
|
|
|
|
{
|
|
|
|
while (player.Tiles.Count < 6)
|
|
|
|
while (player.Tiles.Count < 6)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (bag!.TilesBag.Count == 0)
|
|
|
|
if (bag!.TilesBag!.Count == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -384,13 +376,19 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
/// <returns>bool</returns>
|
|
|
|
/// <returns>bool</returns>
|
|
|
|
public bool SwapTiles(Player player, List<Tile> tilesToSwap)
|
|
|
|
public bool SwapTiles(Player player, List<Tile> tilesToSwap)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
|
|
|
|
if (cellUsed.Count != 0)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
OnSwapTiles(new SwapTilesNotifiedEventArgs("You can't swap tiles after placing some !"));
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (tilesToSwap.Count == 0)
|
|
|
|
if (tilesToSwap.Count == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OnSwapTiles(new SwapTilesNotifiedEventArgs("You must select at least one tile to swap !"));
|
|
|
|
OnSwapTiles(new SwapTilesNotifiedEventArgs("You must select at least one tile to swap !"));
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (bag!.TilesBag.Count < tilesToSwap.Count)
|
|
|
|
if (bag!.TilesBag!.Count < tilesToSwap.Count)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OnSwapTiles(new SwapTilesNotifiedEventArgs("Not enough tiles in the bag to swap !"));
|
|
|
|
OnSwapTiles(new SwapTilesNotifiedEventArgs("Not enough tiles in the bag to swap !"));
|
|
|
|
return false;
|
|
|
|
return false;
|
|
|
@ -719,7 +717,7 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
{
|
|
|
|
{
|
|
|
|
List<int> playerTilesBagPos = [];
|
|
|
|
List<int> playerTilesBagPos = [];
|
|
|
|
|
|
|
|
|
|
|
|
if (bag!.TilesBag.Count == 0)
|
|
|
|
if (bag!.TilesBag!.Count == 0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (int i = 0; i < players.Count; i++)
|
|
|
|
for (int i = 0; i < players.Count; i++)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -771,7 +769,7 @@ namespace QwirkleClassLibrary.Games
|
|
|
|
{
|
|
|
|
{
|
|
|
|
List<int> playerTilesBagPos = CheckTilesBag();
|
|
|
|
List<int> playerTilesBagPos = CheckTilesBag();
|
|
|
|
|
|
|
|
|
|
|
|
if (playerTilesBagPos.Count != 0 && !CheckPlacementPossibilities(playerTilesBagPos) || bag!.TilesBag.Count == 0 && players[GetPlayingPlayerPosition()].Tiles.Count==0)
|
|
|
|
if (playerTilesBagPos.Count != 0 && !CheckPlacementPossibilities(playerTilesBagPos) || bag!.TilesBag!.Count == 0 && players[GetPlayingPlayerPosition()].Tiles.Count==0)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
OnEndOfGame(new EndOfGameNotifiedEventArgs(player));
|
|
|
|
OnEndOfGame(new EndOfGameNotifiedEventArgs(player));
|
|
|
|
GameRunning = false;
|
|
|
|
GameRunning = false;
|
|
|
|