Added Iplayer interface + cleaned up Player.cs + game interface implementation

test_old_branch
Jules LASCRET 1 year ago
parent d4d6b59995
commit 3d35e00df9

@ -9,21 +9,21 @@ using System.Xml.Linq;
namespace QwirkleClassLibrary namespace QwirkleClassLibrary
{ {
public class Game public class Game : IPlayer
{ {
private TileBag bag; private TileBag bag;
private bool gameRunning; private bool gameRunning;
private Board board; private Board board;
public ReadOnlyCollection<Player> PlayerList { get; private set; } public ReadOnlyCollection<Player> PlayerList { get; private set; }
private readonly List<Player> players = new List<Player>(); private readonly List<Player> players;
public Game() public Game()
{ {
board = new Board(); board = new Board();
bag = new TileBag(3); bag = new TileBag(3);
Console.Write(bag.TilesBag.Count);
gameRunning = false; players = new List<Player>();
PlayerList = players.AsReadOnly(); PlayerList = players.AsReadOnly();
} }
@ -43,7 +43,7 @@ namespace QwirkleClassLibrary
for (int i = 0; i < players.Count; i++) for (int i = 0; i < players.Count; i++)
{ {
if (players[i].GetNameTag == PlayerTag) if (players[i].NameTag == PlayerTag)
{ {
return false; return false;
} }
@ -55,6 +55,12 @@ namespace QwirkleClassLibrary
return true; return true;
} }
public Player CreatePlayer(string playerTag)
{
var player = new Player(playerTag);
return player;
}
public bool StartGame() public bool StartGame()
{ {
if (players.Count < 2) if (players.Count < 2)
@ -66,7 +72,6 @@ namespace QwirkleClassLibrary
return 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++)
@ -92,7 +97,6 @@ namespace QwirkleClassLibrary
public void SetNextPlayer(int old, int neew) public void SetNextPlayer(int old, int neew)
{ {
if (old >= 0 || old != -1) if (old >= 0 || old != -1)
{ {
players[old].IsPlaying = false; players[old].IsPlaying = false;
@ -129,7 +133,7 @@ namespace QwirkleClassLibrary
SetNextPlayer(posPlayerPlay, posPlayerNextPlay); SetNextPlayer(posPlayerPlay, posPlayerNextPlay);
return (players[posPlayerNextPlay].GetNameTag); return (players[posPlayerNextPlay].NameTag);
} }
public bool GameRunning public bool GameRunning
@ -153,6 +157,26 @@ namespace QwirkleClassLibrary
return false; return false;
} }
public void SetNextPlayer(List<Player> playersList)
{
for(int i = 0; i < PlayerList.Count; i++)
{
if (PlayerList[i].IsPlaying != true) continue;
PlayerList[i].IsPlaying = false;
PlayerList[(i + 1) % PlayerList.Count].IsPlaying = true;
}
}
public void PlaceTile(Player player, Tile tile, int x, int y)
{
throw new NotImplementedException();
}
public bool ContinueToPlay()
{
throw new NotImplementedException();
}
} }

@ -0,0 +1,12 @@
namespace QwirkleClassLibrary;
public interface IPlayer
{
public Player CreatePlayer(string playerTag);
public void SetNextPlayer(List<Player> players);
public void PlaceTile(Player player, Tile tile, int x, int y);
public bool ContinueToPlay();
}

@ -9,26 +9,23 @@ namespace QwirkleClassLibrary
{ {
public class Player public class Player
{ {
private string nameTag;
public ReadOnlyCollection<Tile> Tiles { get; private set; } public ReadOnlyCollection<Tile> Tiles { get; private set; }
private readonly List<Tile> playerTiles = new List<Tile>(); private readonly List<Tile> playerTiles;
public Player(string name) public Player(string name)
{ {
if(name==null || string.IsNullOrEmpty(name)) if(name == null || string.IsNullOrEmpty(name))
{ {
throw new ArgumentNullException("name"); throw new ArgumentNullException(name);
} }
nameTag = name;
NameTag = name;
playerTiles = new List<Tile>(); playerTiles = new List<Tile>();
Tiles = playerTiles.AsReadOnly(); Tiles = playerTiles.AsReadOnly();
} }
public string GetNameTag public string NameTag { get; set; }
{
get { return nameTag; }
set { nameTag = value; }
}
public bool IsPlaying { get; set; } = false; public bool IsPlaying { get; set; } = false;
@ -41,6 +38,5 @@ namespace QwirkleClassLibrary
{ {
return playerTiles.Remove(tile); return playerTiles.Remove(tile);
} }
} }
} }

@ -14,7 +14,7 @@ namespace QwirkleClassLibrary
public Score(Player p) public Score(Player p)
{ {
score = 0; score = 0;
playerTag = p.GetNameTag; playerTag = p.NameTag;
} }
} }

@ -15,7 +15,7 @@ namespace TestBase
return; return;
} }
Player player = new Player(playertag); Player player = new Player(playertag);
Assert.Equal(playertag, player.GetNameTag); Assert.Equal(playertag, player.NameTag);
} }
[Fact] [Fact]

Loading…
Cancel
Save