From f687f172627922d1c6542d96d814266e9baa9153 Mon Sep 17 00:00:00 2001 From: "jeremy.mouyon" Date: Sat, 6 Apr 2024 16:42:09 +0200 Subject: [PATCH] push of edit game player tile tile bag program --- Qwirkle/QwirkleClassLibrary/Game.cs | 38 +++++++++++++++++ Qwirkle/QwirkleClassLibrary/Player.cs | 30 ++++++++------ Qwirkle/QwirkleClassLibrary/Tile.cs | 2 +- Qwirkle/QwirkleClassLibrary/TileBag.cs | 13 ++++++ Qwirkle/QwirkleConsoleApp/Program.cs | 56 +++++++++++++++++++++++++- 5 files changed, 125 insertions(+), 14 deletions(-) create mode 100644 Qwirkle/QwirkleClassLibrary/Game.cs diff --git a/Qwirkle/QwirkleClassLibrary/Game.cs b/Qwirkle/QwirkleClassLibrary/Game.cs new file mode 100644 index 0000000..64c9a2b --- /dev/null +++ b/Qwirkle/QwirkleClassLibrary/Game.cs @@ -0,0 +1,38 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + + +namespace QwirkleClassLibrary +{ + public class Game + { + private TileBag bag; + private List players; + + public Game(List pl) { + players = pl; + bag = new TileBag(); + } + + public void SetNextPlayer(Player player_old, Player player_new) + { + for(int i = 0; i < players.Count; i++) + { + if (players[i] == player_old) + { + players[i].IsPlaying = false; + } + if (players[i] == player_new) + { + players[i].IsPlaying = true; + } + + } + + } + + } +} diff --git a/Qwirkle/QwirkleClassLibrary/Player.cs b/Qwirkle/QwirkleClassLibrary/Player.cs index 2cf19d1..c464ab5 100644 --- a/Qwirkle/QwirkleClassLibrary/Player.cs +++ b/Qwirkle/QwirkleClassLibrary/Player.cs @@ -9,34 +9,40 @@ namespace QwirkleClassLibrary public class Player { private string nameTag; - + private List Tiles; private bool isPlaying = false; public Player(string name) { nameTag = name; - if(isPlaying == false) - { - Console.WriteLine("Player created. Name : " + nameTag + ", Turn to play : No\n"); - } - - else Console.WriteLine("Player created. Name : " + nameTag + ", Turn to play : Yes\n"); + Tiles = new List(); + Console.WriteLine("Player created. Name : " + nameTag + "\n"); + } + public Player() + { + nameTag = "Unknow"; + Tiles = new List(); + Console.WriteLine("Player created. Name : " + nameTag + "\n"); } - public string getName + public string GetName { get { return nameTag; } } - public bool getIsPlaying + public bool IsPlaying { get { return isPlaying; } + set { isPlaying = value; } // pour vulgariser, le C# prends la value qui sert d'égalité !! } - - public void setIsPlaying(bool isPlaying) + public void AddTilePlayer(Tile tile) { - this.isPlaying = isPlaying; + Tiles.Add(tile); + } + public void RemoveTilePlayer(Tile tile) + { + Tiles.Remove(tile); } } diff --git a/Qwirkle/QwirkleClassLibrary/Tile.cs b/Qwirkle/QwirkleClassLibrary/Tile.cs index 62c9294..2280cff 100644 --- a/Qwirkle/QwirkleClassLibrary/Tile.cs +++ b/Qwirkle/QwirkleClassLibrary/Tile.cs @@ -16,7 +16,7 @@ namespace QwirkleClassLibrary { shape = sh; color = co; - Console.WriteLine("A tile of shape " + shape + " and color " + color + " has been created.\n"); + Console.WriteLine("A tile of shape " + shape + " and color " + color + " has been created."); } } } diff --git a/Qwirkle/QwirkleClassLibrary/TileBag.cs b/Qwirkle/QwirkleClassLibrary/TileBag.cs index 6f923f8..f8bc121 100644 --- a/Qwirkle/QwirkleClassLibrary/TileBag.cs +++ b/Qwirkle/QwirkleClassLibrary/TileBag.cs @@ -14,11 +14,24 @@ namespace QwirkleClassLibrary public TileBag() { tiles = new List(); + + foreach (Shape s in Enum.GetValues(typeof(Shape))) + { + foreach (Color c in Enum.GetValues(typeof(Color))) + { + Tile t = new Tile(s, c); + tiles.Add(t); + } + } + } + private void WhithdrawNbTiles() { this.nbtiles = this.nbtiles - 1; } } + } + diff --git a/Qwirkle/QwirkleConsoleApp/Program.cs b/Qwirkle/QwirkleConsoleApp/Program.cs index 0406af4..b58a5f3 100644 --- a/Qwirkle/QwirkleConsoleApp/Program.cs +++ b/Qwirkle/QwirkleConsoleApp/Program.cs @@ -1,3 +1,57 @@ using QwirkleClassLibrary; +using static System.Console; -Console.WriteLine("Hello, World!"); +static Game InitializerGame() +{ + OutputEncoding = System.Text.Encoding.UTF8; + List Players = new List(); + + WriteLine("Enter number of player play : "); + try + { + int nbplayer = Convert.ToInt32(ReadLine()); + + + while (nbplayer <= 1 || nbplayer > 4) + { + WriteLine("ERROR : Enter minmun one player or four max !"); + nbplayer = Convert.ToInt32(ReadLine()); + } + + + for (int i = 0; i < nbplayer; i++) + { + WriteLine("Enter name of player " + (i + 1) + " : \n"); + + String name = ReadLine(); + + bool nameInvalid = string.IsNullOrWhiteSpace(name); + + while (nameInvalid == true) + { + WriteLine("ERROR Incorrect name, please enter name of player " + (i + 1) + " : \n"); + name = ReadLine(); + nameInvalid = string.IsNullOrWhiteSpace(name); + } + + for (int j = 0; j < Players.Count; j++) + { + if (Players[j].GetName == name) + { + name = (name + "bis"); + } + } + + Player p = new Player(name); + Players.Add(p); + + } + + } + catch (Exception e) + { Console.WriteLine(e.Message); } + + return new Game(Players); +} + +Game game = InitializerGame(); \ No newline at end of file