From 160e4a63015f77ed6541a3f21197e2a75fd4bc35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Mouyon?= Date: Sat, 4 May 2024 09:32:14 +0200 Subject: [PATCH 1/5] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'Documentation/?= =?UTF-8?q?doxygen/Doxyfile'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Documentation/doxygen/Doxyfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/doxygen/Doxyfile b/Documentation/doxygen/Doxyfile index 68ddcdb..cdaae48 100644 --- a/Documentation/doxygen/Doxyfile +++ b/Documentation/doxygen/Doxyfile @@ -125,7 +125,7 @@ WARN_LOGFILE = # Configuration options related to the input files #--------------------------------------------------------------------------- -INPUT = Qwirkle +INPUT = /Qwirkle INPUT_ENCODING = UTF-8 FILE_PATTERNS = *.c \ *.cc \ From a650c5bec7771ec25dd458d0608712d966d3c02a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Mouyon?= Date: Sat, 4 May 2024 09:33:58 +0200 Subject: [PATCH 2/5] =?UTF-8?q?Mise=20=C3=A0=20jour=20de=20'Documentation/?= =?UTF-8?q?doxygen/Doxyfile'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Documentation/doxygen/Doxyfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Documentation/doxygen/Doxyfile b/Documentation/doxygen/Doxyfile index cdaae48..1d9c30e 100644 --- a/Documentation/doxygen/Doxyfile +++ b/Documentation/doxygen/Doxyfile @@ -125,7 +125,7 @@ WARN_LOGFILE = # Configuration options related to the input files #--------------------------------------------------------------------------- -INPUT = /Qwirkle +INPUT = ../../Qwirkle INPUT_ENCODING = UTF-8 FILE_PATTERNS = *.c \ *.cc \ From 5c66fd76f9cb70af614bc881420f2a1cd58f570d Mon Sep 17 00:00:00 2001 From: "jules.lascret" Date: Sat, 4 May 2024 09:52:42 +0200 Subject: [PATCH 3/5] Enhanced PlaceTile method, added SwapTiles method, began to implement IRules.cs into Game.cs --- Qwirkle/QwirkleClassLibrary/Game.cs | 51 +++++++++++++++++++++++--- Qwirkle/QwirkleClassLibrary/IPlayer.cs | 2 +- Qwirkle/QwirkleClassLibrary/IRules.cs | 5 +-- Qwirkle/QwirkleConsoleApp/Program.cs | 40 +++++++++++++++++++- 4 files changed, 86 insertions(+), 12 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Game.cs b/Qwirkle/QwirkleClassLibrary/Game.cs index 21aa5ca..3783c16 100644 --- a/Qwirkle/QwirkleClassLibrary/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Game.cs @@ -9,7 +9,7 @@ using System.Security.Cryptography; namespace QwirkleClassLibrary { - public class Game : IPlayer + public class Game : IPlayer, IRules { private TileBag bag; public bool GameRunning { get; private set; } @@ -20,8 +20,8 @@ namespace QwirkleClassLibrary public Game() { - board = new Board(); bag = new TileBag(3); + board = CreateBoard(); } public bool AddPlayerInGame(string? playerTag) @@ -55,6 +55,12 @@ namespace QwirkleClassLibrary return player; } + public Board CreateBoard() + { + board = new Board(); + return board; + } + public void StartGame() { this.GameRunning = true; @@ -88,7 +94,7 @@ namespace QwirkleClassLibrary { for (int j = 0; j < 6; j++) { - int val = RandomNumberGenerator.GetInt32(0, bag.TilesBag.Count); + int val = RandomNumberGenerator.GetInt32(0, bag.TilesBag.Count + 1); p.AddTileToPlayer(bag.TilesBag[val]); bag.RemoveTileInBag(bag.TilesBag[val]); @@ -138,7 +144,7 @@ namespace QwirkleClassLibrary return false; } - int val = RandomNumberGenerator.GetInt32(0, bag.TilesBag.Count); + int val = RandomNumberGenerator.GetInt32(0, bag.TilesBag.Count + 1); player.AddTileToPlayer(bag.TilesBag[val]); bag.RemoveTileInBag(bag.TilesBag[val]); @@ -146,10 +152,43 @@ namespace QwirkleClassLibrary return true; } - - public bool SwapTiles(Player player) + + public bool SwapTiles(Player player, List tilesToSwap) + { + if (tilesToSwap.Count == 0) + { + return false; + } + + foreach (var t in tilesToSwap) + { + if (player.RemoveTileToPlayer(t) == false) + { + return false; + } + } + + if (DrawTiles(player) == false) + { + return false; + } + + foreach (var t in tilesToSwap) + { + bag.AddTileInBag(t); + } + + return true; + } + + public bool IsMoveCorrect(Tile t, Board b) { return false; } + + public bool IsGameOver() + { + throw new NotImplementedException(); + } } } \ No newline at end of file diff --git a/Qwirkle/QwirkleClassLibrary/IPlayer.cs b/Qwirkle/QwirkleClassLibrary/IPlayer.cs index 48eac76..264ea7c 100644 --- a/Qwirkle/QwirkleClassLibrary/IPlayer.cs +++ b/Qwirkle/QwirkleClassLibrary/IPlayer.cs @@ -10,5 +10,5 @@ public interface IPlayer public bool DrawTiles(Player player); - public bool SwapTiles(Player player); + public bool SwapTiles(Player player, List tilesToSwap); } \ No newline at end of file diff --git a/Qwirkle/QwirkleClassLibrary/IRules.cs b/Qwirkle/QwirkleClassLibrary/IRules.cs index 83180f4..4d0456e 100644 --- a/Qwirkle/QwirkleClassLibrary/IRules.cs +++ b/Qwirkle/QwirkleClassLibrary/IRules.cs @@ -9,8 +9,7 @@ namespace QwirkleClassLibrary public interface IRules { Board CreateBoard(); - bool isMoveCorrect(Tile t, Cell c); - bool isGameOver(); - + bool IsMoveCorrect(Tile t, Board b); + bool IsGameOver(); } } diff --git a/Qwirkle/QwirkleConsoleApp/Program.cs b/Qwirkle/QwirkleConsoleApp/Program.cs index f329073..ef1a41e 100644 --- a/Qwirkle/QwirkleConsoleApp/Program.cs +++ b/Qwirkle/QwirkleConsoleApp/Program.cs @@ -58,7 +58,7 @@ static void AddTile(Game game) Write("Enter the number of the tile you want to place : "); int no = Convert.ToInt32(ReadLine()); - while (no < 1 || no > 6) + while (no is < 1 or > 6) { Write("ERROR : Enter a number between 1 and 6 ! : "); no = Convert.ToInt32(ReadLine()); @@ -81,6 +81,39 @@ static void AddTile(Game game) } } +static void SwapTile(Game game) +{ + var tilesToSwap = new List(); + bool continueSwap = true; + + ShowTiles(game); + + while (continueSwap == true) + { + Write("Enter the number of the tile you want to swap : "); + int no = Convert.ToInt32(ReadLine()); + + if (no is < 1 or > 6) + { + WriteLine("ERROR : Enter a number between 1 and 6 !"); + } + else + { + tilesToSwap.Add(game.TileOfPlayerWithPos(no - 1)); + } + + Write("Do you want to swap another tile ? (y/n) : "); + string? answer = ReadLine(); + + if (answer == "n") + { + continueSwap = false; + } + } + + game.SwapTiles(game.GetPlayingPlayer(), tilesToSwap); +} + static void MenuSwitch(Game game) { int enter = 0; @@ -103,6 +136,8 @@ static void MenuSwitch(Game game) AddTile(game); break; case 2: + SwapTile(game); + enter = 3; break; case 3: return; @@ -125,6 +160,7 @@ static void MainMenu(Game game) WriteLine(" --------------------- GAME ! ------------------------"); WriteLine(tagPlayerPlay + "'s turn !"); + game.DrawTiles(game.GetPlayingPlayer()); MenuSwitch(game); } while (game.GetPlayingPlayerPosition() != game.PlayerList.Count - 1); @@ -146,4 +182,4 @@ static void MainGame() MainMenu(game); } -MainGame(); +MainGame(); \ No newline at end of file From f57eeb6b0c3be09a3e5bad9318c3b1db3c1bcf25 Mon Sep 17 00:00:00 2001 From: "jeremy.mouyon" Date: Sat, 4 May 2024 09:54:55 +0200 Subject: [PATCH 4/5] test --- Qwirkle/QwirkleClassLibrary/TileBag.cs | 16 +++++++- .../TestBase/{UnitTest1.cs => TestPlayer.cs} | 0 Qwirkle/TestBase/TestTileBag.cs | 39 +++++++++++++++++++ 3 files changed, 53 insertions(+), 2 deletions(-) rename Qwirkle/TestBase/{UnitTest1.cs => TestPlayer.cs} (100%) create mode 100644 Qwirkle/TestBase/TestTileBag.cs diff --git a/Qwirkle/QwirkleClassLibrary/TileBag.cs b/Qwirkle/QwirkleClassLibrary/TileBag.cs index d7b7e11..9b16b4b 100644 --- a/Qwirkle/QwirkleClassLibrary/TileBag.cs +++ b/Qwirkle/QwirkleClassLibrary/TileBag.cs @@ -14,6 +14,11 @@ namespace QwirkleClassLibrary public TileBag(int nbSet) { + if (nbSet < 0 || nbSet < 3) + { + throw new ArgumentException(nbSet.ToString()); + } + for (int i = 0; i < nbSet; i++) { foreach (Shape s in Enum.GetValues(typeof(Shape))) @@ -28,20 +33,27 @@ namespace QwirkleClassLibrary TilesBag = tiles.AsReadOnly(); } - public void AddTileInBag(Tile tile) + public bool AddTileInBag(Tile tile) { + if (tiles == null) + { + return false; + } tiles.Add(tile); + return true; } - public void RemoveTileInBag(Tile tile) + public bool RemoveTileInBag(Tile tile) { for (int i = 0; i < tiles.Count; i++) { if (tiles[i] == tile) { tiles.RemoveAt(i); + return true; } } + return false; } } } \ No newline at end of file diff --git a/Qwirkle/TestBase/UnitTest1.cs b/Qwirkle/TestBase/TestPlayer.cs similarity index 100% rename from Qwirkle/TestBase/UnitTest1.cs rename to Qwirkle/TestBase/TestPlayer.cs diff --git a/Qwirkle/TestBase/TestTileBag.cs b/Qwirkle/TestBase/TestTileBag.cs new file mode 100644 index 0000000..84a0058 --- /dev/null +++ b/Qwirkle/TestBase/TestTileBag.cs @@ -0,0 +1,39 @@ +using QwirkleClassLibrary; +namespace TestBase; + +public class TestTileBag +{ + [Theory] + [InlineData(false, 5)] + [InlineData(false, -5)] + [InlineData(true, 2)] + + public void Test_TileBagConstructor(bool isValid, int nbset) + { + if (!isValid) + { + Assert.Throws(() => new TileBag(nbset)); + return; + } + TileBag bag = new TileBag(nbset); + Assert.Equal(bag.TilesBag.Count, nbset); + } + + [Fact] + public void Test_AddTileInBag() + { + Tile t = null; + Tile tok = new(Shape.Club, Color.Green); + TileBag bag = new TileBag(2); + + if (bag.AddTileInBag(t) == false) + { + Assert.True(bag.AddTileInBag(tok)); + + } + + } + + +} + From 99a09fdb40d4ae62ddc1946c14eec8860ebda3c7 Mon Sep 17 00:00:00 2001 From: "jeremy.mouyon" Date: Sat, 4 May 2024 09:57:30 +0200 Subject: [PATCH 5/5] test --- Qwirkle/TestBase/TestTileBag.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/Qwirkle/TestBase/TestTileBag.cs b/Qwirkle/TestBase/TestTileBag.cs index 84a0058..c06f72d 100644 --- a/Qwirkle/TestBase/TestTileBag.cs +++ b/Qwirkle/TestBase/TestTileBag.cs @@ -33,7 +33,5 @@ public class TestTileBag } } - - }