hello everyone :)
continuous-integration/drone/push Build is passing Details

test_old_branch
Jérémy Mouyon 11 months ago
parent 54e6e2de6b
commit 6c2b4076f9

@ -5,14 +5,15 @@ using System.Linq;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using QwirkleClassLibrary.Tiles;
namespace QwirkleClassLibrary namespace QwirkleClassLibrary.Boards
{ {
public class Board public class Board
{ {
public ReadOnlyCollection<Cell> ReadCells => cells.AsReadOnly(); public ReadOnlyCollection<Cell> ReadCells => cells.AsReadOnly();
private readonly List<Cell> cells = new(); private readonly List<Cell> cells = new();
public int Rows { get; } public int Rows { get; }
public int Columns { get; } public int Columns { get; }
@ -20,7 +21,7 @@ namespace QwirkleClassLibrary
{ {
Rows = rows; Rows = rows;
Columns = cols; Columns = cols;
for (int a = 0; a < Rows; a++) for (int a = 0; a < Rows; a++)
{ {
for (int b = 0; b < Columns; b++) for (int b = 0; b < Columns; b++)
@ -47,7 +48,7 @@ namespace QwirkleClassLibrary
{ {
for (int i = 0; i < cells.Count; i++) 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) if (cells[i].IsFree)
{ {
return cells[i].SetTile(tile); return cells[i].SetTile(tile);
@ -65,12 +66,12 @@ namespace QwirkleClassLibrary
{ {
return ReadCells; return ReadCells;
} }
public Cell? GetCell(int x, int y) public Cell? GetCell(int x, int y)
{ {
for (int i = 0; i < cells.Count; i++) 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]; return cells[i];
} }

@ -1,7 +1,8 @@
// ReSharper disable All // ReSharper disable All
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
using QwirkleClassLibrary.Tiles;
namespace QwirkleClassLibrary; namespace QwirkleClassLibrary.Boards;
public class Cell public class Cell
{ {
@ -42,7 +43,7 @@ public class Cell
public bool SetTile(Tile addedTile) public bool SetTile(Tile addedTile)
{ {
if(this.tile == null) if (tile == null)
{ {
tile = addedTile; tile = addedTile;
return true; return true;

@ -1,8 +1,8 @@
namespace QwirkleClassLibrary namespace QwirkleClassLibrary.Events
{ {
public class AddPlayerNotifiedEventArgs : EventArgs public class AddPlayerNotifiedEventArgs : EventArgs
{ {
public string returnedNotified { get; private set; } public string returnedNotified { get; private set; }
public AddPlayerNotifiedEventArgs(string returnedNotified) public AddPlayerNotifiedEventArgs(string returnedNotified)
{ {

@ -1,4 +1,6 @@
namespace QwirkleClassLibrary using QwirkleClassLibrary.Players;
namespace QwirkleClassLibrary.Events
{ {
public class EndOfGameNotifiedEventArgs public class EndOfGameNotifiedEventArgs
{ {

@ -1,4 +1,6 @@
namespace QwirkleClassLibrary using QwirkleClassLibrary.Players;
namespace QwirkleClassLibrary.Events
{ {
public class NextPlayerNotifiedEventArgs : EventArgs public class NextPlayerNotifiedEventArgs : EventArgs
{ {

@ -1,8 +1,10 @@
namespace QwirkleClassLibrary using QwirkleClassLibrary.Tiles;
namespace QwirkleClassLibrary.Events
{ {
public class PlaceTileNotifiedEventArgs : EventArgs public class PlaceTileNotifiedEventArgs : EventArgs
{ {
public Tile tile { get; private set; } public Tile tile { get; private set; }
public string reason { get; private set; } public string reason { get; private set; }

@ -8,8 +8,12 @@ using System.Xml.Linq;
using System.Security.Cryptography; using System.Security.Cryptography;
using System.Collections; using System.Collections;
using System.Collections.Immutable; 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 public class Game : IPlayer, IRules
@ -62,7 +66,7 @@ namespace QwirkleClassLibrary
return false; return false;
} }
if (this.GameRunning) if (GameRunning)
{ {
OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR : The game is running.")); OnPlayerNotified(new AddPlayerNotifiedEventArgs("ERROR : The game is running."));
return false; return false;
@ -116,7 +120,7 @@ namespace QwirkleClassLibrary
public bool StartGame() public bool StartGame()
{ {
if (players.Count < 2 || players.Count >= 5) return false; if (players.Count < 2 || players.Count >= 5) return false;
this.GameRunning = true; GameRunning = true;
return true; return true;
} }
@ -487,14 +491,14 @@ namespace QwirkleClassLibrary
{ {
for (int i = 0; i < PlayerTilesBagPos.Count; i++) 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 x = board.ReadCells[b].GetX;
int y = this.board.ReadCells[b].GetY; 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; return true;
} }

@ -1,19 +1,22 @@
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using QwirkleClassLibrary.Boards;
using QwirkleClassLibrary.Players;
using QwirkleClassLibrary.Tiles;
namespace QwirkleClassLibrary; namespace QwirkleClassLibrary.Games;
public interface IPlayer public interface IPlayer
{ {
public Player CreatePlayer(string playerTag); public Player CreatePlayer(string playerTag);
public string SetNextPlayer(); public string SetNextPlayer();
public string SetFirstPlayer(); public string SetFirstPlayer();
public bool PlaceTile(Player player, Tile tile, int x, int y); public bool PlaceTile(Player player, Tile tile, int x, int y);
public bool DrawTiles(Player player); public bool DrawTiles(Player player);
public bool SwapTiles(Player player, List<Tile> tilesToSwap); public bool SwapTiles(Player player, List<Tile> tilesToSwap);
public int GetPlayerScore(Player player, ReadOnlyCollection<Cell> cellsPlayed, Board b); public int GetPlayerScore(Player player, ReadOnlyCollection<Cell> cellsPlayed, Board b);

@ -3,21 +3,24 @@ using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using QwirkleClassLibrary.Boards;
using QwirkleClassLibrary.Players;
using QwirkleClassLibrary.Tiles;
namespace QwirkleClassLibrary namespace QwirkleClassLibrary.Games
{ {
public interface IRules public interface IRules
{ {
Board CreateBoard(); Board CreateBoard();
TileBag CreateTileBag(int nbSet); TileBag CreateTileBag(int nbSet);
bool IsMoveCorrect(Tile t, int x, int y, Board b); 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 CheckExtendedSurroundingCells(Tile tile, int x, int y, int dx, int dy, Board b);
bool CheckTilesInLine(List<Cell> cells, Board b, int x, int y); bool CheckTilesInLine(List<Cell> cells, Board b, int x, int y);
bool CheckGameOver(Player player); bool CheckGameOver(Player player);
} }
} }

@ -1,39 +1,40 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using QwirkleClassLibrary.Tiles;
namespace QwirkleClassLibrary
{ namespace QwirkleClassLibrary.Players
public class Player {
{ public class Player
public ReadOnlyCollection<Tile> Tiles => playerTiles.AsReadOnly(); {
private readonly List<Tile> playerTiles = new(); public ReadOnlyCollection<Tile> Tiles => playerTiles.AsReadOnly();
private readonly List<Tile> playerTiles = new();
public Player(string name)
{ public Player(string name)
if(name == null || string.IsNullOrEmpty(name)) {
{ if (name == null || string.IsNullOrEmpty(name))
throw new ArgumentNullException(name); {
} throw new ArgumentNullException(name);
}
NameTag = name;
} NameTag = name;
}
public string NameTag { get; }
public string NameTag { get; }
public bool IsPlaying { get; set; } = false;
public bool IsPlaying { get; set; } = false;
public void AddTileToPlayer(Tile tile)
{ public void AddTileToPlayer(Tile tile)
playerTiles.Add(tile); {
} playerTiles.Add(tile);
}
public bool RemoveTileToPlayer(Tile tile)
{ public bool RemoveTileToPlayer(Tile tile)
return playerTiles.Remove(tile); {
} return playerTiles.Remove(tile);
} }
} }
}

@ -4,7 +4,7 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace QwirkleClassLibrary namespace QwirkleClassLibrary.Players
{ {
public struct Score public struct Score
{ {
@ -18,7 +18,8 @@ namespace QwirkleClassLibrary
throw new ArgumentNullException(nameof(p), "player cannot be null"); throw new ArgumentNullException(nameof(p), "player cannot be null");
} }
else else
{ PlayerScore = 0; {
PlayerScore = 0;
PlayerTag = p.NameTag; PlayerTag = p.NameTag;
} }
} }

@ -1,18 +1,18 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace QwirkleClassLibrary namespace QwirkleClassLibrary.Tiles
{ {
public enum Color public enum Color
{ {
Red, Red,
Blue, Blue,
Green, Green,
Yellow, Yellow,
Orange, Orange,
Purple Purple
} }
} }

@ -1,22 +1,22 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace QwirkleClassLibrary namespace QwirkleClassLibrary.Tiles
{ {
/// <summary> /// <summary>
/// Enum is used to have a finished number of shapes for the tiles. /// Enum is used to have a finished number of shapes for the tiles.
/// </summary> /// </summary>
public enum Shape public enum Shape
{ {
Square, Square,
Round, Round,
Rhombus, Rhombus,
Club, Club,
Shuriken, Shuriken,
Star Star
} }
} }

@ -1,42 +1,41 @@
using QwirkleClassLibrary; using System;
using System; using System.Collections.Generic;
using System.Collections.Generic; using System.Drawing;
using System.Drawing; using System.Linq;
using System.Linq; using System.Text;
using System.Text; using System.Threading.Tasks;
using System.Threading.Tasks;
namespace QwirkleClassLibrary.Tiles
namespace QwirkleClassLibrary {
{ public class Tile
public class Tile {
{ private readonly Shape shape;
private readonly Shape shape; private readonly Color color;
private readonly Color color;
public Tile(Shape sh, Color co)
public Tile(Shape sh, Color co) {
{ shape = sh;
shape = sh; color = co;
color = co; }
}
public string NameColorTile()
public string NameColorTile() {
{ return color.ToString() + shape.ToString();
return color.ToString() + shape.ToString(); }
}
public Shape GetShape
public Shape GetShape {
{ get { return shape; }
get { return this.shape; } }
}
public Color GetColor
public Color GetColor {
{ get { return color; }
get { return this.color; } }
}
public override string ToString()
public override string ToString() {
{ return color.ToString() + " " + shape.ToString();
return color.ToString() + shape.ToString(); }
} }
}
} }

@ -5,11 +5,11 @@ using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
namespace QwirkleClassLibrary namespace QwirkleClassLibrary.Tiles
{ {
public class TileBag public class TileBag
{ {
public ReadOnlyCollection<Tile> TilesBag { get ; private set; } public ReadOnlyCollection<Tile> TilesBag { get; private set; }
private readonly List<Tile> tiles = new List<Tile>(); private readonly List<Tile> tiles = new List<Tile>();
public TileBag(int nbSet) public TileBag(int nbSet)
@ -33,7 +33,7 @@ namespace QwirkleClassLibrary
TilesBag = tiles.AsReadOnly(); TilesBag = tiles.AsReadOnly();
} }
public bool AddTileInBag(Tile tile) public bool AddTileInBag(Tile tile)
{ {
if (tile == null) if (tile == null)

@ -1,4 +1,4 @@
using QwirkleClassLibrary; using QwirkleClassLibrary.Events;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;

@ -1,4 +1,7 @@
using QwirkleClassLibrary; using QwirkleClassLibrary.Boards;
using QwirkleClassLibrary.Games;
using QwirkleClassLibrary.Players;
using QwirkleClassLibrary.Tiles;
using QwirkleConsoleApp; using QwirkleConsoleApp;
using System.Collections.Immutable; using System.Collections.Immutable;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
@ -114,7 +117,8 @@ static void AddTile(Game game)
WriteLine("ERROR : You must type. Please retry : "); WriteLine("ERROR : You must type. Please retry : ");
ResetColor(); 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 : ---------------------"); WriteLine(" --------------------- THE SCORE BOARD : ---------------------");
int i = 0; int i = 0;
foreach (KeyValuePair<Player, int> pair in g.ScoreBoard)
var sb = g.ScoreBoard.OrderByDescending(x => x.Value).ThenBy(x => x.Key.NameTag);
foreach (KeyValuePair<Player, int> pair in sb)
{ {
i++; i++;
WriteLine("[" + i + "] " + pair.Key.NameTag + " with " + pair.Value.ToString() + " points."); WriteLine("[" + i + "] " + pair.Key.NameTag + " with " + pair.Value.ToString() + " points.");
} }
} }
static void MainMenu(Game game) static void MainMenu(Game game)

@ -1,4 +1,5 @@
using QwirkleClassLibrary; using QwirkleClassLibrary.Boards;
using QwirkleClassLibrary.Tiles;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
namespace TestBase; namespace TestBase;

@ -1,4 +1,5 @@
using QwirkleClassLibrary; using QwirkleClassLibrary.Boards;
using QwirkleClassLibrary.Tiles;
namespace TestBase; namespace TestBase;
public class TestCell public class TestCell

@ -1,4 +1,5 @@
using QwirkleClassLibrary; using QwirkleClassLibrary.Games;
using QwirkleClassLibrary.Players;
namespace TestBase; namespace TestBase;
public class TestGame public class TestGame

@ -1,4 +1,5 @@
using QwirkleClassLibrary; using QwirkleClassLibrary.Players;
using QwirkleClassLibrary.Tiles;
namespace TestBase; namespace TestBase;
public class TestPlayers public class TestPlayers

@ -1,4 +1,4 @@
using QwirkleClassLibrary; using QwirkleClassLibrary.Players;
namespace TestBase; namespace TestBase;
public class TestScore public class TestScore

@ -1,4 +1,4 @@
using QwirkleClassLibrary; using QwirkleClassLibrary.Tiles;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
@ -7,7 +7,7 @@ using System.Threading.Tasks;
namespace TestBase namespace TestBase
{ {
public class TestTile public class TestTile
{ {
[Fact] [Fact]
public void TestCreateCorrect() public void TestCreateCorrect()

@ -1,4 +1,4 @@
using QwirkleClassLibrary; using QwirkleClassLibrary.Tiles;
namespace TestBase; namespace TestBase;
public class TestTileBag public class TestTileBag

Loading…
Cancel
Save