diff --git a/Qwirkle/QwirkleClassLibrary/Board.cs b/Qwirkle/QwirkleClassLibrary/Boards/Board.cs similarity index 89% rename from Qwirkle/QwirkleClassLibrary/Board.cs rename to Qwirkle/QwirkleClassLibrary/Boards/Board.cs index 8d48d6c..7b50f3d 100644 --- a/Qwirkle/QwirkleClassLibrary/Board.cs +++ b/Qwirkle/QwirkleClassLibrary/Boards/Board.cs @@ -5,14 +5,15 @@ using System.Linq; using System.Security.Cryptography; using System.Text; using System.Threading.Tasks; +using QwirkleClassLibrary.Tiles; -namespace QwirkleClassLibrary +namespace QwirkleClassLibrary.Boards { public class Board { public ReadOnlyCollection ReadCells => cells.AsReadOnly(); private readonly List cells = new(); - + public int Rows { get; } public int Columns { get; } @@ -20,7 +21,7 @@ namespace QwirkleClassLibrary { Rows = rows; Columns = cols; - + for (int a = 0; a < Rows; a++) { for (int b = 0; b < Columns; b++) @@ -47,7 +48,7 @@ namespace QwirkleClassLibrary { for (int i = 0; i < cells.Count; i++) { - if (this.cells[i].GetX != x || this.cells[i].GetY != y) continue; + if (cells[i].GetX != x || cells[i].GetY != y) continue; if (cells[i].IsFree) { return cells[i].SetTile(tile); @@ -65,12 +66,12 @@ namespace QwirkleClassLibrary { return ReadCells; } - + public Cell? GetCell(int x, int y) { for (int i = 0; i < cells.Count; i++) { - if (this.cells[i].GetX == x && this.cells[i].GetY == y) + if (cells[i].GetX == x && cells[i].GetY == y) { return cells[i]; } diff --git a/Qwirkle/QwirkleClassLibrary/Cell.cs b/Qwirkle/QwirkleClassLibrary/Boards/Cell.cs similarity index 89% rename from Qwirkle/QwirkleClassLibrary/Cell.cs rename to Qwirkle/QwirkleClassLibrary/Boards/Cell.cs index 88ad90b..544b284 100644 --- a/Qwirkle/QwirkleClassLibrary/Cell.cs +++ b/Qwirkle/QwirkleClassLibrary/Boards/Cell.cs @@ -1,7 +1,8 @@ // ReSharper disable All using System.Runtime.CompilerServices; +using QwirkleClassLibrary.Tiles; -namespace QwirkleClassLibrary; +namespace QwirkleClassLibrary.Boards; public class Cell { @@ -42,7 +43,7 @@ public class Cell public bool SetTile(Tile addedTile) { - if(this.tile == null) + if (tile == null) { tile = addedTile; return true; diff --git a/Qwirkle/QwirkleClassLibrary/AddPlayerNotifiedEventArgs.cs b/Qwirkle/QwirkleClassLibrary/Events/AddPlayerNotifiedEventArgs.cs similarity index 67% rename from Qwirkle/QwirkleClassLibrary/AddPlayerNotifiedEventArgs.cs rename to Qwirkle/QwirkleClassLibrary/Events/AddPlayerNotifiedEventArgs.cs index 1f6abd3..5969f87 100644 --- a/Qwirkle/QwirkleClassLibrary/AddPlayerNotifiedEventArgs.cs +++ b/Qwirkle/QwirkleClassLibrary/Events/AddPlayerNotifiedEventArgs.cs @@ -1,8 +1,8 @@ -namespace QwirkleClassLibrary +namespace QwirkleClassLibrary.Events { public class AddPlayerNotifiedEventArgs : EventArgs { - public string returnedNotified { get; private set; } + public string returnedNotified { get; private set; } public AddPlayerNotifiedEventArgs(string returnedNotified) { diff --git a/Qwirkle/QwirkleClassLibrary/EndOfGameNotifiedEventArgs.cs b/Qwirkle/QwirkleClassLibrary/Events/EndOfGameNotifiedEventArgs.cs similarity index 74% rename from Qwirkle/QwirkleClassLibrary/EndOfGameNotifiedEventArgs.cs rename to Qwirkle/QwirkleClassLibrary/Events/EndOfGameNotifiedEventArgs.cs index 992135f..b36f906 100644 --- a/Qwirkle/QwirkleClassLibrary/EndOfGameNotifiedEventArgs.cs +++ b/Qwirkle/QwirkleClassLibrary/Events/EndOfGameNotifiedEventArgs.cs @@ -1,4 +1,6 @@ -namespace QwirkleClassLibrary +using QwirkleClassLibrary.Players; + +namespace QwirkleClassLibrary.Events { public class EndOfGameNotifiedEventArgs { diff --git a/Qwirkle/QwirkleClassLibrary/NextPlayerNotifiedEventArgs.cs b/Qwirkle/QwirkleClassLibrary/Events/NextPlayerNotifiedEventArgs.cs similarity index 75% rename from Qwirkle/QwirkleClassLibrary/NextPlayerNotifiedEventArgs.cs rename to Qwirkle/QwirkleClassLibrary/Events/NextPlayerNotifiedEventArgs.cs index d406f4b..967ca26 100644 --- a/Qwirkle/QwirkleClassLibrary/NextPlayerNotifiedEventArgs.cs +++ b/Qwirkle/QwirkleClassLibrary/Events/NextPlayerNotifiedEventArgs.cs @@ -1,4 +1,6 @@ -namespace QwirkleClassLibrary +using QwirkleClassLibrary.Players; + +namespace QwirkleClassLibrary.Events { public class NextPlayerNotifiedEventArgs : EventArgs { diff --git a/Qwirkle/QwirkleClassLibrary/PlaceTileNotifiedEventArgs.cs b/Qwirkle/QwirkleClassLibrary/Events/PlaceTileNotifiedEventArgs.cs similarity index 69% rename from Qwirkle/QwirkleClassLibrary/PlaceTileNotifiedEventArgs.cs rename to Qwirkle/QwirkleClassLibrary/Events/PlaceTileNotifiedEventArgs.cs index 2abbd8a..9608417 100644 --- a/Qwirkle/QwirkleClassLibrary/PlaceTileNotifiedEventArgs.cs +++ b/Qwirkle/QwirkleClassLibrary/Events/PlaceTileNotifiedEventArgs.cs @@ -1,8 +1,10 @@ -namespace QwirkleClassLibrary +using QwirkleClassLibrary.Tiles; + +namespace QwirkleClassLibrary.Events { public class PlaceTileNotifiedEventArgs : EventArgs { - public Tile tile { get; private set; } + public Tile tile { get; private set; } public string reason { get; private set; } diff --git a/Qwirkle/QwirkleClassLibrary/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs similarity index 96% rename from Qwirkle/QwirkleClassLibrary/Game.cs rename to Qwirkle/QwirkleClassLibrary/Games/Game.cs index 50f6b36..2be0031 100644 --- a/Qwirkle/QwirkleClassLibrary/Game.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs @@ -8,8 +8,12 @@ using System.Xml.Linq; using System.Security.Cryptography; using System.Collections; using System.Collections.Immutable; +using QwirkleClassLibrary.Tiles; +using QwirkleClassLibrary.Boards; +using QwirkleClassLibrary.Events; +using QwirkleClassLibrary.Players; -namespace QwirkleClassLibrary +namespace QwirkleClassLibrary.Games { public class Game : IPlayer, IRules @@ -62,7 +66,7 @@ namespace QwirkleClassLibrary return false; } - if (this.GameRunning) + if (GameRunning) { OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR : The game is running.")); return false; @@ -116,7 +120,7 @@ namespace QwirkleClassLibrary public bool StartGame() { if (players.Count < 2 || players.Count >= 5) return false; - this.GameRunning = true; + GameRunning = true; return true; } @@ -487,14 +491,14 @@ namespace QwirkleClassLibrary { for (int i = 0; i < PlayerTilesBagPos.Count; i++) { - for (int j = 0; j < this.players[PlayerTilesBagPos[i]].Tiles.Count; j++) + for (int j = 0; j < players[PlayerTilesBagPos[i]].Tiles.Count; j++) { - for (int b = 0; b < this.board.ReadCells.Count; b++) + for (int b = 0; b < board.ReadCells.Count; b++) { - int x = this.board.ReadCells[b].GetX; - int y = this.board.ReadCells[b].GetY; + int x = board.ReadCells[b].GetX; + int y = board.ReadCells[b].GetY; - if (IsMoveCorrect(this.players[PlayerTilesBagPos[i]].Tiles[j], x, y, this.board)) + if (IsMoveCorrect(players[PlayerTilesBagPos[i]].Tiles[j], x, y, board)) { return true; } diff --git a/Qwirkle/QwirkleClassLibrary/IPlayer.cs b/Qwirkle/QwirkleClassLibrary/Games/IPlayer.cs similarity index 76% rename from Qwirkle/QwirkleClassLibrary/IPlayer.cs rename to Qwirkle/QwirkleClassLibrary/Games/IPlayer.cs index a8b769d..3135127 100644 --- a/Qwirkle/QwirkleClassLibrary/IPlayer.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/IPlayer.cs @@ -1,19 +1,22 @@ using System.Collections.ObjectModel; +using QwirkleClassLibrary.Boards; +using QwirkleClassLibrary.Players; +using QwirkleClassLibrary.Tiles; -namespace QwirkleClassLibrary; +namespace QwirkleClassLibrary.Games; public interface IPlayer { public Player CreatePlayer(string playerTag); - + public string SetNextPlayer(); public string SetFirstPlayer(); - + public bool PlaceTile(Player player, Tile tile, int x, int y); - + public bool DrawTiles(Player player); - + public bool SwapTiles(Player player, List tilesToSwap); public int GetPlayerScore(Player player, ReadOnlyCollection cellsPlayed, Board b); diff --git a/Qwirkle/QwirkleClassLibrary/IRules.cs b/Qwirkle/QwirkleClassLibrary/Games/IRules.cs similarity index 77% rename from Qwirkle/QwirkleClassLibrary/IRules.cs rename to Qwirkle/QwirkleClassLibrary/Games/IRules.cs index 78c1759..064fde2 100644 --- a/Qwirkle/QwirkleClassLibrary/IRules.cs +++ b/Qwirkle/QwirkleClassLibrary/Games/IRules.cs @@ -3,21 +3,24 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; +using QwirkleClassLibrary.Boards; +using QwirkleClassLibrary.Players; +using QwirkleClassLibrary.Tiles; -namespace QwirkleClassLibrary +namespace QwirkleClassLibrary.Games { public interface IRules { Board CreateBoard(); - + TileBag CreateTileBag(int nbSet); - + bool IsMoveCorrect(Tile t, int x, int y, Board b); - + bool CheckExtendedSurroundingCells(Tile tile, int x, int y, int dx, int dy, Board b); - + bool CheckTilesInLine(List cells, Board b, int x, int y); - + bool CheckGameOver(Player player); } } diff --git a/Qwirkle/QwirkleClassLibrary/Player.cs b/Qwirkle/QwirkleClassLibrary/Players/Player.cs similarity index 84% rename from Qwirkle/QwirkleClassLibrary/Player.cs rename to Qwirkle/QwirkleClassLibrary/Players/Player.cs index f0b8fdf..fe3530e 100644 --- a/Qwirkle/QwirkleClassLibrary/Player.cs +++ b/Qwirkle/QwirkleClassLibrary/Players/Player.cs @@ -1,39 +1,40 @@ -using System; -using System.Collections.Generic; -using System.Collections.ObjectModel; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace QwirkleClassLibrary -{ - public class Player - { - public ReadOnlyCollection Tiles => playerTiles.AsReadOnly(); - private readonly List playerTiles = new(); - - public Player(string name) - { - if(name == null || string.IsNullOrEmpty(name)) - { - throw new ArgumentNullException(name); - } - - NameTag = name; - } - - public string NameTag { get; } - - public bool IsPlaying { get; set; } = false; - - public void AddTileToPlayer(Tile tile) - { - playerTiles.Add(tile); - } - - public bool RemoveTileToPlayer(Tile tile) - { - return playerTiles.Remove(tile); - } - } -} +using System; +using System.Collections.Generic; +using System.Collections.ObjectModel; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using QwirkleClassLibrary.Tiles; + +namespace QwirkleClassLibrary.Players +{ + public class Player + { + public ReadOnlyCollection Tiles => playerTiles.AsReadOnly(); + private readonly List playerTiles = new(); + + public Player(string name) + { + if (name == null || string.IsNullOrEmpty(name)) + { + throw new ArgumentNullException(name); + } + + NameTag = name; + } + + public string NameTag { get; } + + public bool IsPlaying { get; set; } = false; + + public void AddTileToPlayer(Tile tile) + { + playerTiles.Add(tile); + } + + public bool RemoveTileToPlayer(Tile tile) + { + return playerTiles.Remove(tile); + } + } +} diff --git a/Qwirkle/QwirkleClassLibrary/Score.cs b/Qwirkle/QwirkleClassLibrary/Players/Score.cs similarity index 85% rename from Qwirkle/QwirkleClassLibrary/Score.cs rename to Qwirkle/QwirkleClassLibrary/Players/Score.cs index ff52f78..d0bd957 100644 --- a/Qwirkle/QwirkleClassLibrary/Score.cs +++ b/Qwirkle/QwirkleClassLibrary/Players/Score.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace QwirkleClassLibrary +namespace QwirkleClassLibrary.Players { public struct Score { @@ -18,7 +18,8 @@ namespace QwirkleClassLibrary throw new ArgumentNullException(nameof(p), "player cannot be null"); } else - { PlayerScore = 0; + { + PlayerScore = 0; PlayerTag = p.NameTag; } } diff --git a/Qwirkle/QwirkleClassLibrary/Color.cs b/Qwirkle/QwirkleClassLibrary/Tiles/Color.cs similarity index 83% rename from Qwirkle/QwirkleClassLibrary/Color.cs rename to Qwirkle/QwirkleClassLibrary/Tiles/Color.cs index c35f87f..394317b 100644 --- a/Qwirkle/QwirkleClassLibrary/Color.cs +++ b/Qwirkle/QwirkleClassLibrary/Tiles/Color.cs @@ -1,18 +1,18 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace QwirkleClassLibrary -{ - public enum Color - { - Red, - Blue, - Green, - Yellow, - Orange, - Purple - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace QwirkleClassLibrary.Tiles +{ + public enum Color + { + Red, + Blue, + Green, + Yellow, + Orange, + Purple + } +} diff --git a/Qwirkle/QwirkleClassLibrary/Shape.cs b/Qwirkle/QwirkleClassLibrary/Tiles/Shape.cs similarity index 87% rename from Qwirkle/QwirkleClassLibrary/Shape.cs rename to Qwirkle/QwirkleClassLibrary/Tiles/Shape.cs index 4d3df57..833781b 100644 --- a/Qwirkle/QwirkleClassLibrary/Shape.cs +++ b/Qwirkle/QwirkleClassLibrary/Tiles/Shape.cs @@ -1,22 +1,22 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - - -namespace QwirkleClassLibrary -{ - /// - /// Enum is used to have a finished number of shapes for the tiles. - /// - public enum Shape - { - Square, - Round, - Rhombus, - Club, - Shuriken, - Star - } -} +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + + +namespace QwirkleClassLibrary.Tiles +{ + /// + /// Enum is used to have a finished number of shapes for the tiles. + /// + public enum Shape + { + Square, + Round, + Rhombus, + Club, + Shuriken, + Star + } +} diff --git a/Qwirkle/QwirkleClassLibrary/Tile.cs b/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs similarity index 65% rename from Qwirkle/QwirkleClassLibrary/Tile.cs rename to Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs index 76a509d..e73ec4a 100644 --- a/Qwirkle/QwirkleClassLibrary/Tile.cs +++ b/Qwirkle/QwirkleClassLibrary/Tiles/Tile.cs @@ -1,42 +1,41 @@ -using QwirkleClassLibrary; -using System; -using System.Collections.Generic; -using System.Drawing; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace QwirkleClassLibrary -{ - public class Tile - { - private readonly Shape shape; - private readonly Color color; - - public Tile(Shape sh, Color co) - { - shape = sh; - color = co; - } - - public string NameColorTile() - { - return color.ToString() + shape.ToString(); - } - - public Shape GetShape - { - get { return this.shape; } - } - - public Color GetColor - { - get { return this.color; } - } - - public override string ToString() - { - return color.ToString() + shape.ToString(); - } - } +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; + +namespace QwirkleClassLibrary.Tiles +{ + public class Tile + { + private readonly Shape shape; + private readonly Color color; + + public Tile(Shape sh, Color co) + { + shape = sh; + color = co; + } + + public string NameColorTile() + { + return color.ToString() + shape.ToString(); + } + + public Shape GetShape + { + get { return shape; } + } + + public Color GetColor + { + get { return color; } + } + + public override string ToString() + { + return color.ToString() + " " + shape.ToString(); + } + } } \ No newline at end of file diff --git a/Qwirkle/QwirkleClassLibrary/TileBag.cs b/Qwirkle/QwirkleClassLibrary/Tiles/TileBag.cs similarity index 92% rename from Qwirkle/QwirkleClassLibrary/TileBag.cs rename to Qwirkle/QwirkleClassLibrary/Tiles/TileBag.cs index 21f1381..e4154ba 100644 --- a/Qwirkle/QwirkleClassLibrary/TileBag.cs +++ b/Qwirkle/QwirkleClassLibrary/Tiles/TileBag.cs @@ -5,11 +5,11 @@ using System.Linq; using System.Text; using System.Threading.Tasks; -namespace QwirkleClassLibrary +namespace QwirkleClassLibrary.Tiles { public class TileBag { - public ReadOnlyCollection TilesBag { get ; private set; } + public ReadOnlyCollection TilesBag { get; private set; } private readonly List tiles = new List(); public TileBag(int nbSet) @@ -33,7 +33,7 @@ namespace QwirkleClassLibrary TilesBag = tiles.AsReadOnly(); } - + public bool AddTileInBag(Tile tile) { if (tile == null) diff --git a/Qwirkle/QwirkleConsoleApp/NotificationClass.cs b/Qwirkle/QwirkleConsoleApp/NotificationClass.cs index b7c9ef2..4f05a50 100644 --- a/Qwirkle/QwirkleConsoleApp/NotificationClass.cs +++ b/Qwirkle/QwirkleConsoleApp/NotificationClass.cs @@ -1,4 +1,4 @@ -using QwirkleClassLibrary; +using QwirkleClassLibrary.Events; using System; using System.Collections.Generic; using System.Linq; diff --git a/Qwirkle/QwirkleConsoleApp/Program.cs b/Qwirkle/QwirkleConsoleApp/Program.cs index a530b80..6ebf71a 100644 --- a/Qwirkle/QwirkleConsoleApp/Program.cs +++ b/Qwirkle/QwirkleConsoleApp/Program.cs @@ -1,4 +1,7 @@ -using QwirkleClassLibrary; +using QwirkleClassLibrary.Boards; +using QwirkleClassLibrary.Games; +using QwirkleClassLibrary.Players; +using QwirkleClassLibrary.Tiles; using QwirkleConsoleApp; using System.Collections.Immutable; using System.Collections.ObjectModel; @@ -114,7 +117,8 @@ static void AddTile(Game game) WriteLine("ERROR : You must type. Please retry : "); ResetColor(); } - + game.PlaceTile(game.GetPlayingPlayer(), tile, x, y); + game.PlaceTileNotified -= nc.NotificationAddTile; } } } @@ -244,13 +248,14 @@ static void ShowScoreBoard(Game g) WriteLine(" --------------------- THE SCORE BOARD : ---------------------"); int i = 0; - foreach (KeyValuePair pair in g.ScoreBoard) + + var sb = g.ScoreBoard.OrderByDescending(x => x.Value).ThenBy(x => x.Key.NameTag); + + foreach (KeyValuePair pair in sb) { i++; WriteLine("[" + i + "] " + pair.Key.NameTag + " with " + pair.Value.ToString() + " points."); } - - } static void MainMenu(Game game) diff --git a/Qwirkle/TestBase/TestBoard.cs b/Qwirkle/TestBase/TestBoard.cs index 2ad505c..8b524ba 100644 --- a/Qwirkle/TestBase/TestBoard.cs +++ b/Qwirkle/TestBase/TestBoard.cs @@ -1,4 +1,5 @@ -using QwirkleClassLibrary; +using QwirkleClassLibrary.Boards; +using QwirkleClassLibrary.Tiles; using System.Collections.ObjectModel; namespace TestBase; diff --git a/Qwirkle/TestBase/TestCell.cs b/Qwirkle/TestBase/TestCell.cs index 091a5f2..72588bd 100644 --- a/Qwirkle/TestBase/TestCell.cs +++ b/Qwirkle/TestBase/TestCell.cs @@ -1,4 +1,5 @@ -using QwirkleClassLibrary; +using QwirkleClassLibrary.Boards; +using QwirkleClassLibrary.Tiles; namespace TestBase; public class TestCell diff --git a/Qwirkle/TestBase/TestGame.cs b/Qwirkle/TestBase/TestGame.cs index 121e8de..63bfa66 100644 --- a/Qwirkle/TestBase/TestGame.cs +++ b/Qwirkle/TestBase/TestGame.cs @@ -1,4 +1,5 @@ -using QwirkleClassLibrary; +using QwirkleClassLibrary.Games; +using QwirkleClassLibrary.Players; namespace TestBase; public class TestGame diff --git a/Qwirkle/TestBase/TestPlayer.cs b/Qwirkle/TestBase/TestPlayer.cs index 37b92e5..2e8df05 100644 --- a/Qwirkle/TestBase/TestPlayer.cs +++ b/Qwirkle/TestBase/TestPlayer.cs @@ -1,4 +1,5 @@ -using QwirkleClassLibrary; +using QwirkleClassLibrary.Players; +using QwirkleClassLibrary.Tiles; namespace TestBase; public class TestPlayers diff --git a/Qwirkle/TestBase/TestScore.cs b/Qwirkle/TestBase/TestScore.cs index ea8efd2..b8a357d 100644 --- a/Qwirkle/TestBase/TestScore.cs +++ b/Qwirkle/TestBase/TestScore.cs @@ -1,4 +1,4 @@ -using QwirkleClassLibrary; +using QwirkleClassLibrary.Players; namespace TestBase; public class TestScore diff --git a/Qwirkle/TestBase/TestTile.cs b/Qwirkle/TestBase/TestTile.cs index 0e98a62..9943cac 100644 --- a/Qwirkle/TestBase/TestTile.cs +++ b/Qwirkle/TestBase/TestTile.cs @@ -1,4 +1,4 @@ -using QwirkleClassLibrary; +using QwirkleClassLibrary.Tiles; using System; using System.Collections.Generic; using System.Linq; @@ -7,7 +7,7 @@ using System.Threading.Tasks; namespace TestBase { - public class TestTile + public class TestTile { [Fact] public void TestCreateCorrect() diff --git a/Qwirkle/TestBase/TestTileBag.cs b/Qwirkle/TestBase/TestTileBag.cs index e6556bf..d1e9ce2 100644 --- a/Qwirkle/TestBase/TestTileBag.cs +++ b/Qwirkle/TestBase/TestTileBag.cs @@ -1,4 +1,4 @@ -using QwirkleClassLibrary; +using QwirkleClassLibrary.Tiles; namespace TestBase; public class TestTileBag