@ -1,5 +1,6 @@
using System ;
using System ;
using System.Collections.Generic ;
using System.Collections.Generic ;
using System.Collections.ObjectModel ;
using System.Linq ;
using System.Linq ;
using System.Text ;
using System.Text ;
using System.Threading.Tasks ;
using System.Threading.Tasks ;
@ -11,9 +12,10 @@ namespace QwirkleClassLibrary
public class Game : IRules
public class Game : IRules
{
{
private TileBag bag ;
private TileBag bag ;
private List < Player > players ;
private bool gameRunning ;
private bool gameRunning ;
private Board board ;
private Board board ;
public ReadOnlyCollection < Player > PlayerList { get ; private set ; }
private readonly List < Player > players = new List < Player > ( ) ;
Board CreateBoard ( )
Board CreateBoard ( )
{
{
@ -43,8 +45,11 @@ namespace QwirkleClassLibrary
{
{
this . players = new List < Player > ( ) ;
this . players = new List < Player > ( ) ;
Board board = CreateBoard ( ) ;
Board board = CreateBoard ( ) ;
board = new Board ( ) ;
bag = new TileBag ( 3 ) ;
bag = new TileBag ( 3 ) ;
Console . Write ( bag . TilesBag . Count ) ;
gameRunning = false ;
gameRunning = false ;
PlayerList = players . AsReadOnly ( ) ;
}
}
public bool AddPlayerInGame ( string? PlayerTag )
public bool AddPlayerInGame ( string? PlayerTag )
@ -104,24 +109,6 @@ namespace QwirkleClassLibrary
get { return players . Count ; }
get { return players . Count ; }
}
}
public List < Tile > ListTilesBag
{
get { return bag . TilesInBag ( ) ; }
}
public string ShowTileOfPlayer ( int posplayer )
{
List < Tile > tiles = players [ posplayer ] . Tiles ;
string r = ( "Tile of " + posplayer + " : " ) ;
foreach ( Tile tile in tiles )
{
r = ( r + " " + tile . NameColorTile ( ) ) ;
}
return r ;
}
public Tile TileOfPlayerWithPos ( int postile )
public Tile TileOfPlayerWithPos ( int postile )
{
{
@ -145,7 +132,9 @@ namespace QwirkleClassLibrary
{
{
for ( int j = 0 ; j < 6 ; j + + )
for ( int j = 0 ; j < 6 ; j + + )
{
{
Tile tile = ListTilesBag [ j ] ;
Random random = new Random ( ) ;
int val = random . Next ( 0 , bag . TilesBag . Count ) ;
Tile tile = bag . TilesBag [ val ] ;
players [ i ] . AddTilePlayer ( tile ) ;
players [ i ] . AddTilePlayer ( tile ) ;
bag . RemoveTileInBag ( tile ) ;
bag . RemoveTileInBag ( tile ) ;
}
}
@ -158,7 +147,7 @@ namespace QwirkleClassLibrary
int posPlayerNextPlay = GetPlayingPlayerPosition ( ) + 1 ;
int posPlayerNextPlay = GetPlayingPlayerPosition ( ) + 1 ;
if ( posPlayerNextPlay > = GetNbPlayers )
if ( posPlayerNextPlay > GetNbPlayers )
{
{
posPlayerNextPlay = 0 ;
posPlayerNextPlay = 0 ;
}
}
@ -175,9 +164,18 @@ namespace QwirkleClassLibrary
public bool PlaceTileGame ( Tile tile , int x , int y )
public bool PlaceTileGame ( Tile tile , int x , int y )
{
{
bool r = board . AddTileInCell ( x , y , tile ) ;
bool checkremove = false ;
players [ GetPlayingPlayerPosition ( ) ] . RemoveTilePlayer ( tile ) ;
bool checkaddcell = board . AddTileInCell ( x , y , tile ) ;
return r ;
if ( checkaddcell = = true )
{
checkremove = players [ GetPlayingPlayerPosition ( ) ] . RemoveTilePlayer ( tile ) ;
}
if ( checkaddcell = = checkremove )
{
return checkaddcell ;
}
return false ;
}
}
}
}