Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Doc waiting list game list #25

Merged
merged 3 commits into from
Nov 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 39 additions & 1 deletion src/Library/GameList.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,48 @@
namespace Library;

/// <summary>
/// Esta clase representa la lista de partidas en curso.
/// </summary>
public class GameList
{
/// <summary>
/// Obtiene la lista de partidas.
/// </summary>
private List<Game> Games { get; set; } = new List<Game>();

/// <summary>
/// Agrega una partida a la lista de partidas.
/// </summary>
/// <param name="player1"></param>
/// <param name="player2"></param>
/// <returns>La partida agregada.</returns>
public Game AddGame(Player player1, Player player2)
{
Game game = new Game(player1, player2);
this.Games.Add(game);
return game;
}
/// <summary>
/// Elimina una partida de la lista de partidas.
/// </summary>
/// <param name="game"></param>
/// <returns>
/// <c>true</c> si la partida fue eliminada. <c>false</c> si no encontró la partida.
/// </returns>
public bool RemoveGame(Game game)
{
if (this.Games.Remove(game))
return true;
return false;
}

/// <summary>
/// Devuelve un jugador buscandolo por su nombre
/// </summary>
/// <param name="playerName"></param>
/// <returns>
/// <c>null</c> si el jugador no está en ninguna partida.
/// </returns>
public Player? FindPlayerByName(string playerName)

Check warning on line 45 in src/Library/GameList.cs

View workflow job for this annotation

GitHub Actions / build-test-generate-docs

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
foreach (Game game in this.Games)
foreach (Player player in game.GetPlayers())
Expand All @@ -20,7 +51,14 @@
return null;
}

/// <summary>
/// Devuelve la partida en la que se encuentra un jugador.
/// </summary>
/// <param name="player"></param>
/// <returns>
/// <c>null</c> si el jugador no está en ninguna partida.
/// </returns>
public Game? FindGameByPlayer(Player player)

Check warning on line 61 in src/Library/GameList.cs

View workflow job for this annotation

GitHub Actions / build-test-generate-docs

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
foreach (Game game in this.Games)
if (game.GetPlayers().Contains(player))
Expand Down
38 changes: 36 additions & 2 deletions src/Library/WaitingList.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,31 @@
namespace Library;

/// <summary>
/// Esta clase representa la lista de espera.
/// </summary>
public class WaitingList
{
/// <summary>
/// Obtiene la lista de jugadores en espera.
/// </summary>

private List<Player> Players { get; set; }= new List<Player>();

/// <summary>
/// Devuelve el número de jugadores en espera.
/// </summary>
public int Count
{
get { return this.Players.Count; }
}

/// <summary>
/// Agrega un jugador a la lista de espera.
/// </summary>
/// <param name="playerName"></param>
/// <returns>
///<c>true</c> si el jugador fue agregado. <c>false</c> si ya estaba esperando.
/// </returns>
/// <exception cref="ArgumentException"></exception>
public bool AddPlayer(string playerName)
{
if (string.IsNullOrEmpty(playerName))
Expand All @@ -18,17 +35,31 @@
this.Players.Add(new Player(playerName));
return true;
}


/// <summary>
/// Elimina un jugador de la lista de espera.
/// </summary>
/// <param name="playerName"></param>
/// <returns>
///<c>true</c> si el jugador fue eliminado. <c>false</c> si no estaba esperando.
/// </returns>
public bool RemovePlayer(string playerName)
{
Player? player = FindPlayerByName(playerName);

Check warning on line 48 in src/Library/WaitingList.cs

View workflow job for this annotation

GitHub Actions / build-test-generate-docs

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
if (player == null)
return false;
this.Players.Remove(player);
return true;
}

/// <summary>
/// Devuelve un jugador de la lista de espera buscandolo por su nombre.
/// </summary>
/// <param name="playerName"></param>
/// <returns>
/// <c>null</c> si el jugador no está esperando.
/// </returns>
public Player? FindPlayerByName(string playerName)

Check warning on line 62 in src/Library/WaitingList.cs

View workflow job for this annotation

GitHub Actions / build-test-generate-docs

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
foreach (Player player in this.Players)
if (player.Name == playerName)
Expand All @@ -36,7 +67,10 @@
return null;
}

/// <summary>
/// Devuelve un jugador al azar de la lista de espera.
/// </summary>
public Player? GetAnyoneWaiting()

Check warning on line 73 in src/Library/WaitingList.cs

View workflow job for this annotation

GitHub Actions / build-test-generate-docs

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
Random random = new Random();
int randomNumber = random.Next(0, this.Count);
Expand Down
Loading