Skip to content

Commit

Permalink
merge
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastianCuneo committed Nov 7, 2024
2 parents 51128cb + 68a1045 commit be8c26e
Show file tree
Hide file tree
Showing 9 changed files with 313 additions and 321 deletions.
15 changes: 7 additions & 8 deletions src/Library/Domain/Domain/Facade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public class Facade
private UserInterface UserInterface { get; }


private static Facade? _instance;
private static Facade _instance;

// Este constructor privado impide que otras clases puedan crear instancias de esta.
private Facade()
Expand Down Expand Up @@ -245,13 +245,10 @@ public string PlayerAttack(string attackerName, string defenderName, string move
//Enviar mensaje interfaz de que no es efectivo y sino seguir

double AccuaracyAttack = attackingPokemon.SpecialMoveNormal.Accuracy;

string message;

if (AccuaracyAttack < 0.5)
{
// return UserInterface.ShowMessageLowEffectiveness(AccuaracyAttack);
message = UserInterface.ShowMessageLowEffectiveness(AccuaracyAttack);
return UserInterface.ShowMessageLowEffectiveness(AccuaracyAttack);
}
// if (AccuaracyAttack > 0.5)
// {
Expand All @@ -263,15 +260,17 @@ public string PlayerAttack(string attackerName, string defenderName, string move

// Generar un número aleatorio entre 1 y 100
int randomNumber = random.Next(1, 101);
bool criticalHit = randomNumber <= 10;

if (randomNumber < 10)
{
//int golpeCritico = attackingPokemon.Moves
}
//Comprobar si es un golpe crítico.
//Un golpe crítico aumenta un 20% el daño a realizar. La probabilidad de que un golpe sea crítico es del 10%.
//Para eso definir de default 1

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

Check failure on line 273 in src/Library/Domain/Domain/Facade.cs

View workflow job for this annotation

GitHub Actions / build-test-generate-docs

The name 'criticalHit' does not exist in the current context

Check failure on line 273 in src/Library/Domain/Domain/Facade.cs

View workflow job for this annotation

GitHub Actions / build-test-generate-docs

The name 'criticalHit' does not exist in the current context

// Ejecuta el efecto de los ataques especiales que reducen el HP por turno
if (attackingPokemon.IsPoisoned)
Expand Down
6 changes: 3 additions & 3 deletions src/Library/Domain/Domain/WaitingList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public bool RemovePlayer(string DisplayName)
{
throw new ArgumentException("El nombre de usuario no puede estar vacío o nulo.", nameof(DisplayName));
}
Player? player = this.FindPlayerByDisplayName(DisplayName);
Player player = this.FindPlayerByDisplayName(DisplayName);
if (player == null) return false;
players.Remove(player);
return true;
Expand All @@ -81,7 +81,7 @@ public bool RemovePlayer(string DisplayName)
/// </param>
/// <returns>El jugador encontrado o <c>null</c> en caso contrario.
/// </returns>
public Player? FindPlayerByDisplayName(string DisplayName)
public Player FindPlayerByDisplayName(string DisplayName)
{
// Verifica que el nombre no esté vacío o nulo
if (string.IsNullOrEmpty(DisplayName))
Expand All @@ -108,7 +108,7 @@ public bool RemovePlayer(string DisplayName)
///
/// </summary>
/// <returns></returns>
public Player? GetAnyoneWaiting()
public Player GetAnyoneWaiting()
{
// Verifica si la lista está vacía
if (this.players.Count == 0)
Expand Down
9 changes: 0 additions & 9 deletions src/Library/Domain/Moves/IMove.cs

This file was deleted.

18 changes: 2 additions & 16 deletions src/Library/Domain/Moves/Move.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace ClassLibrary;

public abstract class Move: IMove
public abstract class Move

Check warning on line 3 in src/Library/Domain/Moves/Move.cs

View workflow job for this annotation

GitHub Actions / build-test-generate-docs

Abstract type 'Move' should not have public constructors (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1012)
{
/// <summary>
/// Nombre del movimiento.
Expand Down Expand Up @@ -35,19 +35,5 @@ public Move(string name, int attackValue, double accuracy)
/// <param name="attacker">El pokemon que está atacando.</param>
/// <param name="target">El pokemon que está siendo atacado.</param>
///
public virtual void ExecuteMove(Pokemon attacker, Pokemon target, bool criticalHit)
{
double typeEffectiveness = PokemonType.GetEffectiveness(attacker.Type, target.Type);
int calculatedDamage;
if (criticalHit)
{
calculatedDamage = (int)((this.AttackValue * typeEffectiveness) * 1.2);
}
else
{
calculatedDamage = (int)((this.AttackValue * typeEffectiveness));
}

target.HealthPoints -= calculatedDamage;
}
public abstract void ExecuteMove(Pokemon attacker, Pokemon target, double criticalHit);
}
4 changes: 2 additions & 2 deletions src/Library/Domain/Moves/MoveNormal.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ public MoveNormal(string name, int attackValue, double accuracy): base(name, att
/// <param name="attacker">El pokemon que está atacando.</param>
/// <param name="target">El pokemon que está siendo atacado.</param>
///
public void ExecuteMove(Pokemon attacker, Pokemon target)
public override void ExecuteMove(Pokemon attacker, Pokemon target, double criticalHit)
{
double typeEffectiveness = PokemonType.GetEffectiveness(attacker.Type, target.Type);
int calculatedDamage = (int)(this.AttackValue * typeEffectiveness);
int calculatedDamage = (int)((this.AttackValue * typeEffectiveness)*(criticalHit));

target.HealthPoints -= calculatedDamage;
}
Expand Down
26 changes: 13 additions & 13 deletions src/Library/Domain/Pokemon/Pokemon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public class Pokemon
private int _healthPoints;
private MoveNormal _specialMoveNormal;
private const int MaxMoves = 4;
private List<IMove> _moves;
private List<Move> _moves;
private bool _isPoisoned;
private bool _isBurned;
private int _sleepTurns;
Expand All @@ -28,7 +28,7 @@ public class Pokemon
/// </summary>
public Pokemon()
{
Moves = new List<IMove>();
Moves = new List<Move>();
this.IsBurned = false;
this.IsPoisoned = false;
this.SleepTurns = 0;
Expand All @@ -41,7 +41,7 @@ public Pokemon()
/// </summary>
public bool IsPoisoned
{
get => _isPoisoned;
get { return this._isPoisoned; }
set
{
// Verifica si el Pokémon ya está afectado por un estado especial
Expand Down Expand Up @@ -78,7 +78,7 @@ public bool IsBurned
/// </summary>
public bool IsParalyzed
{
get => _isParalyzed;
get { return this._isParalyzed; }
set
{
if (_isPoisoned || _isBurned || _sleepTurns > 0)
Expand All @@ -96,7 +96,7 @@ public bool IsParalyzed
/// </summary>
public int SleepTurns
{
get => _sleepTurns;
get { return this._sleepTurns; }
set
{
if (_isPoisoned || _isBurned || _isParalyzed)
Expand All @@ -112,15 +112,14 @@ public int SleepTurns
_sleepTurns = value;
}
}


/// <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;
public string Name
{
get { return this._name; }
set
{
if (string.IsNullOrEmpty(value))
Expand All @@ -135,7 +134,7 @@ public string Name
/// <exception cref="ArgumentOutOfRangeException">Se lanza si los puntos de salud son negativos.</exception>
public int HealthPoints
{
get => _healthPoints;
get { return this._healthPoints; }
set
{
if (value < 0)
Expand All @@ -150,7 +149,7 @@ public int HealthPoints
/// <exception cref="ArgumentNullException">Se lanza si el movimiento especial es nulo.</exception>
public MoveNormal SpecialMoveNormal
{
get => _specialMoveNormal;
get { return this._specialMoveNormal; }
set
{
if (value == null)
Expand All @@ -167,9 +166,10 @@ public MoveNormal SpecialMoveNormal
/// <summary>
/// Obtiene o establece la lista de movimientos regulares del Pokémon.
/// </summary>
public List<IMove> Moves
public List<Move> Moves

Check warning on line 169 in src/Library/Domain/Pokemon/Pokemon.cs

View workflow job for this annotation

GitHub Actions / build-test-generate-docs

Change 'Moves' to be read-only by removing the property setter (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca2227)

Check warning on line 169 in src/Library/Domain/Pokemon/Pokemon.cs

View workflow job for this annotation

GitHub Actions / build-test-generate-docs

Change 'List<Move>' in 'Pokemon.Moves' to use 'Collection<T>', 'ReadOnlyCollection<T>' or 'KeyedCollection<K,V>' (https://learn.microsoft.com/dotnet/fundamentals/code-analysis/quality-rules/ca1002)
{
get => _moves ??= new List<IMove>(); // Inicializa la lista si es nula.
get { return this._moves; }

set
{
if (value != null && value.Count > MaxMoves)
Expand Down
15 changes: 9 additions & 6 deletions src/Library/Domain/Pokemon/PokemonCatalog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ namespace ClassLibrary

public class PokemonCatalog
{
// El builder crea y gniestiona la lista de Pokémon del catálogo. Esta variable es estática porque el catállogo de pokemon es único y no cambainte en la solución.
private static PokemonCatalogBuilder catalog = new PokemonCatalogBuilder();

// Lista de Pokémon obtenida a través del builder.
private List<Pokemon> pokemons = catalog.GetPokemonList();
private List<Pokemon> pokemons;

public PokemonCatalog()
{
PokemonCatalogBuilder builder = new PokemonCatalogBuilder();
this.pokemons = builder.GetPokemonList();
}

/// <summary>
/// Encuentra un Pokémon por su nombre en el catálogo.
Expand All @@ -27,16 +30,16 @@ public class PokemonCatalog
/// </summary>
/// <param name="pokemonName">Nombre del Pokémon a buscar.</param>
/// <returns>El objeto Pokemon si se encuentra, de lo contrario null.</returns>

public Pokemon FindPokemonByName(string pokemonName)
{
// Verifica que la string no esté vacía.
if (string.IsNullOrWhiteSpace(pokemonName))
{
throw new ArgumentException("El nombre del Pokémon no puede estar vacío.", nameof(pokemonName));
}

// Recorre la lista de Pokémons en busca del nombre proporcionado.
foreach (Pokemon pokemon in catalog.GetPokemonList())
foreach (Pokemon pokemon in this.pokemons)
{
if (pokemon.Name.Equals(pokemonName, StringComparison.OrdinalIgnoreCase))
{
Expand Down
Loading

0 comments on commit be8c26e

Please sign in to comment.