|
|
@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.Text;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
using System.Xml.Linq;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace QwirkleClassLibrary
|
|
|
|
namespace QwirkleClassLibrary
|
|
|
@ -11,13 +12,57 @@ namespace QwirkleClassLibrary
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private TileBag bag;
|
|
|
|
private TileBag bag;
|
|
|
|
private List<Player> players;
|
|
|
|
private List<Player> players;
|
|
|
|
|
|
|
|
private bool gameRunning;
|
|
|
|
|
|
|
|
private Board board;
|
|
|
|
|
|
|
|
|
|
|
|
public Game(List<Player> players)
|
|
|
|
public Game()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
this.players = players;
|
|
|
|
this.players = new List<Player>();
|
|
|
|
|
|
|
|
board = new Board();
|
|
|
|
bag = new TileBag(3);
|
|
|
|
bag = new TileBag(3);
|
|
|
|
|
|
|
|
gameRunning = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool AddPlayerInGame(string? PlayerTag)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bool nameInvalid = string.IsNullOrWhiteSpace(PlayerTag);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (nameInvalid == true || this.gameRunning == true || PlayerTag == null)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (players.Count >= 4)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < players.Count; i++)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (players[i].GetNameTag == PlayerTag)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Player p = new Player(PlayerTag);
|
|
|
|
|
|
|
|
players.Add(p);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool StartGame()
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (players.Count < 2)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
this.gameRunning = true;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int GetPlayingPlayerPosition()
|
|
|
|
public int GetPlayingPlayerPosition()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
for (int i = 0; i < players.Count; i++)
|
|
|
|
for (int i = 0; i < players.Count; i++)
|
|
|
@ -46,7 +91,7 @@ namespace QwirkleClassLibrary
|
|
|
|
|
|
|
|
|
|
|
|
string r = ("Tile of " + posplayer + " : ");
|
|
|
|
string r = ("Tile of " + posplayer + " : ");
|
|
|
|
|
|
|
|
|
|
|
|
foreach(Tile tile in tiles)
|
|
|
|
foreach (Tile tile in tiles)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
r = (r + " " + tile.NameColorTile());
|
|
|
|
r = (r + " " + tile.NameColorTile());
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -54,15 +99,20 @@ namespace QwirkleClassLibrary
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public Tile TileOfPlayerWithPos(int postile)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return players[GetPlayingPlayerPosition()].Tiles[postile];
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void SetNextPlayer(int old, int neew)
|
|
|
|
public void SetNextPlayer(int old, int neew)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
if (old >= 0)
|
|
|
|
|
|
|
|
|
|
|
|
if (old >= 0 || old != -1)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
players[old].IsPlaying = false;
|
|
|
|
players[old].IsPlaying = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
players[neew].IsPlaying = true;
|
|
|
|
players[neew].IsPlaying = true;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void TilsBagPlayer()
|
|
|
|
public void TilsBagPlayer()
|
|
|
@ -94,6 +144,18 @@ namespace QwirkleClassLibrary
|
|
|
|
return (players[posPlayerNextPlay].GetNameTag);
|
|
|
|
return (players[posPlayerNextPlay].GetNameTag);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool GameRunning
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
get { return gameRunning; }
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public bool PlaceTileGame(Tile tile, int x, int y)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
bool r = board.AddTileInCell(x, y, tile);
|
|
|
|
|
|
|
|
players[GetPlayingPlayerPosition()].RemoveTilePlayer(tile);
|
|
|
|
|
|
|
|
return r;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|