You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
149 lines
3.6 KiB
149 lines
3.6 KiB
using System;
|
|
using System.Collections.Generic;
|
|
using System.Collections.ObjectModel;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Xml.Linq;
|
|
|
|
namespace QwirkleClassLibrary
|
|
{
|
|
public class Game : IPlayer
|
|
{
|
|
private TileBag bag;
|
|
public bool GameRunning { get; private set; }
|
|
private Board board;
|
|
|
|
public ReadOnlyCollection<Player> PlayerList { get; }
|
|
private readonly List<Player> players;
|
|
|
|
public Game()
|
|
{
|
|
board = new Board();
|
|
bag = new TileBag(3);
|
|
Console.Write(bag.TilesBag.Count);
|
|
gameRunning = false;
|
|
PlayerList = players.AsReadOnly();
|
|
}
|
|
|
|
public bool AddPlayerInGame(string? playerTag)
|
|
{
|
|
if (string.IsNullOrWhiteSpace(playerTag) == true || this.GameRunning == true)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (players.Count >= 4)
|
|
{
|
|
return false;
|
|
}
|
|
|
|
foreach (var p in players)
|
|
{
|
|
if (p.NameTag == playerTag)
|
|
{
|
|
return false;
|
|
}
|
|
}
|
|
|
|
players.Add(CreatePlayer(playerTag));
|
|
|
|
return true;
|
|
}
|
|
|
|
public Player CreatePlayer(string playerTag)
|
|
{
|
|
var player = new Player(playerTag);
|
|
return player;
|
|
}
|
|
|
|
public void StartGame()
|
|
{
|
|
this.GameRunning = true;
|
|
}
|
|
|
|
public int GetPlayingPlayerPosition()
|
|
{
|
|
for (int i = 0; i < players.Count; i++)
|
|
{
|
|
if (players[i].IsPlaying == true)
|
|
{
|
|
return i;
|
|
}
|
|
}
|
|
return -1;
|
|
}
|
|
|
|
public Tile TileOfPlayerWithPos(int postile)
|
|
{
|
|
return players[GetPlayingPlayerPosition()].Tiles[postile];
|
|
}
|
|
|
|
public void GiveTilesToPlayers()
|
|
{
|
|
foreach (var p in players)
|
|
{
|
|
for (int j = 0; j < 6; j++)
|
|
{
|
|
Random random = new Random();
|
|
int val = random.Next(0, bag.TilesBag.Count);
|
|
|
|
p.AddTileToPlayer(bag.TilesBag[val]);
|
|
bag.RemoveTileInBag(bag.TilesBag[val]);
|
|
}
|
|
}
|
|
}
|
|
|
|
public bool PlaceTileGame(Tile tile, int x, int y)
|
|
{
|
|
bool checkremove = false;
|
|
bool checkaddcell = board.AddTileInCell(x, y, tile);
|
|
if (checkaddcell == true)
|
|
{
|
|
checkremove = players[GetPlayingPlayerPosition()].RemoveTileToPlayer(tile);
|
|
}
|
|
|
|
if (checkaddcell == checkremove)
|
|
{
|
|
return checkaddcell;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public string SetFirstPlayer()
|
|
{
|
|
players[0].IsPlaying = true;
|
|
return players[0].NameTag;
|
|
}
|
|
|
|
public string SetNextPlayer()
|
|
{
|
|
int i = GetPlayingPlayerPosition();
|
|
|
|
if (i == -1)
|
|
{
|
|
return SetFirstPlayer();
|
|
}
|
|
|
|
players[i].IsPlaying = false;
|
|
players[(i + 1) % players.Count].IsPlaying = true;
|
|
|
|
return players[GetPlayingPlayerPosition()].NameTag;
|
|
}
|
|
|
|
public void PlaceTile(Player player, Tile tile, int x, int y)
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
|
|
public bool ContinueToPlay()
|
|
{
|
|
throw new NotImplementedException();
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|