Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianCuneo committed Nov 15, 2024
2 parents b550342 + 97b6f4d commit e6abb4a
Show file tree
Hide file tree
Showing 19 changed files with 508 additions and 378 deletions.
114 changes: 58 additions & 56 deletions src/Library/Domain/Domain/Facade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ private Facade()
this.GameList = new GameList();
this.UserInterface = new UserInterface();
}

/// <summary>
/// Obtiene la única instancia de la clase <see cref="Facade"/>.
/// </summary>
Expand All @@ -50,10 +50,10 @@ public static void Reset()
{
_instance = null;
}


//HISTORIA DE USUARIO 1

/// <summary>
/// Muestra el catálogo completo de Pokémon disponibles para seleccionar en la partida.
/// </summary>
Expand All @@ -62,7 +62,7 @@ public string ShowPokemonCatalog()
{
return UserInterface.ShowMessagePokemonCatalog();
}

/// <summary>
/// Permite a un jugador seleccionar hasta seis Pokémon para su equipo en la partida.
/// Verifica que el jugador esté activo y que no seleccione más de seis Pokémon. Luego,
Expand Down Expand Up @@ -96,7 +96,8 @@ public string ChoosePokemons(string playerDisplayName, string[] pokemonNames)
selectedPokemons.Add(pokemon);
}
else
{ ;
{
;
throw new Exception($"El pokemon {pokemonName} no esta en el catalogo");
}
}
Expand Down Expand Up @@ -130,7 +131,7 @@ public List<string> ShowMoves(string playerDisplayName)
{
movesList.Add(move.Name);
}

string pokemonMoves = $"{pokemon.Name}: {string.Join(", ", movesList)}";

pokemonsWithMoves.Add(pokemonMoves);
Expand Down Expand Up @@ -158,8 +159,9 @@ public void ChoosePokemonAndMoveToAttack(string playerDisplayName, string moveNa
{
throw new Exception($"El Pokémon {pokemonName} no está disponible para el jugador {playerDisplayName}");
}

player.ActivatePokemon(pokemonIndex);

int moveIndex = player.GetIndexOfMoveInActivePokemon(moveName);
if (moveIndex < 0)
{
Expand All @@ -182,9 +184,10 @@ public string GetPokemonsHealth(string playerDisplayName)
//Verifica que el parámetro playerDisplayName no sea Null ni este vacío
if (string.IsNullOrWhiteSpace(playerDisplayName))
{
throw new ArgumentNullException(nameof(playerDisplayName), "El nombre del jugador no puede ser nulo o estar vacío.");
throw new ArgumentNullException(nameof(playerDisplayName),
"El nombre del jugador no puede ser nulo o estar vacío.");
}

// Busca al jugador por su nombre para obtener sus Pokémon.
Player player = this.GameList.FindPlayerByDisplayName(playerDisplayName);
if (player == null)
Expand All @@ -202,9 +205,9 @@ public string GetPokemonsHealth(string playerDisplayName)
// Devuelve la cadena formateada con la salud de los Pokémon de ambos jugadores.
return UserInterface.ShowMessagePokemonHealth(player.AvailablePokemons, opponent.AvailablePokemons);
}

// HISTORIA DE USUARIO 4

/// <summary>
/// Realiza un ataque en el turno del jugador, aplicando el daño basado en la efectividad del tipo.
/// </summary>
Expand All @@ -213,56 +216,55 @@ public string GetPokemonsHealth(string playerDisplayName)
/// <param name="moveName">El nombre del movimiento seleccionado para el ataque.</param>
/// <returns>Un mensaje con el resultado del ataque.</returns>
public string PlayerAttack(string attackerName, string defenderName, string moveName)
{
{
//Encontrar el jugador
Player attacker = this.GameList.FindPlayerByDisplayName(attackerName);
Player defender = this.GameList.FindPlayerByDisplayName(defenderName);

if (attacker == null || defender == null)
{
return "Uno o ambos jugadores no están en el juego.";
}

//Encontrar los pokemones activos
Pokemon attackingPokemon = attacker.ActivePokemon;
Pokemon defendingPokemon = defender.ActivePokemon;

// Buscar el jugador por su nombre y validar que esté en el juego
if (attacker == null )
if (attacker == null)
{
throw new ArgumentException($"El jugador '{attackerName}' no está jugando.");
}

if (defender == null)
{
throw new ArgumentException($"El jugador '{attackerName}' no está jugando.");
}

// Verificar que el Pokémon tenga el ataque seleccionado

if (attackingPokemon == null)
{
throw new ArgumentException($"El Pókemon '{attacker.ActivePokemon}' no está activo para la ataque.");
}
if (defendingPokemon == null)
//Encontrar el movimiento activos
Move attackingMove = attacker.ActiveMove;

// Buscar el movimiento y verificar que esté asignado
if (attackingMove == null)
{
throw new ArgumentException($"El Pókemon '{defender.ActivePokemon}' no está activo para la defensa.");
throw new ArgumentException($"El jugador '{attackerName}' no está jugando.");
}

// Verifica que el ataque realiza daño
bool canAttack = attackingPokemon.TryAttack();
if (!canAttack)
{
return UserInterface.ShowMessageAttackDidNotOccur(attacker, attackingPokemon);
}

// Verificar si el ataque es efectivo aleatorio con random
//Enviar mensaje interfaz de que no es efectivo y sino seguir

double AccuaracyAttack = attacker.ActiveMove.Accuracy;

if (AccuaracyAttack < 0.5)
{
return UserInterface.ShowMessageLowEffectiveness(AccuaracyAttack);
return UserInterface.ShowMessageLowEffectiveness(AccuaracyAttack);
}

// Genera el Golpe Crítico con random
Expand All @@ -275,31 +277,31 @@ public string PlayerAttack(string attackerName, string defenderName, string move
{
criticalHit = 1.20;
}

//Ejecuta el ataque
attacker.ExecuteMove(defender, criticalHit);

// Ejecuta el efecto de los ataques especiales que reducen el HP por turno
if (attackingPokemon.IsPoisoned)
{
attackingPokemon.HealthPoints -= (int) 0.05 * (attackingPokemon.HealthPoints);
attackingPokemon.HealthPoints -= (int)0.05 * (attackingPokemon.HealthPoints);
}

if (attackingPokemon.IsBurned)
{
attackingPokemon.HealthPoints -= (int) 0.10 * (attackingPokemon.HealthPoints);
attackingPokemon.HealthPoints -= (int)0.10 * (attackingPokemon.HealthPoints);
}

//Penalizar el turno del jugador
Game game = GameList.FindGameByPlayerDisplayName(attackerName);
game.Turn.PenalizeTurn(attacker);

// Construye el mensaje de resultado
return UserInterface.ShowMessageAttackOcurred(attackingPokemon, defendingPokemon, attacker, defender);
}

//HISTORIA DE USUARIO 5

/// <summary>
/// Obtiene el nombre del jugador que tiene el turno actual en la partida en la que se encuentra el jugador especificado.
/// Verifica si el jugador está en una partida activa y, de ser así, devuelve el nombre del jugador cuyo turno está en curso.
Expand All @@ -308,20 +310,20 @@ public string PlayerAttack(string attackerName, string defenderName, string move
/// <returns>Un mensaje que indica el nombre del jugador con el turno actual o un mensaje de error si el jugador no está en una partida.</returns>
public string GetCurrentTurnPlayer(string playerDisplayName)
{
// Buscar la partida en la que está el jugador
// Buscar la partida en la que está el jugador
Game game = this.GameList.FindGameByPlayerDisplayName(playerDisplayName);

if (game == null)
{
throw new Exception($"El jugador {playerDisplayName} no está en una partida.");
}

// Obtener el nombre del jugador que tiene el turno actual
// Obtener el nombre del jugador que tiene el turno actual
string currentPlayerDisplayName = game.Turn.CurrentPlayer.DisplayName;

return UserInterface.ShowMessageCurrentTurnPlayer(currentPlayerDisplayName);
}

//HISTORIA DE USUARIO 6

/// <summary>
Expand All @@ -338,24 +340,25 @@ public string EndGame(Game game, Player player, string playerDisplayName)
{
// Verifica si el juego ha terminado (puede modificar estados internos del juego)
game.CheckIfGameEnds();

// Si el jugador no tiene Pokémon disponibles, termina la batalla y muestra el mensaje de fin de la batalla
if (player.AvailablePokemons.Count == 0)
{
return UserInterface.ShowBattleEndMessage(playerName: playerDisplayName);
}

// Si el jugador tiene un Pokémon o mas disponibles, la batalla no ha terminado
if (player.AvailablePokemons.Count >= 1)
{
throw new ArgumentException($"La batalla continúa.");
}

return null;
}


//HISTORIA DE USUARIO 7

/// <summary>
/// Cambia el Pokémon activo del jugador al especificado por <paramref name="newPokemonName"/> y pierde su turno.
/// </summary>
Expand All @@ -367,9 +370,10 @@ public string EndGame(Game game, Player player, string playerDisplayName)
public string ChangePokemon(string playerDisplayName, string newPokemonName)
{
// Validación de parámetros de entrada
if (string.IsNullOrWhiteSpace(playerDisplayName)||string.IsNullOrWhiteSpace(newPokemonName))
if (string.IsNullOrWhiteSpace(playerDisplayName) || string.IsNullOrWhiteSpace(newPokemonName))
{
throw new ArgumentNullException(nameof(playerDisplayName), "El nombre del jugador o de su pokemon seleccionado no puede ser nulo o estar vacío.");
throw new ArgumentNullException(nameof(playerDisplayName),
"El nombre del jugador o de su pokemon seleccionado no puede ser nulo o estar vacío.");
}

// Buscar el jugador por su nombre y validar que esté en el juego
Expand All @@ -383,7 +387,8 @@ public string ChangePokemon(string playerDisplayName, string newPokemonName)
int pokemonIndex = player.GetIndexOfPokemon(newPokemonName);
if (pokemonIndex < 0)
{
throw new ArgumentException($"El Pokémon '{newPokemonName}' no está disponible para el jugador '{playerDisplayName}'");
throw new ArgumentException(
$"El Pokémon '{newPokemonName}' no está disponible para el jugador '{playerDisplayName}'");
}

// Activar el Pokémon y generar mensaje
Expand All @@ -395,9 +400,9 @@ public string ChangePokemon(string playerDisplayName, string newPokemonName)

return UserInterface.ShowMessageChangePokemon(player.DisplayName, player.ActivePokemon.Name);
}

//HISTORIA DE USUARIO 8

/// <summary>
/// Permite que un jugador use un ítem específico en su Pokémon activo dentro de una partida.
/// La función busca al jugador por su nombre, verifica que esté en la partida y que tenga un Pokémon activo
Expand All @@ -406,7 +411,7 @@ public string ChangePokemon(string playerDisplayName, string newPokemonName)
/// <param name="playerDisplayName">El nombre del jugador que intenta usar el ítem.</param>
/// <param name="itemName">El nombre del ítem que el jugador intenta usar.</param>
/// <returns>Un mensaje que indica si el jugador usó el ítem con éxito, el efecto del ítem o cualquier error.</returns>
public string PlayerUseItem(string playerDisplayName, string itemName)
public string PlayerUseItem(string playerDisplayName, string itemName)
{
// Buscar el jugador por su nombre
Player player = this.GameList.FindPlayerByDisplayName(playerDisplayName);
Expand Down Expand Up @@ -462,7 +467,6 @@ public string AddPlayerToWaitingList(string displayName)
/// </summary>
/// <param name="displayName">El jugador a remover.</param>
/// <returns>Un mensaje con el resultado.</returns>

public string RemovePlayerFromWaitingList(string displayName)
{
if (this.WaitingList.RemovePlayer(displayName))
Expand All @@ -489,9 +493,8 @@ public string GetAllPlayersWaiting()
}

return UserInterface.ShowMessagePlayersWaiting(this.WaitingList.GetAllWaiting());

}

//HISTORIA DE USUARIO 11

/// <summary>
Expand All @@ -509,7 +512,7 @@ public string PlayerIsWaiting(string displayName)

return $"{displayName} está esperando";
}

private string CreateBattle(string playerDisplayName, string opponentDisplayName)
{
Player player1 = new Player(playerDisplayName);
Expand Down Expand Up @@ -570,5 +573,4 @@ bool OpponentFound()
}
}
}
}

}
4 changes: 2 additions & 2 deletions src/Library/Domain/Domain/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public Game(Player player1, Player player2)
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 @@ -81,7 +81,7 @@ 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 Down
3 changes: 1 addition & 2 deletions src/Library/Domain/Domain/UserInterface.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,11 @@ public class UserInterface
public static string ShowMessagePokemonCatalog()
{
PokemonCatalogBuilder pokemons = new PokemonCatalogBuilder();
List<Pokemon> pokemonList = pokemons.GetPokemonList();

StringBuilder catalogo = new StringBuilder();
catalogo.AppendLine("📜 Catálogo de Pokémon:\n");

foreach (Pokemon pokemon in pokemonList)
foreach (Pokemon pokemon in pokemons.PokemonList)
{
catalogo.AppendLine($"{pokemon.Name}");
}
Expand Down
Loading

0 comments on commit e6abb4a

Please sign in to comment.