diff --git a/Qwirkle/QwirkleClassLibrary/Game.cs b/Qwirkle/QwirkleClassLibrary/Game.cs index ea7ee7b..1f800c6 100644 --- a/Qwirkle/QwirkleClassLibrary/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Game.cs @@ -26,16 +26,54 @@ namespace QwirkleClassLibrary { if (players[i].IsPlaying == true) { + Console.WriteLine(i); return i; } } return -1; } + public int GetNbPlayers + { + get { return players.Count; } + } + + public void RemoveTileInBagGame(Tile tile) + { + bag.RemoveTileInBag(tile); + } + + public List Bag + { + get { return bag.TilesInBag(); } + } + + public void AddTileInBagOfPlayer(int posplayer, Tile tile) + { + players[posplayer].AddTilePlayer(tile); + } + + public void ShowTileOfPlayer(int posplayer) + { + List tiles = players[posplayer].Tiles; + + string r = ("Tile of " + posplayer); + + foreach(Tile tile in tiles) + { + r = (r + tile.NameColorTile()); + } + Console.WriteLine(r); + + } + public void SetNextPlayer(int old, int neew) { - players[old].IsPlaying = false; - players[neew].IsPlaying = false; + if (old >= 0) + { + players[old].IsPlaying = false; + } + players[neew].IsPlaying = true; Console.WriteLine(players[neew].GetName + "you have main now !"); } diff --git a/Qwirkle/QwirkleClassLibrary/Player.cs b/Qwirkle/QwirkleClassLibrary/Player.cs index c464ab5..82a7093 100644 --- a/Qwirkle/QwirkleClassLibrary/Player.cs +++ b/Qwirkle/QwirkleClassLibrary/Player.cs @@ -9,20 +9,20 @@ namespace QwirkleClassLibrary public class Player { private string nameTag; - private List Tiles; + private List tiles; private bool isPlaying = false; public Player(string name) { nameTag = name; - Tiles = new List(); + tiles = new List(); Console.WriteLine("Player created. Name : " + nameTag + "\n"); } public Player() { nameTag = "Unknow"; - Tiles = new List(); + tiles = new List(); Console.WriteLine("Player created. Name : " + nameTag + "\n"); } @@ -38,12 +38,17 @@ namespace QwirkleClassLibrary } public void AddTilePlayer(Tile tile) { - Tiles.Add(tile); + tiles.Add(tile); } public void RemoveTilePlayer(Tile tile) - { - Tiles.Remove(tile); + { + tiles.Remove(tile); } + public List Tiles + { + get{ return tiles; } + + } } } diff --git a/Qwirkle/QwirkleClassLibrary/Tile.cs b/Qwirkle/QwirkleClassLibrary/Tile.cs index 2280cff..7a50a7d 100644 --- a/Qwirkle/QwirkleClassLibrary/Tile.cs +++ b/Qwirkle/QwirkleClassLibrary/Tile.cs @@ -18,5 +18,10 @@ namespace QwirkleClassLibrary color = co; Console.WriteLine("A tile of shape " + shape + " and color " + color + " has been created."); } + + public string NameColorTile() + { + return (color.ToString() + " , " + shape.ToString()); + } } } diff --git a/Qwirkle/QwirkleClassLibrary/TileBag.cs b/Qwirkle/QwirkleClassLibrary/TileBag.cs index f8bc121..158200c 100644 --- a/Qwirkle/QwirkleClassLibrary/TileBag.cs +++ b/Qwirkle/QwirkleClassLibrary/TileBag.cs @@ -15,21 +15,38 @@ namespace QwirkleClassLibrary { tiles = new List(); - foreach (Shape s in Enum.GetValues(typeof(Shape))) + + for(int i=0; i<3; i++) { - foreach (Color c in Enum.GetValues(typeof(Color))) + foreach (Shape s in Enum.GetValues(typeof(Shape))) { - Tile t = new Tile(s, c); - tiles.Add(t); + foreach (Color c in Enum.GetValues(typeof(Color))) + { + Tile t = new Tile(s, c); + tiles.Add(t); + } } + } + } + public void RemoveTileInBag(Tile tile) + { + for(int i=0; i TilesInBag() { - this.nbtiles = this.nbtiles - 1; + return tiles; } } diff --git a/Qwirkle/QwirkleConsoleApp/Program.cs b/Qwirkle/QwirkleConsoleApp/Program.cs index ee5dc17..bdd8a07 100644 --- a/Qwirkle/QwirkleConsoleApp/Program.cs +++ b/Qwirkle/QwirkleConsoleApp/Program.cs @@ -58,12 +58,46 @@ static void NextPlayer(Game game) { int posPlayerPlay = game.PositionPlayerPlay(); - int posPlayerNextPlay = (game.PositionPlayerPlay() + 1); + int posPlayerNextPlay = game.PositionPlayerPlay() + 1; + + if (posPlayerNextPlay >= game.GetNbPlayers) + { + posPlayerNextPlay = 0; + } game.SetNextPlayer(posPlayerPlay, posPlayerNextPlay); +} + +static void TilsBagPlayer(Game game) +{ + List listTile = game.Bag; + + for (int i = 0; i < game.GetNbPlayers; i++) + { + for (int j = 0; j < 6; j++) + { + Tile tile = listTile[j]; + game.AddTileInBagOfPlayer(i, tile); + game.RemoveTileInBagGame(tile); + } + } } + Game game = InitializerGame(); +Write("\n -------------------------------------------------------- \n"); + + + +NextPlayer(game); +NextPlayer(game); +NextPlayer(game); +NextPlayer(game); + +TilsBagPlayer(game); -NextPlayer(game); \ No newline at end of file +game.ShowTileOfPlayer(0); +game.ShowTileOfPlayer(1); +game.ShowTileOfPlayer(2); +game.ShowTileOfPlayer(3);