diff --git a/Qwirkle/QwirkleClassLibrary/Games/Game.cs b/Qwirkle/QwirkleClassLibrary/Games/Game.cs
index e622436..a3e2711 100644
--- a/Qwirkle/QwirkleClassLibrary/Games/Game.cs
+++ b/Qwirkle/QwirkleClassLibrary/Games/Game.cs
@@ -51,13 +51,20 @@ namespace QwirkleClassLibrary.Games
protected virtual void OnEndOfGame(EndOfGameNotifiedEventArgs args)
=> EndOfGameNotified?.Invoke(this, args);
+ ///
+ /// Creates a game with a board and a tile bag
+ ///
public Game()
{
bag = CreateTileBag(3);
board = CreateBoard();
-
}
-
+
+ ///
+ /// Adds a player in the game if the game is not running, if the name is correct, if the game is not full and if the name is not already taken.
+ ///
+ ///
+ /// boolean to check it
public bool AddPlayerInGame(string? playerTag)
{
if (string.IsNullOrWhiteSpace(playerTag))
@@ -96,6 +103,11 @@ namespace QwirkleClassLibrary.Games
return true;
}
+ ///
+ /// Creates a player with a name
+ ///
+ ///
+ /// Player
public Player CreatePlayer(string playerTag)
{
var player = new Player(playerTag);
@@ -103,36 +115,64 @@ namespace QwirkleClassLibrary.Games
return player;
}
+ ///
+ /// Returns the board of the game
+ ///
+ /// Board
public Board GetBoard() { return board; }
+ ///
+ /// Creates a board with a number of columns and rows
+ ///
+ /// Board
public Board CreateBoard()
{
board = new Board(15, 12);
return board;
}
+ ///
+ /// Creates a bag of tiles with a number of sets of 36 tiles
+ ///
+ ///
+ /// TileBag
public TileBag CreateTileBag(int nbSet)
{
bag = new TileBag(nbSet);
return bag;
}
+ ///
+ /// Starts the game if there are at least 2 players and at most 4 players
+ ///
public void StartGame()
{
if (players.Count < 2 || players.Count >= 5) return;
GameRunning = true;
}
+ ///
+ /// Adds a cell to the list of cells used by the player in his turn if the cell is not null
+ ///
+ ///
public void AddCellUsed(Cell? c)
{
if (c != null) cellUsed.Add(c);
}
+ ///
+ /// Empty the list of cells used by the player at the end of his turn
+ ///
public void EmptyCellUsed()
{
cellUsed.Clear();
}
+ ///
+ /// Gets the player who is currently playing
+ ///
+ /// Player
+ ///
public Player GetPlayingPlayer()
{
if (GetPlayingPlayerPosition() == -1)
@@ -142,6 +182,10 @@ namespace QwirkleClassLibrary.Games
return players[GetPlayingPlayerPosition()];
}
+ ///
+ /// Gets the position of the player who is currently playing
+ ///
+ /// int
public int GetPlayingPlayerPosition()
{
for (int i = 0; i < players.Count; i++)
@@ -154,11 +198,19 @@ namespace QwirkleClassLibrary.Games
return -1;
}
+ ///
+ /// Returns the tile of the player who is currently playing at the position postile
+ ///
+ ///
+ /// Tile
public Tile TileOfPlayerWithPos(int postile)
{
return players[GetPlayingPlayerPosition()].Tiles[postile];
}
+ ///
+ /// Gives random picked tiles to the players at the beginning of the game
+ ///
public void GiveTilesToPlayers()
{
foreach (var p in players)
@@ -173,6 +225,11 @@ namespace QwirkleClassLibrary.Games
}
}
+ ///
+ /// Sets the first player of the game at the beginning of the game
+ ///
+ /// string
+ ///
public string SetFirstPlayer()
{
if (GameRunning)
@@ -181,13 +238,13 @@ namespace QwirkleClassLibrary.Games
OnNextPlayer(new NextPlayerNotifiedEventArgs(players[0]));
return players[0].NameTag;
}
- else
- {
throw new ArgumentException("Game is not running");
- }
-
}
+ ///
+ /// Sets the next player of the game. If there's no current player, it sets the first player
+ ///
+ ///
public string SetNextPlayer()
{
int i = GetPlayingPlayerPosition();
@@ -204,6 +261,14 @@ namespace QwirkleClassLibrary.Games
return players[GetPlayingPlayerPosition()].NameTag;
}
+ ///
+ /// Allows the player to place a tile on the board at a (x, y) position
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// bool
public bool PlaceTile(Player player, Tile tile, int x, int y)
{
if (!IsMoveCorrect(tile, x, y, board)) return false;
@@ -242,6 +307,12 @@ namespace QwirkleClassLibrary.Games
return true;
}
+ ///
+ /// Allows a player to swap some of his tile with the ones in the bag if he can't play them
+ ///
+ ///
+ ///
+ /// bool
public bool SwapTiles(Player player, List tilesToSwap)
{
if (tilesToSwap.Count == 0)
@@ -270,6 +341,16 @@ namespace QwirkleClassLibrary.Games
return true;
}
+ ///
+ /// Extension of IsMoveCorrect to check beyond the surrounding cells of the cell where the tile is placed
+ ///
+ ///
+ ///
+ ///
+ /// used to get the direction on the x axis
+ /// used to get the direction on the y axis
+ ///
+ /// bool
public bool CheckExtendedSurroundingCells(Tile tile, int x, int y, int dx, int dy, Board b)
{
for (int i = 1; i < 7; i++)
@@ -302,7 +383,15 @@ namespace QwirkleClassLibrary.Games
return true;
}
-
+
+ ///
+ /// Extension of IsMoveCorrect to check if the tiles are on the same line
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// bool
public bool CheckTilesInLine(List cells, Board b, int x, int y)
{
if (cells.Count == 0)
@@ -338,6 +427,14 @@ namespace QwirkleClassLibrary.Games
return false;
}
+ ///
+ /// Main method to check if the move the player is trying to make is correct
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// bool
public bool IsMoveCorrect(Tile t, int x, int y, Board b)
{
if (!b.HasOccupiedCase())
@@ -398,8 +495,14 @@ namespace QwirkleClassLibrary.Games
return true;
}
-
-
+
+ ///
+ /// Main method to get the score of the player after he played his turn
+ ///
+ ///
+ ///
+ ///
+ /// int
public int GetPlayerScore(Player player, ReadOnlyCollection cellsPlayed, Board b)
{
if (cellsPlayed.Count == 0)
@@ -441,6 +544,15 @@ namespace QwirkleClassLibrary.Games
return score;
}
+ ///
+ /// Extension of GetPlayerScore to calculate the score of the player based on the adjacent cells
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// int
public int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection cellsPlayed, int cellsX, int cellsY)
{
int score = 0;
@@ -469,6 +581,17 @@ namespace QwirkleClassLibrary.Games
return score;
}
+ ///
+ /// Extension of GetPlayerScore to calculate the score of the player based on the line/column of the adjacent cells
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ ///
+ /// int
public int CalculateLineScore(Cell cell, int dx, int dy, Board b, int cellsX, int cellsY, int nbCellsPlayed)
{
int score = 0;
@@ -499,6 +622,10 @@ namespace QwirkleClassLibrary.Games
}
+ ///
+ /// Returns the list of the positions of the players who still have tiles in their bag
+ ///
+ /// List
public List CheckTilesBag()
{
List playerTilesBagPos = [];
@@ -518,6 +645,11 @@ namespace QwirkleClassLibrary.Games
return playerTilesBagPos;
}
+ ///
+ /// Returns a boolean to check if the player can play a tile on the board
+ ///
+ ///
+ ///
public bool CheckBoardTile(List playerTilesBagPos)
{
for (int i = 0; i < playerTilesBagPos.Count; i++)
@@ -541,6 +673,11 @@ namespace QwirkleClassLibrary.Games
}
+ ///
+ /// Main method to check if the game is over
+ ///
+ ///
+ ///
public bool CheckGameOver(Player player)
{
List playerTilesBagPos = CheckTilesBag();
diff --git a/Qwirkle/QwirkleClassLibrary/Players/Leaderboard.cs b/Qwirkle/QwirkleClassLibrary/Players/Leaderboard.cs
index 4cd16db..2971291 100644
--- a/Qwirkle/QwirkleClassLibrary/Players/Leaderboard.cs
+++ b/Qwirkle/QwirkleClassLibrary/Players/Leaderboard.cs
@@ -13,6 +13,12 @@ namespace QwirkleClassLibrary.Players
public ReadOnlyCollection Lb => leaderboard.AsReadOnly();
private readonly List leaderboard = new();
+
+ ///
+ /// Returns the index of the player in the leaderboard, -1 if the player is not in the leaderboard
+ ///
+ ///
+ /// int
public int IsPlayerIn(Player player)
{
for (int i = 0; i < leaderboard.Count; i++)
@@ -25,6 +31,10 @@ namespace QwirkleClassLibrary.Players
return -1;
}
+ ///
+ /// Adds the score of the players in the leaderboard with the date of the day and the number of victories
+ ///
+ ///
public void AddScoreInLead(ReadOnlyDictionary scoreBoard)
{
DateTime now = DateTime.Today;
diff --git a/Qwirkle/QwirkleClassLibrary/Players/Player.cs b/Qwirkle/QwirkleClassLibrary/Players/Player.cs
index fe3530e..2c7411b 100644
--- a/Qwirkle/QwirkleClassLibrary/Players/Player.cs
+++ b/Qwirkle/QwirkleClassLibrary/Players/Player.cs
@@ -13,6 +13,11 @@ namespace QwirkleClassLibrary.Players
public ReadOnlyCollection Tiles => playerTiles.AsReadOnly();
private readonly List playerTiles = new();
+ ///
+ /// Creates a player with a name
+ ///
+ ///
+ ///
public Player(string name)
{
if (name == null || string.IsNullOrEmpty(name))
@@ -26,12 +31,21 @@ namespace QwirkleClassLibrary.Players
public string NameTag { get; }
public bool IsPlaying { get; set; } = false;
-
+
+ ///
+ /// Adds a tile to the player's hand
+ ///
+ ///
public void AddTileToPlayer(Tile tile)
{
playerTiles.Add(tile);
}
+ ///
+ /// Removes a tile from the player's hand
+ ///
+ ///
+ /// bool
public bool RemoveTileToPlayer(Tile tile)
{
return playerTiles.Remove(tile);
diff --git a/Qwirkle/QwirkleClassLibrary/Players/Score.cs b/Qwirkle/QwirkleClassLibrary/Players/Score.cs
index dc10780..cb02b98 100644
--- a/Qwirkle/QwirkleClassLibrary/Players/Score.cs
+++ b/Qwirkle/QwirkleClassLibrary/Players/Score.cs
@@ -15,14 +15,25 @@ namespace QwirkleClassLibrary.Players
public int Points { get; set; }
public int Victories { get; set; }
+ ///
+ /// Creates a score with the player's name, the date of the score, the number of points and the number of victories
+ ///
+ ///
+ ///
+ ///
+ ///
public Score(string playerName, DateTime date, int points, int victories)
{
- this.PlayerName = playerName;
- this.Date = date;
- this.Points = points;
- this.Victories = victories;
+ PlayerName = playerName;
+ Date = date;
+ Points = points;
+ Victories = victories;
}
+ ///
+ /// Overrides the ToString method to display the player's name, the date of the score, the number of points and the number of victories
+ ///
+ /// string
public override string ToString()
{
return PlayerName + " / " + Date.ToString() + " / " + Points + " / " + Victories;
| | |