@ -8,6 +8,7 @@ using System.Xml.Linq;
using System.Security.Cryptography ;
using System.Security.Cryptography ;
using System.Collections ;
using System.Collections ;
using System.Collections.Immutable ;
using System.Collections.Immutable ;
using System.Runtime.Serialization ;
using QwirkleClassLibrary.Tiles ;
using QwirkleClassLibrary.Tiles ;
using QwirkleClassLibrary.Boards ;
using QwirkleClassLibrary.Boards ;
using QwirkleClassLibrary.Events ;
using QwirkleClassLibrary.Events ;
@ -16,22 +17,21 @@ using QwirkleClassLibrary.Players;
namespace QwirkleClassLibrary.Games
namespace QwirkleClassLibrary.Games
{
{
[DataContract]
public class Game : IPlayer , IRules
public class Game : IPlayer , IRules
{
{
public ReadOnlyDictionary < Player , int > ScoreBoard = > scoreBoard . AsReadOnly ( ) ;
public ReadOnlyDictionary < Player , int > ScoreBoard = > scoreBoard . AsReadOnly ( ) ;
private readonly Dictionary < Player , int > scoreBoard = new ( ) ;
private readonly Dictionary < Player , int > scoreBoard = new ( ) ;
private TileBag ? bag = null ;
private TileBag ? bag = null ;
[DataMember]
public bool GameRunning { get ; private set ; }
public bool GameRunning { get ; private set ; }
private Board _board = new Board ( 15 , 12 ) ;
[DataMember]
public Board Board
private Board board = new Board ( 15 , 12 ) ;
{
get { return _board ; }
private set { _board = value ; }
}
public ObservableCollection < Cell > GetCellsInBoard = > new ObservableCollection < Cell > ( B oard! . GetCells ( ) ) ;
public ObservableCollection < Cell > GetCellsInBoard = > new ObservableCollection < Cell > ( board ! . GetCells ( ) ) ;
public ReadOnlyCollection < Player > PlayerList = > players . AsReadOnly ( ) ;
public ReadOnlyCollection < Player > PlayerList = > players . AsReadOnly ( ) ;
private readonly List < Player > players = new ( ) ;
private readonly List < Player > players = new ( ) ;
@ -154,7 +154,7 @@ namespace QwirkleClassLibrary.Games
/// Returns the Board of the game
/// Returns the Board of the game
/// </summary>
/// </summary>
/// <returns>Board</returns>
/// <returns>Board</returns>
public Board ? GetBoard ( ) { return B oard; }
public Board ? GetBoard ( ) { return b oard; }
/// <summary>
/// <summary>
/// Returns the tile bag of the game
/// Returns the tile bag of the game
@ -168,8 +168,8 @@ namespace QwirkleClassLibrary.Games
/// <returns>Board</returns>
/// <returns>Board</returns>
public Board CreateBoard ( )
public Board CreateBoard ( )
{
{
B oard = new Board ( 15 , 12 ) ;
b oard = new Board ( 15 , 12 ) ;
return B oard;
return b oard;
}
}
/// <summary>
/// <summary>
@ -189,7 +189,7 @@ namespace QwirkleClassLibrary.Games
public void StartGame ( )
public void StartGame ( )
{
{
if ( players . Count < 2 | | players . Count > = 5 ) return ;
if ( players . Count < 2 | | players . Count > = 5 ) return ;
B oard = CreateBoard ( ) ;
b oard = CreateBoard ( ) ;
bag = CreateTileBag ( 3 ) ;
bag = CreateTileBag ( 3 ) ;
GameRunning = true ;
GameRunning = true ;
}
}
@ -318,11 +318,11 @@ namespace QwirkleClassLibrary.Games
/// <returns>bool</returns>
/// <returns>bool</returns>
public bool PlaceTile ( Player player , Tile tile , int x , int y )
public bool PlaceTile ( Player player , Tile tile , int x , int y )
{
{
if ( ! IsMoveCorrect ( tile , x , y , B oard! ) ) return false ;
if ( ! IsMoveCorrect ( tile , x , y , b oard! ) ) return false ;
if ( B oard! . AddTileInCell ( x , y , tile ) )
if ( b oard! . AddTileInCell ( x , y , tile ) )
{
{
OnPlaceTile ( new PlaceTileNotifiedEventArgs ( tile , "was correctly placed !" ) ) ;
OnPlaceTile ( new PlaceTileNotifiedEventArgs ( tile , "was correctly placed !" ) ) ;
AddCellUsed ( B oard. GetCell ( x , y ) ) ;
AddCellUsed ( b oard. GetCell ( x , y ) ) ;
return player . RemoveTileToPlayer ( tile ) ;
return player . RemoveTileToPlayer ( tile ) ;
}
}
@ -730,12 +730,12 @@ namespace QwirkleClassLibrary.Games
{
{
foreach ( var t in players [ t1 ] . Tiles )
foreach ( var t in players [ t1 ] . Tiles )
{
{
for ( int b = 0 ; b < B oard! . ReadCells . Count ; b + + )
for ( int b = 0 ; b < b oard! . ReadCells . Count ; b + + )
{
{
int x = B oard. ReadCells [ b ] . GetX ;
int x = b oard. ReadCells [ b ] . GetX ;
int y = B oard. ReadCells [ b ] . GetY ;
int y = b oard. ReadCells [ b ] . GetY ;
if ( IsMoveCorrect ( t , x , y , B oard) )
if ( IsMoveCorrect ( t , x , y , b oard) )
{
{
return true ;
return true ;
}
}
@ -773,7 +773,7 @@ namespace QwirkleClassLibrary.Games
scoreBoard . Clear ( ) ;
scoreBoard . Clear ( ) ;
cellUsed . Clear ( ) ;
cellUsed . Clear ( ) ;
bag = null ;
bag = null ;
B oard = CreateBoard ( ) ;
b oard = CreateBoard ( ) ;
GameRunning = false ;
GameRunning = false ;
}
}
}
}