more and more documentation, again
continuous-integration/drone/push Build is passing Details

master
rportet 11 months ago
parent ffbd8aba48
commit d24b19e757

@ -60,9 +60,9 @@ namespace QwirkleClassLibrary.Boards
}
/// <summary>
/// This method is used to check if a cell in the board whether it already contains a tile or not.
/// This method is used to check if a cell in the board whether already contains a tile or not.
/// </summary>
/// <returns>Returns a boolean : true if the cell doesn't contain any tile, false if it already contains a tile.</returns>
/// <returns>Returns a boolean : true if the cell doesn't contain any tile, false if already contains a tile.</returns>
public bool HasOccupiedCase()
{
foreach (var cell in cells)

@ -4,92 +4,94 @@ using System.Runtime.CompilerServices;
using System.Runtime.Serialization;
using QwirkleClassLibrary.Tiles;
namespace QwirkleClassLibrary.Boards;
/// <summary>
/// Our board is made with a list of this class. It can stock infos such as its position on the board and the tile it contains.
/// </summary>
[DataContract]
public class Cell : INotifyPropertyChanged
namespace QwirkleClassLibrary.Boards
{
public event PropertyChangedEventHandler? PropertyChanged;
[DataMember]
private readonly int x;
[DataMember]
private readonly int y;
[DataMember]
public Tile? Tile { get; private set;}
/// <summary>
/// This is the constructor for a Cell.
/// Our board is made with a list of this class. It can stock infos such as its position on the board and the tile it contains.
/// </summary>
/// <param name="x">The x attribute of the cell.</param>
/// <param name="y">The y attribute of the cell.</param>
/// <exception cref="ArgumentException">Throw an exception if the x or y attribute is negative.</exception>
public Cell(int x, int y)
[DataContract]
public class Cell : INotifyPropertyChanged
{
if (x < 0 || y < 0)
{
throw new ArgumentException(x.ToString() + y.ToString());
}
public event PropertyChangedEventHandler? PropertyChanged;
this.x = x;
this.y = y;
}
[DataMember]
private readonly int x;
/// <summary>
/// A getter for the position of the cell on the x-axis.
/// </summary>
/// <returns>The position of the cell on the x-axis.</returns>
public int GetX
{
get { return x; }
}
[DataMember]
private readonly int y;
/// <summary>
/// A getter for the position of the cell on the y-axis.
/// </summary>
/// <returns>The position of the cell on the y-axis.</returns>
public int GetY
{
get { return y; }
}
[DataMember]
public Tile? Tile { get; private set; }
/// <summary>
/// Check if the Cell whether is empty or contains a tile.
/// </summary>
/// <returns>True if the cell is empty, false if the cell contains a tile.</returns>
public bool IsFree
{
get { return Tile! == null!; }
}
/// <summary>
/// This is the constructor for a Cell.
/// </summary>
/// <param name="x">The x attribute of the cell.</param>
/// <param name="y">The y attribute of the cell.</param>
/// <exception cref="ArgumentException">Throw an exception if the x or y attribute is negative.</exception>
public Cell(int x, int y)
{
if (x < 0 || y < 0)
{
throw new ArgumentException(x.ToString() + y.ToString());
}
this.x = x;
this.y = y;
}
/// <summary>
/// A setter for the tile in the cell.
/// </summary>
/// <param name="addedTile">The tile the player want to add in the cell.</param>
/// <returns>True if added succefully (if the cell didn't already contain a tile), false if there already was a tile in this cell.</returns>
public bool SetTile(Tile addedTile)
{
if (Tile! == null!)
/// <summary>
/// A getter for the position of the cell on the x-axis.
/// </summary>
/// <returns>The position of the cell on the x-axis.</returns>
public int GetX
{
get { return x; }
}
/// <summary>
/// A getter for the position of the cell on the y-axis.
/// </summary>
/// <returns>The position of the cell on the y-axis.</returns>
public int GetY
{
get { return y; }
}
Tile = addedTile;
OnPropertyChanged(nameof(Tile));
return true;
/// <summary>
/// Checks if the Cell whether is empty or contains a tile.
/// </summary>
/// <returns>True if the cell is empty, false if the cell contains a tile.</returns>
public bool IsFree
{
get { return Tile! == null!; }
}
else
/// <summary>
/// A setter for the tile in the cell.
/// </summary>
/// <param name="addedTile">The tile the player want to add in the cell.</param>
/// <returns>True if added succefully (if the cell didn't already contain a tile), false if there already was a tile in this cell.</returns>
public bool SetTile(Tile addedTile)
{
return false;
if (Tile! == null!)
{
Tile = addedTile;
OnPropertyChanged(nameof(Tile));
return true;
}
else
{
return false;
}
}
}
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

@ -122,7 +122,12 @@ namespace QwirkleClassLibrary.Games
OnPlayerNotified(new AddPlayerNotifiedEventArgs("Players were correctly added."));
return true;
}
/// <summary>
/// This function is used to check if the player name that the user has entered meets the criteria set by the application.
/// </summary>
/// <param name="playersTag">A list that contains all the names entered when the game was started.</param>
/// <param name="pos">The position of the name we want to check in this list.</param>
/// <returns>boolean true if everything is okay, false if there was a problem in the player name.</returns>
public bool CheckPlayerTag(List<string> playersTag, int pos)
{
if (string.IsNullOrWhiteSpace(playersTag[pos]))

@ -3,30 +3,32 @@ using QwirkleClassLibrary.Boards;
using QwirkleClassLibrary.Players;
using QwirkleClassLibrary.Tiles;
namespace QwirkleClassLibrary.Games;
/// <summary>
/// This interface is used for all methods related to the player, such as the moves he can make.
/// </summary>
public interface IPlayer
namespace QwirkleClassLibrary.Games
{
public Player CreatePlayer(string playerTag);
public string SetNextPlayer();
/// <summary>
/// This interface is used for all methods related to the player, such as the moves he can make.
/// </summary>
public interface IPlayer
{
public Player CreatePlayer(string playerTag);
public string SetNextPlayer();
public string SetFirstPlayer(ReadOnlyCollection<Player> playingPlayers);
public string SetFirstPlayer(ReadOnlyCollection<Player> playingPlayers);
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);
int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection<Cell> cellsPlayed, Tuple<int, int> orientation,
ref int nbCellsInLine, ref int nbCellsInPerpLine, ref List<Cell> checkedCells);
int CalculateAdjacentScore(Cell cell, Board b, ReadOnlyCollection<Cell> cellsPlayed, Tuple<int, int> orientation,
ref int nbCellsInLine, ref int nbCellsInPerpLine, ref List<Cell> checkedCells);
int CalculateLineScore(ReadOnlyCollection<Cell> cellsPlayed, Cell cell, Tuple<int, int> direction,
Tuple<int, int> orientation, ref int nbCellsInLine, ref int nbCellsInPerpLine, ref List<Cell> checkedCells);
int CalculateLineScore(ReadOnlyCollection<Cell> cellsPlayed, Cell cell, Tuple<int, int> direction,
Tuple<int, int> orientation, ref int nbCellsInLine, ref int nbCellsInPerpLine, ref List<Cell> checkedCells);
}
}

@ -1,36 +1,47 @@
using System.Runtime.Serialization;
using QwirkleClassLibrary.Games;
namespace QwirkleClassLibrary.Persistences;
public class GamePersistenceXml : IGamePersistence
namespace QwirkleClassLibrary.Persistences
{
public void SaveGame(Game game)
/// <summary>
/// This class takes care of managing persistence with regard to the information of the current game, allowing the last game played to be resumed even when returning to the menu or exiting the application.
/// </summary>
public class GamePersistenceXml : IGamePersistence
{
var serializer = new DataContractSerializer(typeof(Game),
new DataContractSerializerSettings() { PreserveObjectReferences = true });
using (Stream writer = File.Create("Game.xml"))
/// <summary>
/// The main purpose of this method is to save the data from the game when the user quits the app, so players can continue it later.
/// </summary>
/// <param name="game"></param>
public void SaveGame(Game game)
{
serializer.WriteObject(writer, game);
}
}
var serializer = new DataContractSerializer(typeof(Game),
new DataContractSerializerSettings() { PreserveObjectReferences = true });
public Game LoadGame()
{
var serializer = new DataContractSerializer(typeof(Game));
try
{
using (Stream reader = File.OpenRead("Game.xml"))
using (Stream writer = File.Create("Game.xml"))
{
var newGame = serializer.ReadObject(reader) as Game;
return newGame!;
serializer.WriteObject(writer, game);
}
}
catch
/// <summary>
/// This method is used to retrieve the information needed to resume the last game launched on the application.
/// </summary>
/// <returns>A Game.</returns>
public Game LoadGame()
{
return new Game();
var serializer = new DataContractSerializer(typeof(Game));
try
{
using (Stream reader = File.OpenRead("Game.xml"))
{
var newGame = serializer.ReadObject(reader) as Game;
return newGame!;
}
}
catch
{
return new Game();
}
}
}
}

@ -1,27 +1,39 @@
using System.Runtime.Serialization.Json;
using QwirkleClassLibrary.Players;
namespace QwirkleClassLibrary.Persistences;
public class LeaderboardPersistenceJson : ILeaderboardPersistence
namespace QwirkleClassLibrary.Persistences
{
public void SaveLeaderboard(Leaderboard leaderboard)
/// <summary>
/// This is the persistence class for the leaderboard : it is in charge of managing all the parameters necessary for the backup and recovery of data concerning the leaderboard.
/// </summary>
public class LeaderboardPersistenceJson : ILeaderboardPersistence
{
var serializer = new DataContractJsonSerializer(typeof(Leaderboard));
using (Stream writer = File.Create("Leaderboard.json"))
/// <summary>
/// As the name suggest, this class is used to save the data from the leaderboard.
/// </summary>
/// <param name="leaderboard">The current leaderboard we want to save data from.</param>
public void SaveLeaderboard(Leaderboard leaderboard)
{
serializer.WriteObject(writer, leaderboard);
}
}
var serializer = new DataContractJsonSerializer(typeof(Leaderboard));
public Leaderboard LoadLeaderboard()
{
var serializer = new DataContractJsonSerializer(typeof(Leaderboard));
using (Stream reader = File.OpenRead("Leaderboard.json"))
using (Stream writer = File.Create("Leaderboard.json"))
{
serializer.WriteObject(writer, leaderboard);
}
}
/// <summary>
/// This method is used to load the leaderboard into the app when the application starts.
/// </summary>
/// <returns>Leaderboard</returns>
/// <exception cref="InvalidOperationException"></exception>
public Leaderboard LoadLeaderboard()
{
return serializer.ReadObject(reader) as Leaderboard ?? throw new InvalidOperationException();
var serializer = new DataContractJsonSerializer(typeof(Leaderboard));
using (Stream reader = File.OpenRead("Leaderboard.json"))
{
return serializer.ReadObject(reader) as Leaderboard ?? throw new InvalidOperationException();
}
}
}
}
Loading…
Cancel
Save