From d4d6b59995e1b3bbbde21cef0315ec4caacddb49 Mon Sep 17 00:00:00 2001 From: "jeremy.mouyon" Date: Thu, 11 Apr 2024 13:31:34 +0200 Subject: [PATCH] show + add tile fix --- Qwirkle/QwirkleClassLibrary/Board.cs | 9 +++++++-- Qwirkle/QwirkleClassLibrary/Cell.cs | 4 ++-- Qwirkle/QwirkleConsoleApp/Program.cs | 3 ++- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Board.cs b/Qwirkle/QwirkleClassLibrary/Board.cs index ea182d1..b1c0f6a 100644 --- a/Qwirkle/QwirkleClassLibrary/Board.cs +++ b/Qwirkle/QwirkleClassLibrary/Board.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; @@ -18,7 +19,7 @@ namespace QwirkleClassLibrary { for (int j = 0; j < 12; j++) { - var localcell = new Cell(i, j); + Cell localcell = new(i, j); Cells.Add(localcell); } } @@ -30,7 +31,11 @@ namespace QwirkleClassLibrary { if (this.Cells[i].GetX == x && this.Cells[i].GetY == y) { - return Cells[i].IsFree == false && Cells[i].SetTile(tile); + if (Cells[i].IsFree == true) + { + return Cells[i].SetTile(tile); + + } } } return false; diff --git a/Qwirkle/QwirkleClassLibrary/Cell.cs b/Qwirkle/QwirkleClassLibrary/Cell.cs index 4570e43..911ee73 100644 --- a/Qwirkle/QwirkleClassLibrary/Cell.cs +++ b/Qwirkle/QwirkleClassLibrary/Cell.cs @@ -15,7 +15,7 @@ public class Cell { throw new ArgumentException(x.ToString() + y.ToString()); } - + this.x = x; this.y = y; } @@ -42,7 +42,7 @@ public class Cell public bool SetTile(Tile addedTile) { - if(tile == null) + if(this.tile == null) { tile = addedTile; return true; diff --git a/Qwirkle/QwirkleConsoleApp/Program.cs b/Qwirkle/QwirkleConsoleApp/Program.cs index a52aa12..0678497 100644 --- a/Qwirkle/QwirkleConsoleApp/Program.cs +++ b/Qwirkle/QwirkleConsoleApp/Program.cs @@ -60,6 +60,7 @@ static void ShowTiles(Game game) for (int i = 0; i < game.PlayerList[pos].Tiles.Count(); i++) { + stringBuilder.Append("[" + (i+1) + "] "); stringBuilder.AppendLine(game.PlayerList[pos].Tiles[i].ToString()); } @@ -107,7 +108,7 @@ static void CaseOneAddTile(Game game) if (no >= 0 && no <= 5) { - tile = game.TileOfPlayerWithPos(no); + tile = game.TileOfPlayerWithPos(no+1); Write("Enter x : "); int x = Convert.ToInt32(ReadLine()); Write("Enter y : ");