From f687f172627922d1c6542d96d814266e9baa9153 Mon Sep 17 00:00:00 2001 From: "jeremy.mouyon" Date: Sat, 6 Apr 2024 16:42:09 +0200 Subject: [PATCH 1/5] 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 From cf35c60518fb98dc4ad065e3349b38610fcda253 Mon Sep 17 00:00:00 2001 From: "jeremy.mouyon" Date: Sat, 6 Apr 2024 16:55:33 +0200 Subject: [PATCH 2/5] nextplayer push --- Qwirkle/QwirkleClassLibrary/Game.cs | 30 ++++++++++++++++++---------- Qwirkle/QwirkleConsoleApp/Program.cs | 14 ++++++++++++- 2 files changed, 32 insertions(+), 12 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Game.cs b/Qwirkle/QwirkleClassLibrary/Game.cs index 64c9a2b..ac82117 100644 --- a/Qwirkle/QwirkleClassLibrary/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Game.cs @@ -12,27 +12,35 @@ namespace QwirkleClassLibrary private TileBag bag; private List players; - public Game(List pl) { + public Game(List pl) + { players = pl; bag = new TileBag(); } - public void SetNextPlayer(Player player_old, Player player_new) + public int PositionPlayerPlay() { - for(int i = 0; i < players.Count; i++) + for (int i = 0; i < players.Count; i++) { - if (players[i] == player_old) - { - players[i].IsPlaying = false; - } - if (players[i] == player_new) + if (players[i].IsPlaying == true) { - players[i].IsPlaying = true; + return i; } - } - + return -1; + } + + public void SetNextPlayer(int old, int neew) + { + players[old].IsPlaying = false; + players[neew].IsPlaying = false; + Console.WriteLine(players[neew].GetName + "you have main now !"); + } } + + + +} } diff --git a/Qwirkle/QwirkleConsoleApp/Program.cs b/Qwirkle/QwirkleConsoleApp/Program.cs index b58a5f3..ee5dc17 100644 --- a/Qwirkle/QwirkleConsoleApp/Program.cs +++ b/Qwirkle/QwirkleConsoleApp/Program.cs @@ -54,4 +54,16 @@ static Game InitializerGame() return new Game(Players); } -Game game = InitializerGame(); \ No newline at end of file +static void NextPlayer(Game game) +{ + int posPlayerPlay = game.PositionPlayerPlay(); + + int posPlayerNextPlay = (game.PositionPlayerPlay() + 1); + + game.SetNextPlayer(posPlayerPlay, posPlayerNextPlay); + +} + +Game game = InitializerGame(); + +NextPlayer(game); \ No newline at end of file From f95c10d3846a4218c924c285c3ff5f94b9844187 Mon Sep 17 00:00:00 2001 From: "jeremy.mouyon" Date: Sat, 6 Apr 2024 16:57:54 +0200 Subject: [PATCH 3/5] fix --- Qwirkle/QwirkleClassLibrary/Game.cs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/Qwirkle/QwirkleClassLibrary/Game.cs b/Qwirkle/QwirkleClassLibrary/Game.cs index ac82117..ea7ee7b 100644 --- a/Qwirkle/QwirkleClassLibrary/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Game.cs @@ -16,6 +16,8 @@ namespace QwirkleClassLibrary { players = pl; bag = new TileBag(); + + players[0].IsPlaying = true; } public int PositionPlayerPlay() @@ -43,4 +45,4 @@ namespace QwirkleClassLibrary } -} + From 81105449de114143766473eb29b0f599443d9112 Mon Sep 17 00:00:00 2001 From: "jeremy.mouyon" Date: Sat, 6 Apr 2024 19:59:13 +0200 Subject: [PATCH 4/5] game / player / tile / tile bag / program --- Qwirkle/QwirkleClassLibrary/Game.cs | 42 ++++++++++++++++++++++++-- Qwirkle/QwirkleClassLibrary/Player.cs | 17 +++++++---- Qwirkle/QwirkleClassLibrary/Tile.cs | 5 +++ Qwirkle/QwirkleClassLibrary/TileBag.cs | 29 ++++++++++++++---- Qwirkle/QwirkleConsoleApp/Program.cs | 38 +++++++++++++++++++++-- 5 files changed, 115 insertions(+), 16 deletions(-) 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); From 8e9e93575fd841d55b440483012e246f447202c0 Mon Sep 17 00:00:00 2001 From: "jeremy.mouyon" Date: Sun, 7 Apr 2024 14:13:08 +0200 Subject: [PATCH 5/5] last edit of this branch --- Qwirkle/QwirkleClassLibrary/Game.cs | 2 +- Qwirkle/QwirkleClassLibrary/Player.cs | 3 +++ Qwirkle/QwirkleClassLibrary/Score.cs | 7 +++++++ Qwirkle/QwirkleConsoleApp/Program.cs | 26 +++++++++++++++----------- 4 files changed, 26 insertions(+), 12 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Game.cs b/Qwirkle/QwirkleClassLibrary/Game.cs index 1f800c6..828a995 100644 --- a/Qwirkle/QwirkleClassLibrary/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Game.cs @@ -57,7 +57,7 @@ namespace QwirkleClassLibrary { List tiles = players[posplayer].Tiles; - string r = ("Tile of " + posplayer); + string r = ("Tile of " + posplayer + " : "); foreach(Tile tile in tiles) { diff --git a/Qwirkle/QwirkleClassLibrary/Player.cs b/Qwirkle/QwirkleClassLibrary/Player.cs index 82a7093..367291f 100644 --- a/Qwirkle/QwirkleClassLibrary/Player.cs +++ b/Qwirkle/QwirkleClassLibrary/Player.cs @@ -11,11 +11,13 @@ namespace QwirkleClassLibrary private string nameTag; private List tiles; private bool isPlaying = false; + private Score s; public Player(string name) { nameTag = name; tiles = new List(); + s = new Score(this); Console.WriteLine("Player created. Name : " + nameTag + "\n"); } @@ -23,6 +25,7 @@ namespace QwirkleClassLibrary { nameTag = "Unknow"; tiles = new List(); + s = new Score(this); Console.WriteLine("Player created. Name : " + nameTag + "\n"); } diff --git a/Qwirkle/QwirkleClassLibrary/Score.cs b/Qwirkle/QwirkleClassLibrary/Score.cs index f855527..9989d92 100644 --- a/Qwirkle/QwirkleClassLibrary/Score.cs +++ b/Qwirkle/QwirkleClassLibrary/Score.cs @@ -10,5 +10,12 @@ namespace QwirkleClassLibrary { private int score; private string playerTag; + + public Score(Player p) + { + score = 0; + playerTag = p.GetName; + } + } } diff --git a/Qwirkle/QwirkleConsoleApp/Program.cs b/Qwirkle/QwirkleConsoleApp/Program.cs index bdd8a07..a03a265 100644 --- a/Qwirkle/QwirkleConsoleApp/Program.cs +++ b/Qwirkle/QwirkleConsoleApp/Program.cs @@ -85,19 +85,23 @@ static void TilsBagPlayer(Game game) } -Game game = InitializerGame(); -Write("\n -------------------------------------------------------- \n"); +static void testJeremy() +{ + Game game = InitializerGame(); + Write("\n -------------------------------------------------------- \n"); + NextPlayer(game); + NextPlayer(game); + NextPlayer(game); + NextPlayer(game); + TilsBagPlayer(game); -NextPlayer(game); -NextPlayer(game); -NextPlayer(game); -NextPlayer(game); + for (int i = 0; i < game.GetNbPlayers; i++) + { + game.ShowTileOfPlayer(i); + } +} -TilsBagPlayer(game); -game.ShowTileOfPlayer(0); -game.ShowTileOfPlayer(1); -game.ShowTileOfPlayer(2); -game.ShowTileOfPlayer(3); +testJeremy();