From 69d6d2f9d3dc1fdbbafc6f3d653b5daba3c79866 Mon Sep 17 00:00:00 2001 From: "jules.lascret" Date: Tue, 7 May 2024 19:29:43 +0200 Subject: [PATCH] Added some rules for the moves --- Qwirkle/QwirkleClassLibrary/Game.cs | 12 ++++++++---- Qwirkle/QwirkleConsoleApp/Program.cs | 19 +++++++++++++------ 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Game.cs b/Qwirkle/QwirkleClassLibrary/Game.cs index 1262316..af8174d 100644 --- a/Qwirkle/QwirkleClassLibrary/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Game.cs @@ -23,7 +23,7 @@ namespace QwirkleClassLibrary public Game() { - bag = CreateTileBag(3); + bag = CreateTileBag(1); board = CreateBoard(); } @@ -63,7 +63,7 @@ namespace QwirkleClassLibrary public Board CreateBoard() { - board = new Board(12, 12); + board = new Board(5, 5); return board; } @@ -112,7 +112,7 @@ namespace QwirkleClassLibrary { for (int j = 0; j < 6; j++) { - int val = RandomNumberGenerator.GetInt32(0, bag.TilesBag.Count + 1); + int val = RandomNumberGenerator.GetInt32(0, bag.TilesBag.Count); p.AddTileToPlayer(bag.TilesBag[val]); bag.RemoveTileInBag(bag.TilesBag[val]); @@ -221,10 +221,11 @@ namespace QwirkleClassLibrary surroundingTiles.Add(b.GetCell(x, y + 1)?.GetTile); surroundingTiles.Add(b.GetCell(x, y - 1)?.GetTile); - foreach (var tile in surroundingTiles) + foreach (var tile in surroundingTiles.ToList()) { if (tile == null) { + surroundingTiles.Remove(tile); continue; } @@ -234,9 +235,12 @@ namespace QwirkleClassLibrary } } + if(surroundingTiles.Count == 0) return false; + return true; } + public bool IsGameOver() { return false; diff --git a/Qwirkle/QwirkleConsoleApp/Program.cs b/Qwirkle/QwirkleConsoleApp/Program.cs index f96e508..b3b78a1 100644 --- a/Qwirkle/QwirkleConsoleApp/Program.cs +++ b/Qwirkle/QwirkleConsoleApp/Program.cs @@ -70,14 +70,21 @@ static void AddTile(Game game) int x = Convert.ToInt32(ReadLine()); Write("Enter the y of the cell : "); int y = Convert.ToInt32(ReadLine()); - - if (game.PlaceTile(game.GetPlayingPlayer(), tile, x, y) == true) + + if (game.IsMoveCorrect(tile, x, y, game.GetBoard()) == true) { - WriteLine("ok ! your tile is placed"); + if (game.PlaceTile(game.GetPlayingPlayer(), tile, x, y) == true) + { + WriteLine("ok ! your tile is placed"); + } + else + { + WriteLine("ERROR : Cell already used"); + } } else { - WriteLine("ERROR : Cell already used"); + WriteLine("ERROR : Move not correct"); } } @@ -156,9 +163,9 @@ static void ShowBoard(Game game) { for(int y=0; y