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.Text;
using System.Threading.Tasks;
using QwirkleClassLibrary.Tiles;
namespace QwirkleClassLibrary
namespace QwirkleClassLibrary.Boards
{
public class Board
{
public ReadOnlyCollection<Cell> ReadCells => cells.AsReadOnly();
private readonly List<Cell> 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];
}

@ -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;

@ -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)
{

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

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

@ -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; }

@ -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;
}

@ -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<Tile> tilesToSwap);
public int GetPlayerScore(Player player, ReadOnlyCollection<Cell> cellsPlayed, Board b);

@ -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<Cell> cells, Board b, int x, int y);
bool CheckGameOver(Player player);
}
}

@ -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<Tile> Tiles => playerTiles.AsReadOnly();
private readonly List<Tile> 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<Tile> Tiles => playerTiles.AsReadOnly();
private readonly List<Tile> 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);
}
}
}

@ -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;
}
}

@ -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
}
}

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

@ -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();
}
}
}

@ -5,11 +5,11 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace QwirkleClassLibrary
namespace QwirkleClassLibrary.Tiles
{
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>();
public TileBag(int nbSet)
@ -33,7 +33,7 @@ namespace QwirkleClassLibrary
TilesBag = tiles.AsReadOnly();
}
public bool AddTileInBag(Tile tile)
{
if (tile == null)

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

@ -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<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++;
WriteLine("[" + i + "] " + pair.Key.NameTag + " with " + pair.Value.ToString() + " points.");
}
}
static void MainMenu(Game game)

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

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

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

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

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

@ -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()

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

Loading…
Cancel
Save