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

Proco #9

Merged
merged 15 commits into from
Nov 7, 2024
522 changes: 0 additions & 522 deletions src/Library/Domain/Domain/Facade.cs

This file was deleted.

521 changes: 521 additions & 0 deletions src/Library/Domain/Facade.cs

Large diffs are not rendered by default.

38 changes: 19 additions & 19 deletions src/Library/Domain/Domain/Game.cs → src/Library/Domain/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,19 @@ public class Game
/// para controlar el flujo del juego.
/// </summary>
public Player Player2 { get; }

/// <summary>
/// Instancia de la clase Turn para gestionar el turno actual del juego.
/// </summary>
public Turn Turn { get; set; }

/// <summary>
/// Propiedad que indica el jugador que actualmente tiene el turno.
/// </summary>
public Player TurnPlayer
{
get
{
return Turn.CurrentPlayer;
}
set
{

}
get { return Turn.CurrentPlayer; }
set { return; }
}

/// <summary>
Expand All @@ -56,15 +50,22 @@ public Player TurnPlayer
/// </summary>
/// <param name="player1">El primer jugador.</param>
/// <param name="player2">El segundo jugador.</param>

public Game(Player player1, Player player2)
{
Player1 = player1;
Player2 = player2;
Turn = new Turn(player1, player2);
TurnPlayer = player1; // El jugador 1 comienza con el turno
PlayIsOn = true; // El juego inicia en estado activo
PlayIsOn = true; // El juego inicia en estado activo

// Establecer los oponentes
Player1.SetOpponent(Player2);
Player2.SetOpponent(Player1);
}



/// <summary>
/// Verifica si el juego debe terminar revisando si todos los Pokémon de alguno de los jugadores tienen 0 puntos de vida.
/// Si un jugador pierde todos sus Pokémon, el juego termina y se declara un ganador.
Expand All @@ -74,6 +75,7 @@ public Game(Player player1, Player player2)
public void CheckIfGameEnds()
{
// Verificamos si todos los Pokémon del jugador 1 tienen 0 puntos de vida
Player opponent = TurnPlayer.GetOpponent();
bool todosSonCeroPlayer1 = true; // = Player1.AvailablePokemons.All(pokemon => pokemon.HealthPoints == 0);
foreach (Pokemon pokemon in Player1.AvailablePokemons)
{
Expand All @@ -82,8 +84,8 @@ public void CheckIfGameEnds()
todosSonCeroPlayer1 = false;
}
}


// Verificamos si todos los Pokémon del jugador 2 tienen 0 puntos de vida
bool todosSonCeroPlayer2 = true; // Player2.AvailablePokemons.All(pokemon => pokemon.HealthPoints == 0);
foreach (Pokemon pokemon in Player2.AvailablePokemons)
Expand All @@ -93,19 +95,17 @@ public void CheckIfGameEnds()
todosSonCeroPlayer2 = false;
}
}

// Si todos los Pokémon de Player 1 tienen 0 puntos de vida, Player 2 gana
if (todosSonCeroPlayer1)
{
Console.WriteLine("¡Ha ganado Player 2!");
PlayIsOn = false; // El juego termina
PlayIsOn = false; // El juego termina
}
// Si todos los Pokémon de Player 2 tienen 0 puntos de vida, Player 1 gana
else if (todosSonCeroPlayer2)
{
Console.WriteLine("¡Ha ganado Player 1!");
PlayIsOn = false; // El juego termina
PlayIsOn = false; // El juego termina
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public Player FindPlayerByDisplayName(string displayName)
}
return null;
}
public Player FindOpponent(string playerDisplayName)
public Player FindOpponentOfDisplayName(string playerDisplayName)
{
foreach (var game in games)
{
Expand All @@ -60,11 +60,12 @@ public Player FindOpponent(string playerDisplayName)
}
return null;
}
public Game FindGameByPlayerDisplayName(string displayName)

public Game FindGameByPlayerDisplayName(string playerDisplayName)
{
foreach (var game in games)
foreach ( Game game in games)
{
if (game.Player1.DisplayName == displayName || game.Player2.DisplayName == displayName)
if (game.Player1.DisplayName == playerDisplayName || game.Player2.DisplayName == playerDisplayName)
{
return game;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,43 @@ public Player(string displayName)
this.items.Add(new CuraTotal());

}

/// <summary>
/// Obtiene la lista de Pokémon disponibles para el jugador.
/// Lista de Pokémon disponibles para el jugador.
/// </summary>
public List<Pokemon> AvailablePokemons { get; } = new List<Pokemon>();

/// <summary>
/// Obtiene el Pokémon actualmente activo del jugador.
/// El Pokémon activo del jugador.
/// </summary>
public Pokemon ActivePokemon { get; private set; }

/// <summary>
/// Obtiene el movimiento actualmente activo del Pokémon del jugador.
/// El movimiento actualmente activo del Pokémon del jugador.
/// </summary>
public Move ActiveMove { get; private set; }

// Referencia al oponente de este jugador.
private Player _opponent;

/// <summary>
/// Establece al oponente del jugador.
/// </summary>
/// <param name="opponent">El jugador que será el oponente.</param>
public void SetOpponent(Player opponent)
{
_opponent = opponent;
}

/// <summary>
/// Obtiene el oponente del jugador.
/// </summary>
public Player GetOpponent()
{
return _opponent;
}


/// <summary>
/// Agrega un Pokémon a la lista de Pokémon disponibles para el jugador.
/// </summary>
Expand Down
114 changes: 114 additions & 0 deletions src/Library/Domain/Pokemon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
// namespace ClassLibrary;
//
// /// <summary>
// /// La clase <c>Pokemon</c> es responsable de encapsular los atributos y comportamientos específicos de un Pokémon.
// /// Aplica el principio de responsabilidad única (SRP) al gestionar exclusivamente los datos y comportamientos de
// /// cada Pokémon. Utiliza el patrón Expert, ya que posee toda la información necesaria para administrar sus atributos,
// /// como puntos de vida y movimientos. Además facilita la extensión de la clase para añadir nuevas categorías de Pokémon
// /// o habilidades sin modificar la clase base, alineándose con el principio abierto/cerrado (OCP) y promoviendo una alta cohesión.
// /// Además la robustez y seguridad de esta clase se asegura al evitar estados inválidos y facilitar la detección de errores
// /// en el uso de la clase
// /// </summary>
// public class Pokemon
// {
// private string _name;
// private int _healthPoints;
// private Move _specialMove;
// private const int MaxMoves = 4;
// private List<Move> _moves;
//
// /// <summary>
// /// Obtiene o establece el nombre del Pokémon.
// /// </summary>
// /// <exception cref="ArgumentNullException">Se lanza si el nombre es nulo o vacío.</exception>
// public string Name
// {
// get => _name;
// set
// {
// if (string.IsNullOrEmpty(value))
// throw new ArgumentNullException(nameof(Name), "El nombre del Pokémon no puede ser nulo o vacío.");
// _name = value;
// }
// }
//
// public Move GetMoveByName(string moveName)
// {
// Move move = this.Moves.FirstOrDefault(m => m.Name.Equals(moveName, StringComparison.OrdinalIgnoreCase));
//
// // Si no lo encontramos, verificamos si es el movimiento especial
// if (move == null && this.SpecialMove.Name.Equals(moveName, StringComparison.OrdinalIgnoreCase))
// {
// move = this.SpecialMove;
// }
//
// // Si no encontramos el movimiento, lanzamos una excepción
// if (move == null)
// {
// throw new Exception(
// $"El movimiento {moveName} no se encuentra en los movimientos del Pokémon {this.Name}.");
// }
//
// return move;
// }
//
// /// <summary>
// /// Obtiene o establece los puntos de salud del Pokémon.
// /// </summary>
// /// <exception cref="ArgumentOutOfRangeException">Se lanza si los puntos de salud son negativos.</exception>
// public int HealthPoints
// {
// get => _healthPoints;
// set
// {
// if (value < 0)
// throw new ArgumentOutOfRangeException(nameof(HealthPoints),
// "Los puntos de salud no pueden ser negativos.");
// _healthPoints = value;
// }
// }
//
// /// <summary>
// /// Obtiene o establece el movimiento especial del Pokémon.
// /// </summary>
// /// <exception cref="ArgumentNullException">Se lanza si el movimiento especial es nulo.</exception>
// public Move SpecialMove
// {
// get => _specialMove;
//
// set
// {
// if (value == null)
// throw new ArgumentNullException(nameof(SpecialMove), "El movimiento especial no puede ser nulo.");
// _specialMove = value;
// }
// }
//
// /// <summary>
// /// Obtiene o establece el tipo del Pokémon.
// /// </summary>
// public PokemonType.Type Type { get; set; }
//
// /// <summary>
// /// Obtiene o establece la lista de movimientos regulares del Pokémon.
// /// </summary>
// public List<Move> Moves
// {
// get => _moves ??= new List<Move>(); // Inicializa la lista si es nula.
// set
// {
// if (value != null && value.Count > MaxMoves)
// throw new InvalidOperationException($"No se pueden agregar más de {MaxMoves} movimientos.");
//
// _moves = value;
// }
// }
//
// /// <summary>
// /// Inicializa una nueva instancia de la clase <see cref="Pokemon"/> con una lista de movimientos vacía.
// /// </summary>
// public Pokemon()
// {
// Moves = new List<Move>();
// }
// }
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public void PenalizeTurn(Player player)
// PenalizedPlayer = CurrentPlayer; // Descomentado si se necesita usar
ChangeTurn();
}
else
else if (WaitingPlayer == player)
{
Console.WriteLine($"{player.DisplayName} is not currently playing.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,21 @@
}
return result.ToString();
}

public string AddPlayerToWaitingList(string displayName)
{
if (displayName == displayName)

Check warning on line 146 in src/Library/Domain/UserInterface.cs

View workflow job for this annotation

GitHub Actions / build-test-generate-docs

Comparison made to same variable; did you mean to compare something else?

Check warning on line 146 in src/Library/Domain/UserInterface.cs

View workflow job for this annotation

GitHub Actions / build-test-generate-docs

Comparison made to same variable; did you mean to compare something else?
{
return $"{displayName} ya está en la lista de espera";
}
return displayName;
}

public static string ShowBattleEndMessage(string playerName)
{
return $"{playerName} ha ganado la batalla";
}

public static string ShowMessageCurrentTurnPlayer(string currentPlayerDisplayName)
{
return $"🎮 Es el turno de {currentPlayerDisplayName}.";
Expand Down Expand Up @@ -177,7 +192,5 @@
{
return $"$ La efectividad del ataque es baja: {accuaracyAttack} ";
}


}
}
Loading
Loading