Skip to content

Commit

Permalink
ayuda
Browse files Browse the repository at this point in the history
  • Loading branch information
mateogutierrezo committed Nov 8, 2024
2 parents 6dbc9dd + a45e757 commit 432ec9c
Show file tree
Hide file tree
Showing 28 changed files with 383 additions and 242 deletions.
12 changes: 12 additions & 0 deletions src/Library/Attack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,18 @@ public class Attack : IAttack
/// <param name="power">Potencia del ataque a crear.</param>
public Attack(string name, Type type, double accuracy, int power)
{
if (string.IsNullOrEmpty(name))
{
throw new ArgumentException("El nombre ingresado no es válido");
}
if (Accuracy < 0 || Accuracy > 1)
{
throw new ArgumentException("La precision ingresada no es válido");
}
if (Power < 0)
{
throw new ArgumentException("El poder ingresado no es válido");
}
this.Name = name;
this.Type = type;
this.Accuracy = accuracy;
Expand Down
4 changes: 2 additions & 2 deletions src/Library/DamageCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public static double CriticalCheck()
return 1.0;
}

public static void SpecialCheck(Pokemon attackedPokemon, Attack attack)
public static void SpecialCheck(Pokemon attackedPokemon, IAttack attack)
{
if (attack is SpecialAttack specialAttack && attackedPokemon.CurrentState == null)
{
Expand All @@ -168,7 +168,7 @@ public static double CalculateDamage(Pokemon attackedPokemon, Attack attack)
double effectivness = GetEffectivness(attack.Type, attackedPokemon.GetTypes());
double critical = CriticalCheck();
SpecialCheck(attackedPokemon, attack);
return power*effectivness*critical;
return power * effectivness * critical;
}
return 0.0;
}
Expand Down
38 changes: 31 additions & 7 deletions src/Library/Facade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,8 @@ public static string ShowAtacks(string playerName)
Player player = GameList.FindPlayerByName(playerName);
if (player == null)
return $"El jugador {playerName} no está en ninguna partida.";
string result = "";
foreach (IAttack atack in player.ActivePokemon.GetAttacks())
result += atack.Name + "\n";
return result;

return player.GetPokemonAttacks();
}

// historia de usuario 3
Expand Down Expand Up @@ -101,7 +99,7 @@ public static string ChangePokemon(string playerName, string pokemonName)
{
return "Tu equipo pokemon está incompleto, elige hasta tener 6 pokemones en tu equipo";
}
Pokemon choosenPokemon = player.ChoosePokemon(pokemonName);
Pokemon choosenPokemon = player.FindPokemon(pokemonName);
if (choosenPokemon == null)
{
return $"El pokemon {pokemonName} no fue encontrado en tu equipo";
Expand Down Expand Up @@ -134,15 +132,17 @@ public static string UseAnItem(string playerName, string item, string pokemon)
return "Partida inexistente.";
}

return game.UseItem(player.ChooseItem(item), player.ChoosePokemon(pokemon));
return game.UseItem(player.FindItem(item), player.FindPokemon(pokemon));
}


// historia de usuario 9
public static string AddPlayerToWaitingList(string playerName)
{
if (WaitingList.AddPlayer(playerName))
{
return $"{playerName} agregado a la lista de espera";
}
return $"{playerName} ya está en la lista de espera";
}

Expand Down Expand Up @@ -238,5 +238,29 @@ public static string ShowCatalogue()
{
return PokemonCatalogue.ShowCatalogue();
}


public static string ChooseAttack(string playerName, string attackName)
{
Player player = GameList.FindPlayerByName(playerName);
if (player == null)
{
return "Para poder atacar necesitas estar en una batalla";
}
Attack attack = player.FindAttack(attackName);
if (attack == null)
{
return $"El ataque {attackName} no pudo ser encontrado";
}
foreach (Game game in GameList.GetGameList())
{
if (game.GetPlayers().Contains(player))
{
string gameResult = game.ExecuteAttack(attack);
game.NextTurn();
return gameResult;
}
}
return "El ataque no pudo ser concretado";
}

}
55 changes: 52 additions & 3 deletions src/Library/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ public class Game
/// </summary>
public int TurnCount { get; private set; }

/// <summary>
/// Constructor de la clase. Agrega a los jugadores a la partida y determina de forma aleatoria cual comienza la partida. Inicializa el contador de turnos en 0.
/// </summary>
/// <param name="player1"> Primer jugador.</param>
/// <param name="player2"> Segundo jugador.</param>
public Game(Player player1, Player player2)
{
this.Players.Add(player1);
Expand Down Expand Up @@ -90,7 +95,9 @@ public string Winner()
return $"Ganador: {Players[winner]}. Perdedor: {Players[loser]}";

}

/// <summary>
/// Reduce el tiempo de enfriamiento (cooldown) de todos los ataques especiales de cada Pokemon en los equipos de los jugadores.
/// </summary>
public void CooldownCheck()
{
foreach (var player in Players)
Expand All @@ -108,6 +115,9 @@ public void CooldownCheck()
}
}

/// <summary>
/// Avanza al siguiente turno del juego. Actualiza el contador de turnos, reduce el cooldown de los ataques especiales
/// y cambia al siguiente jugador activo, siempre que el juego esté en curso.</summary>
public void NextTurn()
{
if (GameStatus())
Expand All @@ -118,6 +128,15 @@ public void NextTurn()
}
}


/// <summary>
/// Ejecuta un ataque por parte del Pokemon activo del jugador actual, siempre y cuando no se encuentre dormido ni paralizado.
/// </summary>
/// <param name="attack">El ataque que se va a ejecutar.</param>
/// <returns>
/// <c>string</c>Un mensaje que indica el daño infligido al Pokemon objetivo o el estado actual que impidió el ataque.
/// Devuelve null si no se proporciona un ataque válido.
/// </returns>
public string ExecuteAttack(Attack attack)
{
if (attack != null)
Expand All @@ -129,6 +148,14 @@ public string ExecuteAttack(Attack attack)
Pokemon attackedPokemon = this.Players[(this.ActivePlayer + 1) % 2].ActivePokemon;
double damage = DamageCalculator.CalculateDamage(attackedPokemon, attack);
attackedPokemon.TakeDamage(damage);
if (attack.Power == 0)
{
return $"El poder del ataque {attack} era de 0, por lo tanto no hizo daño";
}
if (damage == 0.0)
{
return "El ataque falló y no fue exitoso";
}
return $"{attackedPokemon} recibió {damage} puntos de daño";
}
else return $"{this.Players[ActivePlayer].ActivePokemon} está {this.Players[ActivePlayer].ActivePokemon.CurrentState}";
Expand All @@ -137,6 +164,14 @@ public string ExecuteAttack(Attack attack)
}


/// <summary>
/// Permite que un jugador use un item en un Pokemon específico de su equipo, verificando la validez del item y del Pokemon.
/// </summary>
/// <param name="item">El item que se va a usar.</param>
/// <param name="pokemon">El Pokemon sobre el que se usará el item.</param>
/// <returns>
/// Un mensaje indicando el resultado del uso del objeto, o un mensaje de error si el objeto o el Pokemon no son válidos.
/// </returns>
public string UseItem(IItem item, Pokemon pokemon)
{
if (item == null)
Expand All @@ -152,14 +187,28 @@ public string UseItem(IItem item, Pokemon pokemon)
return item.Use(pokemon);
}

/// <summary>
/// Cambia el Pokemon activo del jugador actual por otro de su equipo, verificando si el cambio es válido.
/// </summary>
/// <param name="pokemon">El nuevo Pokemon que se intentará establecer como activo.</param>
/// <returns>
/// <c>string</c>Un mensaje indicando que el cambio fue exitoso, o un mensaje de error si el Pokemon proporcionado no es válido
/// o si no tiene vida.
/// </returns>

public string ChangePokemon(Pokemon pokemon)
{
if (pokemon == null)
{
return "Ese Pokemon no está en tu equipo.";
}
this.Players[ActivePlayer].SetActivePokemon(pokemon);
return $"{pokemon.Name} es tu nuevo Pokemon activo.";

if (this.Players[ActivePlayer].SetActivePokemon(pokemon))
{
return $"{pokemon.Name} es tu nuevo Pokemon activo.";
}

return $"{pokemon.Name} no tiene vida. Suerte bro, lo siento :/";
}

}
7 changes: 0 additions & 7 deletions src/Library/IAction.cs

This file was deleted.

4 changes: 3 additions & 1 deletion src/Library/IAttack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ namespace Library;
/// <summary>
/// Interfaz de Ataque. Creada para subir la cohesión y bajar el acoplamiento.
/// </summary>
public interface IAttack: IAction
public interface IAttack
{
/// <summary>
/// Nombre del ataque.
Expand All @@ -14,4 +14,6 @@ public interface IAttack: IAction
/// Tipo del ataque.
/// </summary>
public Type Type {get;}
public double Accuracy {get;}

}
19 changes: 14 additions & 5 deletions src/Library/Player.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
namespace Library;
using Library;

/// <summary>
/// Esta clase representa un jugador.
Expand Down Expand Up @@ -27,7 +26,7 @@ public class Player
public Pokemon ActivePokemon { get; private set; }

/// <summary>
/// Le asigna un nombre al jugador, crea las listas de pokemons y items
/// Le asigna un nombre al jugador, crea las listas de pokemons e items
/// agregando items iniciales.
/// </summary>
/// <param name="name">Nombre del jugador a crear.</param>
Expand Down Expand Up @@ -85,7 +84,7 @@ public bool SetActivePokemon(Pokemon pokemon)
/// <returns>
/// <c>null</c> si el pokemon no está en la lista de pokemons.
/// </returns>
public Pokemon? ChoosePokemon(string strPokemon)
public Pokemon FindPokemon(string strPokemon)
{
foreach (Pokemon pokemon in this.PokemonTeam)
{
Expand All @@ -104,7 +103,7 @@ public bool SetActivePokemon(Pokemon pokemon)
/// <returns>
///<c>null</c> si el item no está en la lista items.
/// </returns>
public IItem? ChooseItem(string strItem)
public IItem FindItem(string strItem)
{
foreach (IItem item in this.Items)
{
Expand All @@ -124,7 +123,7 @@ public bool SetActivePokemon(Pokemon pokemon)
/// <returns>
/// <c>null</c> si el ataque no se encuentra en la lista de ataques.
/// </returns>
public Attack? ChooseAttack(string strAttack)
public Attack FindAttack(string strAttack)
{
foreach (IAttack attack in this.ActivePokemon.GetAttacks())
{
Expand Down Expand Up @@ -153,5 +152,15 @@ public List<IItem> GetItemList()
{
return this.Items;
}

public string GetPokemonAttacks()
{
string result = "";
foreach (IAttack atack in ActivePokemon.GetAttacks())
{
result += atack.Name + "\n";
}
return result;
}

}
21 changes: 13 additions & 8 deletions src/Library/Pokemon.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
using System.Collections.ObjectModel;

namespace Library;

/// <summary>
Expand Down Expand Up @@ -78,10 +80,10 @@ protected Pokemon(string name, double life, Type type, IAttack attack1, IAttack
/// puede ser mayor a la vida base del Pokemon.
/// </summary>
/// <param name="hp">Puntos de vida a recuperar.</param>
public void RestoreBaseLife(double hp)
public void GainLife(double hp)
{
this.CurrentLife += hp;
if (this.CurrentLife > hp)
if (this.CurrentLife > this.BaseLife)
{
this.CurrentLife = BaseLife;
}
Expand Down Expand Up @@ -124,7 +126,7 @@ public List<IAttack> GetAttacks()
/// Devuelve la lista de tipos del Pokemon.
/// </summary>
/// <returns></returns>
public List<Type> GetTypes()
public List<Type> GetTypes()
{
return this.Type;
}
Expand All @@ -144,15 +146,18 @@ public void AddAttack(IAttack attack)

public Attack FindAttackByName(string attackString)
{
foreach (IAttack attack in Attacks)
if (attackString != null)
{
if (attack is Attack attack2 && attack.Name == attackString)
foreach (IAttack attack in Attacks)
{
return attack2;
}
if (attack is Attack attack2 && attack.Name == attackString)
{
return attack2;
}

}
}

return null;
}

}
2 changes: 1 addition & 1 deletion src/Library/SuperPotion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class SuperPotion : IItem
/// </returns>
public string Use(Pokemon pokemon)
{
pokemon.CurrentLife += 70;
pokemon.GainLife(70);
return $"{pokemon} ha ganado 70HP.";
}
}
Loading

0 comments on commit 432ec9c

Please sign in to comment.