From 867f542f3d4df80160e91c0d20ceee944c7a1205 Mon Sep 17 00:00:00 2001 From: "jeremy.mouyon" Date: Wed, 10 Apr 2024 19:30:14 +0200 Subject: [PATCH 1/5] programcs upgrade + units test --- Qwirkle/QwirkleClassLibrary/Game.cs | 19 ++-- Qwirkle/QwirkleClassLibrary/Player.cs | 21 +++-- Qwirkle/QwirkleClassLibrary/Tile.cs | 5 + Qwirkle/QwirkleClassLibrary/TileBag.cs | 8 +- Qwirkle/QwirkleConsoleApp/Program.cs | 123 +++++++++++++++---------- Qwirkle/TestBase/UnitTest1.cs | 40 ++++++-- 6 files changed, 139 insertions(+), 77 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Game.cs b/Qwirkle/QwirkleClassLibrary/Game.cs index 35b479d..f6b6983 100644 --- a/Qwirkle/QwirkleClassLibrary/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Game.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -11,16 +12,18 @@ namespace QwirkleClassLibrary public class Game { private TileBag bag; - private List players; private bool gameRunning; private Board board; + public ReadOnlyCollection PlayerList { get; private set; } + private readonly List players = new List(); + public Game() { - this.players = new List(); board = new Board(); bag = new TileBag(3); gameRunning = false; + PlayerList = players.AsReadOnly(); } public bool AddPlayerInGame(string? PlayerTag) @@ -80,17 +83,15 @@ namespace QwirkleClassLibrary get { return players.Count; } } - public List ListTilesBag - { - get { return bag.TilesInBag(); } - } - + // a passer en program cs public string ShowTileOfPlayer(int posplayer) { - List tiles = players[posplayer].Tiles; + List tiles = players[posplayer].Tiles.ToList(); string r = ("Tile of " + posplayer + " : "); + StringBuilder stringBuilder = new StringBuilder(); // A UTILISER !!! + foreach (Tile tile in tiles) { r = (r + " " + tile.NameColorTile()); @@ -121,7 +122,7 @@ namespace QwirkleClassLibrary { for (int j = 0; j < 6; j++) { - Tile tile = ListTilesBag[j]; + Tile tile = bag.TilesBag[j]; players[i].AddTilePlayer(tile); bag.RemoveTileInBag(tile); } diff --git a/Qwirkle/QwirkleClassLibrary/Player.cs b/Qwirkle/QwirkleClassLibrary/Player.cs index 3aaab70..53295c6 100644 --- a/Qwirkle/QwirkleClassLibrary/Player.cs +++ b/Qwirkle/QwirkleClassLibrary/Player.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Collections.ObjectModel; using System.Linq; using System.Text; using System.Threading.Tasks; @@ -9,12 +10,18 @@ namespace QwirkleClassLibrary public class Player { private string nameTag; - private List playerTiles; - + public ReadOnlyCollection Tiles { get; private set; } + private readonly List playerTiles = new List(); + public Player(string name) { + if(name==null || string.IsNullOrEmpty(name)) + { + throw new ArgumentNullException("name"); + } nameTag = name; - Tiles = new List(); + playerTiles = new List(); + Tiles = playerTiles.AsReadOnly(); } public string GetNameTag @@ -27,17 +34,13 @@ namespace QwirkleClassLibrary public void AddTilePlayer(Tile tile) { - Tiles.Add(tile); + playerTiles.Add(tile); } public bool RemoveTilePlayer(Tile tile) { - return Tiles.Remove(tile); + return playerTiles.Remove(tile); } - public List Tiles - { - get; - } } } diff --git a/Qwirkle/QwirkleClassLibrary/Tile.cs b/Qwirkle/QwirkleClassLibrary/Tile.cs index a2510a0..4a65dfc 100644 --- a/Qwirkle/QwirkleClassLibrary/Tile.cs +++ b/Qwirkle/QwirkleClassLibrary/Tile.cs @@ -31,5 +31,10 @@ namespace QwirkleClassLibrary { get { return this.color; } } + + public override string ToString() + { + return shape.ToString() + color.ToString(); + } } } diff --git a/Qwirkle/QwirkleClassLibrary/TileBag.cs b/Qwirkle/QwirkleClassLibrary/TileBag.cs index 8f10257..42c9982 100644 --- a/Qwirkle/QwirkleClassLibrary/TileBag.cs +++ b/Qwirkle/QwirkleClassLibrary/TileBag.cs @@ -9,7 +9,7 @@ namespace QwirkleClassLibrary { public class TileBag { - public ReadOnlyCollection Tiles { get ; private set; } + public ReadOnlyCollection TilesBag { get ; private set; } private readonly List tiles = new List(); public TileBag(int nbSet) @@ -25,6 +25,7 @@ namespace QwirkleClassLibrary } } } + TilesBag = tiles.AsReadOnly(); } public void RemoveTileInBag(Tile tile) @@ -37,11 +38,6 @@ namespace QwirkleClassLibrary } } } - - public List TilesInBag() - { - return tiles; - } } } diff --git a/Qwirkle/QwirkleConsoleApp/Program.cs b/Qwirkle/QwirkleConsoleApp/Program.cs index 7489433..cca092d 100644 --- a/Qwirkle/QwirkleConsoleApp/Program.cs +++ b/Qwirkle/QwirkleConsoleApp/Program.cs @@ -1,10 +1,10 @@ using QwirkleClassLibrary; +using System.Text; using static System.Console; -static void testJeremy() -{ - Game game = new Game(); +static void addPlayer(Game game) +{ string? enterline = ""; do @@ -21,64 +21,93 @@ static void testJeremy() } } while (enterline != "quit"); +} - game.StartGame(); +static void MainMenu(Game game) +{ + game.TilsBagPlayer(); + String TagPlayerPlay; + TagPlayerPlay = game.NextPlayer(); - if (game.GameRunning == true) + Write(" --------------------- GAME ! ------------------------ \n"); + + + Write(TagPlayerPlay + " you have main now ! \n"); + + Write("\n --------------------- YOUR TILES ------------------------ \n"); + + + int pos = game.GetPlayingPlayerPosition(); + + StringBuilder stringBuilder = new StringBuilder(); + + for(int i = 0; i < game.PlayerList[pos].Tiles.Count(); i++) { + stringBuilder.AppendLine(game.PlayerList[pos].Tiles[i].ToString()); + } - game.TilsBagPlayer(); + Write(stringBuilder); - String TagPlayerPlay; - TagPlayerPlay = game.NextPlayer(); - Write(TagPlayerPlay + " you have main now ! \n"); - string s = game.ShowTileOfPlayer(game.GetPlayingPlayerPosition()); - Write(s + "\n"); + Write("\n --------------------- CHOICES ------------------------ \n"); - Write("[1] Place your tiles \n"); - Write("[2] Swap your tiles \n"); + Write("[1] Place your tiles \n"); + Write("[2] Swap your tiles \n"); - int enter = Convert.ToInt32(ReadLine()); + int enter = Convert.ToInt32(ReadLine()); - Tile tile = null; + switch (enter) + { + case 1: + CaseOneAddTile(game); + break; + case 2: + break; + } +} - switch (enter) +static void CaseOneAddTile(Game game) +{ + Tile tile = null; + Write("Enter no tile : "); + int no = Convert.ToInt32(ReadLine()); + + if (no >= 0 && no <= 5) + { + tile = game.TileOfPlayerWithPos(no); + Write("Enter x : "); + int x = Convert.ToInt32(ReadLine()); + Write("Enter y : "); + int y = Convert.ToInt32(ReadLine()); + if (game.PlaceTileGame(tile, x, y) == true) + { + Write("ok ! your tile is placed \n"); + + } + else { - case 1: - // si good faire des boucles demain - Write("Enter no tile : "); - int no = Convert.ToInt32(ReadLine()); - - if (no >= 0 && no <= 5) - { - tile = game.TileOfPlayerWithPos(no); - Write("Enter x : "); - int x = Convert.ToInt32(ReadLine()); - Write("Enter y : "); - int y = Convert.ToInt32(ReadLine()); - if (game.PlaceTileGame(tile, x, y) == true) - { - Write("ok ! your tile is placed \n"); - - } - else - { - Write("no no no \n"); - } - } - else - { - Write("No is out of range\n"); - } - - - break; - case 2: - break; + Write("no no no \n"); } + } + else + { + Write("No is out of range\n"); + } +} +static void testJeremy() +{ + Game game = new Game(); + + addPlayer(game); + + game.StartGame(); + + + if (game.GameRunning == true) + { + MainMenu(game); } diff --git a/Qwirkle/TestBase/UnitTest1.cs b/Qwirkle/TestBase/UnitTest1.cs index b759b05..f00d528 100644 --- a/Qwirkle/TestBase/UnitTest1.cs +++ b/Qwirkle/TestBase/UnitTest1.cs @@ -2,14 +2,42 @@ using QwirkleClassLibrary; namespace TestBase { - public class UnitTest1 + public class TestPlayers { - public void Test_PlayerRemoveTile(bool expectedResult) + [Theory] + [InlineData(true, "Mathis")] + [InlineData(false, null)] + public void Test_CreatePlayer(bool isValid, string playertag) { - Tile t = new Tile(Square, Red); - Player p = new Player("Patrick"); - bool result = p.RemoveTilePlayer(t); - Assert.True(result); + if (!isValid) + { + Assert.Throws(() => new Player(playertag)); + return; + } + Player player = new Player(playertag); + Assert.Equal(playertag, player.GetNameTag); + } + + [Fact] + + public void Test_AddTilePlayer() + { + Player p = new Player("cobaye"); + + Tile tile = new Tile(Shape.Round, Color.Orange); + + p.AddTilePlayer(tile); + + bool r = false; + + for(int i = 0; i < p.Tiles.Count; i++) + { + if (p.Tiles[i] == tile) + { + r = true; + } + } + Assert.True(r); } } } \ No newline at end of file From 3850cc8873905f0a14af75b460405f74935a7569 Mon Sep 17 00:00:00 2001 From: "jules.lascret" Date: Wed, 10 Apr 2024 19:31:26 +0200 Subject: [PATCH 2/5] optimized board class + added 1 test that fucking doesn't work --- Qwirkle/QwirkleClassLibrary/Board.cs | 12 +----------- Qwirkle/QwirkleClassLibrary/Cell.cs | 5 +++++ Qwirkle/TestBase/TestCell.cs | 21 +++++++++++++++++++++ 3 files changed, 27 insertions(+), 11 deletions(-) create mode 100644 Qwirkle/TestBase/TestCell.cs diff --git a/Qwirkle/QwirkleClassLibrary/Board.cs b/Qwirkle/QwirkleClassLibrary/Board.cs index 55af03d..ea182d1 100644 --- a/Qwirkle/QwirkleClassLibrary/Board.cs +++ b/Qwirkle/QwirkleClassLibrary/Board.cs @@ -3,7 +3,6 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; -// ReSharper disable All namespace QwirkleClassLibrary { @@ -31,16 +30,7 @@ namespace QwirkleClassLibrary { if (this.Cells[i].GetX == x && this.Cells[i].GetY == y) { - if (Cells[i].IsFree == true) - { - return Cells[i].SetTile(tile); - - } - else - { - return false; - } - + return Cells[i].IsFree == false && Cells[i].SetTile(tile); } } return false; diff --git a/Qwirkle/QwirkleClassLibrary/Cell.cs b/Qwirkle/QwirkleClassLibrary/Cell.cs index 44e0535..9108fe5 100644 --- a/Qwirkle/QwirkleClassLibrary/Cell.cs +++ b/Qwirkle/QwirkleClassLibrary/Cell.cs @@ -11,6 +11,11 @@ public class Cell public Cell(int x, int y) { + if (this.x < 0 || this.y < 0) + { + throw new ArgumentException(""); + } + this.x = x; this.y = y; } diff --git a/Qwirkle/TestBase/TestCell.cs b/Qwirkle/TestBase/TestCell.cs new file mode 100644 index 0000000..07cc6a3 --- /dev/null +++ b/Qwirkle/TestBase/TestCell.cs @@ -0,0 +1,21 @@ +using QwirkleClassLibrary; +namespace TestBase; + +public class TestCell +{ + [Theory] + [InlineData(true, 10, 20, 10, 20)] + [InlineData(false, -10, 20, -10, 20)] + + public void Test_CellConstructor(bool isValid, int expectedX, int expectedY, int x, int y) + { + if (!isValid) + { + Assert.Throws(() => new Cell(x, y)); + } + + Cell c = new Cell(x, y); + Assert.Equal(expectedX, x); + Assert.Equal(expectedY, y); + } +} \ No newline at end of file From 138a04cd54392bbba0cf71cdff77a171f5758259 Mon Sep 17 00:00:00 2001 From: "jeremy.mouyon" Date: Wed, 10 Apr 2024 21:10:42 +0200 Subject: [PATCH 3/5] edit of program cs and game cs : check number of player and stop while + add color + add while for next player and switch --- Qwirkle/QwirkleClassLibrary/Game.cs | 33 ++++------ Qwirkle/QwirkleConsoleApp/Program.cs | 94 ++++++++++++++++++++-------- 2 files changed, 82 insertions(+), 45 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Game.cs b/Qwirkle/QwirkleClassLibrary/Game.cs index f6b6983..4d32293 100644 --- a/Qwirkle/QwirkleClassLibrary/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Game.cs @@ -83,22 +83,6 @@ namespace QwirkleClassLibrary get { return players.Count; } } - // a passer en program cs - public string ShowTileOfPlayer(int posplayer) - { - List tiles = players[posplayer].Tiles.ToList(); - - string r = ("Tile of " + posplayer + " : "); - - StringBuilder stringBuilder = new StringBuilder(); // A UTILISER !!! - - foreach (Tile tile in tiles) - { - r = (r + " " + tile.NameColorTile()); - } - return r; - - } public Tile TileOfPlayerWithPos(int postile) { @@ -135,7 +119,7 @@ namespace QwirkleClassLibrary int posPlayerNextPlay = GetPlayingPlayerPosition() + 1; - if (posPlayerNextPlay >= GetNbPlayers) + if (posPlayerNextPlay > GetNbPlayers) { posPlayerNextPlay = 0; } @@ -152,9 +136,18 @@ namespace QwirkleClassLibrary public bool PlaceTileGame(Tile tile, int x, int y) { - bool r = board.AddTileInCell(x, y, tile); - players[GetPlayingPlayerPosition()].RemoveTilePlayer(tile); - return r; + bool checkremove=false; + bool checkaddcell = board.AddTileInCell(x, y, tile); + if (checkaddcell == true) + { + checkremove = players[GetPlayingPlayerPosition()].RemoveTilePlayer(tile); + } + + if (checkaddcell == checkremove) + { + return checkaddcell; + } + return false; } } diff --git a/Qwirkle/QwirkleConsoleApp/Program.cs b/Qwirkle/QwirkleConsoleApp/Program.cs index cca092d..a52aa12 100644 --- a/Qwirkle/QwirkleConsoleApp/Program.cs +++ b/Qwirkle/QwirkleConsoleApp/Program.cs @@ -1,5 +1,7 @@ using QwirkleClassLibrary; +using System.Net.Quic; using System.Text; +using System.Transactions; using static System.Console; @@ -20,21 +22,35 @@ static void addPlayer(Game game) } } - } while (enterline != "quit"); + } while (game.PlayerList.Count<4 && enterline !="quit"); } static void MainMenu(Game game) { game.TilsBagPlayer(); - String TagPlayerPlay; - TagPlayerPlay = game.NextPlayer(); + Console.ForegroundColor = ConsoleColor.Green; + Write("The loading of the game is well done! Good game :p\n"); + Console.ResetColor(); + + do + { + String TagPlayerPlay; + TagPlayerPlay = game.NextPlayer(); + + Write(" --------------------- GAME ! ------------------------ \n"); - Write(" --------------------- GAME ! ------------------------ \n"); + Write(TagPlayerPlay + " you have main now ! \n"); - Write(TagPlayerPlay + " you have main now ! \n"); + MenuSwitch(game); + + } while (game.GetPlayingPlayerPosition() != 3); // cette boucle permet juste de faire un tour, quand le score fonctionnera il faudra la faire arreter quand la partie sera finis :) + +} +static void ShowTiles(Game game) +{ Write("\n --------------------- YOUR TILES ------------------------ \n"); @@ -42,33 +58,50 @@ static void MainMenu(Game game) StringBuilder stringBuilder = new StringBuilder(); - for(int i = 0; i < game.PlayerList[pos].Tiles.Count(); i++) + for (int i = 0; i < game.PlayerList[pos].Tiles.Count(); i++) { stringBuilder.AppendLine(game.PlayerList[pos].Tiles[i].ToString()); } Write(stringBuilder); - Write("\n --------------------- CHOICES ------------------------ \n"); - - Write("[1] Place your tiles \n"); - Write("[2] Swap your tiles \n"); +} - int enter = Convert.ToInt32(ReadLine()); +static void MenuSwitch(Game game) +{ - switch (enter) + int enter = 0; + do { - case 1: - CaseOneAddTile(game); - break; - case 2: - break; - } + ShowTiles(game); + + Write("\n --------------------- CHOICES ------------------------ \n"); + + Write("[1] Place your tiles \n"); + Write("[2] Swap your tiles \n"); + Write("[3] Skip \n"); + + enter = Convert.ToInt32(ReadLine()); + + switch (enter) + { + case 1: + CaseOneAddTile(game); + break; + case 2: + break; + case 3: + return; + + } + } while (enter != 3); + + } static void CaseOneAddTile(Game game) { - Tile tile = null; + Tile? tile = null; Write("Enter no tile : "); int no = Convert.ToInt32(ReadLine()); @@ -86,7 +119,7 @@ static void CaseOneAddTile(Game game) } else { - Write("no no no \n"); + Write("ERROR : Cell already use \n"); } } else @@ -96,22 +129,33 @@ static void CaseOneAddTile(Game game) } -static void testJeremy() +static void MainGame() { Game game = new Game(); + + Console.BackgroundColor = ConsoleColor.DarkGreen; + Write("WELCOME IN QWIRKLE GAME ! \n For start the game please enter 2 / 4 players ;) \n \n"); + Console.ResetColor(); addPlayer(game); game.StartGame(); - if (game.GameRunning == true) + while (game.GameRunning == false) { - MainMenu(game); - } + game = new Game(); + Console.ForegroundColor= ConsoleColor.Red; + Write("ERROR : Please enter minimun 2 valid player ! \n"); + Console.ResetColor(); + addPlayer(game); + + game.StartGame(); + } + MainMenu(game); } -testJeremy(); +MainGame(); From c55070be58f6fc1f29ca2e5b3121d80e54000fcb Mon Sep 17 00:00:00 2001 From: "jeremy.mouyon" Date: Wed, 10 Apr 2024 22:30:32 +0200 Subject: [PATCH 4/5] fix of test by jules + random distribute --- Qwirkle/QwirkleClassLibrary/Cell.cs | 4 ++-- Qwirkle/QwirkleClassLibrary/Game.cs | 5 ++++- Qwirkle/TestBase/TestCell.cs | 15 +++++++++------ Qwirkle/TestBase/UnitTest1.cs | 22 ++++++++++++++++++++++ 4 files changed, 37 insertions(+), 9 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Cell.cs b/Qwirkle/QwirkleClassLibrary/Cell.cs index 9108fe5..4570e43 100644 --- a/Qwirkle/QwirkleClassLibrary/Cell.cs +++ b/Qwirkle/QwirkleClassLibrary/Cell.cs @@ -11,9 +11,9 @@ public class Cell public Cell(int x, int y) { - if (this.x < 0 || this.y < 0) + if (x < 0 || y < 0) { - throw new ArgumentException(""); + throw new ArgumentException(x.ToString() + y.ToString()); } this.x = x; diff --git a/Qwirkle/QwirkleClassLibrary/Game.cs b/Qwirkle/QwirkleClassLibrary/Game.cs index 4d32293..66dcb53 100644 --- a/Qwirkle/QwirkleClassLibrary/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Game.cs @@ -22,6 +22,7 @@ namespace QwirkleClassLibrary { board = new Board(); bag = new TileBag(3); + Console.Write(bag.TilesBag.Count); gameRunning = false; PlayerList = players.AsReadOnly(); } @@ -106,7 +107,9 @@ namespace QwirkleClassLibrary { for (int j = 0; j < 6; j++) { - Tile tile = bag.TilesBag[j]; + Random random = new Random(); + int val = random.Next(0, bag.TilesBag.Count); + Tile tile = bag.TilesBag[val]; players[i].AddTilePlayer(tile); bag.RemoveTileInBag(tile); } diff --git a/Qwirkle/TestBase/TestCell.cs b/Qwirkle/TestBase/TestCell.cs index 07cc6a3..33f1eba 100644 --- a/Qwirkle/TestBase/TestCell.cs +++ b/Qwirkle/TestBase/TestCell.cs @@ -4,18 +4,21 @@ namespace TestBase; public class TestCell { [Theory] - [InlineData(true, 10, 20, 10, 20)] - [InlineData(false, -10, 20, -10, 20)] - - public void Test_CellConstructor(bool isValid, int expectedX, int expectedY, int x, int y) + [InlineData(true, 10, 20)] + [InlineData(false, -10, -10)] + [InlineData(false, 10, -10)] + [InlineData(false, -10, 10)] + + public void Test_CellConstructor(bool isValid, int x, int y) { if (!isValid) { Assert.Throws(() => new Cell(x, y)); + return; } Cell c = new Cell(x, y); - Assert.Equal(expectedX, x); - Assert.Equal(expectedY, y); + Assert.Equal(x, c.GetX); + Assert.Equal(y, c.GetY); } } \ No newline at end of file diff --git a/Qwirkle/TestBase/UnitTest1.cs b/Qwirkle/TestBase/UnitTest1.cs index f00d528..a8c190e 100644 --- a/Qwirkle/TestBase/UnitTest1.cs +++ b/Qwirkle/TestBase/UnitTest1.cs @@ -39,5 +39,27 @@ namespace TestBase } Assert.True(r); } + + [Fact] + + public void Test_RemoveilePlayer() + { + Player p = new Player("cobaye"); + + Tile tile = new Tile(Shape.Round, Color.Orange); + + p.RemoveTilePlayer(tile); + + bool r = true; + + for (int i = 0; i < p.Tiles.Count; i++) + { + if (p.Tiles[i] == tile) + { + r = false; + } + } + Assert.True(r); + } } } \ No newline at end of file From d4d6b59995e1b3bbbde21cef0315ec4caacddb49 Mon Sep 17 00:00:00 2001 From: "jeremy.mouyon" Date: Thu, 11 Apr 2024 13:31:34 +0200 Subject: [PATCH 5/5] 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 : ");