From de63fd17b61e9f2899d500ad1ce2b731a5255a27 Mon Sep 17 00:00:00 2001 From: "jules.lascret" Date: Tue, 9 Apr 2024 16:59:15 +0200 Subject: [PATCH] Slight modification kinda useless though --- Qwirkle/QwirkleClassLibrary/Board.cs | 8 +++----- Qwirkle/QwirkleClassLibrary/Cell.cs | 3 --- Qwirkle/QwirkleClassLibrary/Game.cs | 18 ++++++++---------- Qwirkle/QwirkleClassLibrary/Player.cs | 26 ++++++++++++-------------- Qwirkle/QwirkleClassLibrary/TileBag.cs | 10 +++------- 5 files changed, 26 insertions(+), 39 deletions(-) diff --git a/Qwirkle/QwirkleClassLibrary/Board.cs b/Qwirkle/QwirkleClassLibrary/Board.cs index 73a7023..7af0a38 100644 --- a/Qwirkle/QwirkleClassLibrary/Board.cs +++ b/Qwirkle/QwirkleClassLibrary/Board.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +// ReSharper disable All namespace QwirkleClassLibrary { @@ -12,7 +13,6 @@ namespace QwirkleClassLibrary public Board() { - //Console.WriteLine("BOARD created !"); Cells = new List(); for (int i = 0; i < 12; i++) @@ -31,19 +31,17 @@ namespace QwirkleClassLibrary { if (this.Cells[i].GetX == x && this.Cells[i].GetY == y) { - if (Cells[i].SetTile(tile) == true) + if (Cells[i].IsFree == false) { - return true; + return Cells[i].SetTile(tile); } else { - //Console.WriteLine("Please enter new coordinates for the cell where you want to place your tile."); return false; } } } - //Console.WriteLine("The cell you're searching for doesn't exist. PLease enter new coordinates for the cell where you want to place your tile."); return false; } } diff --git a/Qwirkle/QwirkleClassLibrary/Cell.cs b/Qwirkle/QwirkleClassLibrary/Cell.cs index 00d3792..44e0535 100644 --- a/Qwirkle/QwirkleClassLibrary/Cell.cs +++ b/Qwirkle/QwirkleClassLibrary/Cell.cs @@ -13,7 +13,6 @@ public class Cell { this.x = x; this.y = y; - //Console.WriteLine("Cell (" + x + ", " + y + ") created"); } public int GetX @@ -41,12 +40,10 @@ public class Cell if(tile == null) { tile = addedTile; - //Console.WriteLine("The tile of shape " + addedTile.GetShape + " and color " + addedTile.GetColor + " has correctly been added to the cell of coordinates x = " + this.x + ", y = " + this.y); return true; } else { - //Console.WriteLine("There already is a tile in this cell !!"); return false; } } diff --git a/Qwirkle/QwirkleClassLibrary/Game.cs b/Qwirkle/QwirkleClassLibrary/Game.cs index d1e0b6f..e3c461e 100644 --- a/Qwirkle/QwirkleClassLibrary/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Game.cs @@ -12,15 +12,13 @@ namespace QwirkleClassLibrary private TileBag bag; private List players; - public Game(List pl) + public Game(List players) { - players = pl; + this.players = players; bag = new TileBag(3); - - players[0].IsPlaying = true; } - public int PositionPlayerPlay() + public int GetPlayingPlayerPosition() { for (int i = 0; i < players.Count; i++) { @@ -34,10 +32,10 @@ namespace QwirkleClassLibrary public int GetNbPlayers { - get { return players.Count; } + get { return players.Count; } } - public List Bag + public List ListTilesBag { get { return bag.TilesInBag(); } } @@ -73,7 +71,7 @@ namespace QwirkleClassLibrary { for (int j = 0; j < 6; j++) { - Tile tile = Bag[j]; + Tile tile = ListTilesBag[j]; players[i].AddTilePlayer(tile); bag.RemoveTileInBag(tile); } @@ -82,9 +80,9 @@ namespace QwirkleClassLibrary public string NextPlayer() { - int posPlayerPlay = PositionPlayerPlay(); + int posPlayerPlay = GetPlayingPlayerPosition(); - int posPlayerNextPlay = PositionPlayerPlay() + 1; + int posPlayerNextPlay = GetPlayingPlayerPosition() + 1; if (posPlayerNextPlay >= GetNbPlayers) { diff --git a/Qwirkle/QwirkleClassLibrary/Player.cs b/Qwirkle/QwirkleClassLibrary/Player.cs index 0dbcb32..3aaab70 100644 --- a/Qwirkle/QwirkleClassLibrary/Player.cs +++ b/Qwirkle/QwirkleClassLibrary/Player.cs @@ -9,37 +9,35 @@ namespace QwirkleClassLibrary public class Player { private string nameTag; - private List tiles; - private bool isPlaying = false; - + private List playerTiles; + public Player(string name) { nameTag = name; - tiles = new List(); + Tiles = new List(); } + public string GetNameTag { get { return nameTag; } + set { nameTag = value; } } - public bool IsPlaying - { - get { return isPlaying; } - set { isPlaying = value; } - } + public bool IsPlaying { get; set; } = false; + public void AddTilePlayer(Tile tile) { - tiles.Add(tile); + Tiles.Add(tile); } + public bool RemoveTilePlayer(Tile tile) { - return tiles.Remove(tile); + return Tiles.Remove(tile); } - public List Tiles // Rajouter un "get" là + public List Tiles { - get{ return tiles; } - + get; } } } diff --git a/Qwirkle/QwirkleClassLibrary/TileBag.cs b/Qwirkle/QwirkleClassLibrary/TileBag.cs index e24c004..8f10257 100644 --- a/Qwirkle/QwirkleClassLibrary/TileBag.cs +++ b/Qwirkle/QwirkleClassLibrary/TileBag.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; @@ -8,14 +9,11 @@ namespace QwirkleClassLibrary { public class TileBag { - public ReadOnlyMemory Tiles { get ; private set; } - private List tiles = new List(); + public ReadOnlyCollection Tiles { get ; private set; } + private readonly List tiles = new List(); public TileBag(int nbSet) { - tiles = new List(); - - for (int i = 0; i < nbSet; i++) { foreach (Shape s in Enum.GetValues(typeof(Shape))) @@ -26,9 +24,7 @@ namespace QwirkleClassLibrary tiles.Add(t); } } - } - } public void RemoveTileInBag(Tile tile)