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 a302b31 + c53aaf2 commit 9049c64
Show file tree
Hide file tree
Showing 28 changed files with 326 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,19 +69,26 @@ public string ChoosePokemons(string playerDisplayName, string[] pokemonNames)
return $"El jugador {playerDisplayName} no está jugando";
}

List<string> result = new List<string>
if (pokemonNames.Length > 6)
{
$"Pokémons seleccionados por el jugador {playerDisplayName}."
};
return "No puedes seleccionar más de 6 Pokémon.";
}

List<Pokemon> selectedPokemons = new List<Pokemon>();
PokemonCatalog catalog = new PokemonCatalog();

foreach (string pokemonName in pokemonNames)
{
Pokemon pokemon = catalog.FindPokemonByName(pokemonName);
player.AddPokemon(pokemon);
if (pokemon != null)
{
player.AddPokemon(pokemon);
selectedPokemons.Add(pokemon);
}
}

return string.Join(",", result);
// Llama a UserInterface para mostrar los Pokémon seleccionados
return UserInterface.ShowMessageSelectedPokemons(selectedPokemons);
}

//HISTORIA DE USUARIO 2
Expand Down Expand Up @@ -109,7 +116,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 @@ -144,7 +151,8 @@ public void ChoosePokemonAndMoveToAttack(string playerDisplayName, string moveNa
{
throw new Exception($"El movimiento {moveName} no está disponible para el Pokémon {pokemonName}");
}
player.ActivateMoveInActivePokemon(moveIndex);

//player.ActivateMoveInActivePokemon(moveIndex);
}

//HISTORIA DE USUARIO 3
Expand Down Expand Up @@ -283,7 +291,21 @@ public string PlayerAttack(string attackerName, string defenderName, string move
}

//HISTORIA DE USUARIO 5

public string GetCurrentTurnPlayer(string playerDisplayName)
{
// Buscar la partida en la que está el jugador
Game game = this.GameList.FindGameByPlayerDisplayName(playerDisplayName);

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

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

return UserInterface.ShowMessageCurrentTurnPlayer(currentPlayerDisplayName);
}

//HISTORIA DE USUARIO 6

Expand Down Expand Up @@ -331,6 +353,40 @@ public string ChangePokemon(string playerDisplayName, string newPokemonName)


//HISTORIA DE USUARIO 8

public string PlayerUseItem(string playerDisplayName, string itemName)
{
// Buscar el jugador por su nombre
Player player = this.GameList.FindPlayerByDisplayName(playerDisplayName);
if (player == null)
{
// Retorna un mensaje indicando que el jugador no está jugando
return $"El jugador {playerDisplayName} no está jugando";
}

try
{
// Intentar usar el ítem
Item itemUsed = player.UseItem(itemName);

// Verificar que el jugador tiene un Pokémon activo
if (player.ActivePokemon == null)
{
return $"{playerDisplayName} no tiene un Pokémon activo para aplicar el ítem.";
}

// Aplicar el efecto del ítem en el Pokémon activo del jugador
string effectResult = itemUsed.ApplyEffect(player.ActivePokemon);

// Retornar un mensaje que indica el uso del ítem y el resultado de su efecto
return $"{playerDisplayName} ha usado {itemUsed.Name}. {effectResult}";
}
catch (ApplicationException ex)
{
// Si ocurre una excepción (por ejemplo, el ítem no existe), retorna el mensaje de error
return ex.Message;
}
}

//HISTORIA DE USUARIO 9

Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,16 @@ public Player FindOpponent(string playerDisplayName)
}
return null;
}
public Game FindGameByPlayerDisplayName(string displayName)
{
foreach (var game in games)
{
if (game.Player1.DisplayName == displayName || game.Player2.DisplayName == displayName)
{
return game;
}
}
return null;
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ namespace ClassLibrary;
/// </summary>

public class Player
{
/// <summary>
{
private List<Item> items = new List<Item>();

/// <summary>
/// Obtiene el nombre para mostrar del jugador.
/// </summary>
public string DisplayName { get; }
Expand All @@ -20,6 +22,14 @@ public class Player
public Player(string displayName)
{
DisplayName = displayName;
this.items.Add(new SuperPocion());
this.items.Add(new SuperPocion());
this.items.Add(new SuperPocion());
this.items.Add(new SuperPocion());
this.items.Add(new Revivir());
this.items.Add(new CuraTotal());
this.items.Add(new CuraTotal());

}

/// <summary>
Expand Down Expand Up @@ -96,10 +106,31 @@ public int GetIndexOfMoveInActivePokemon(string moveDisplayName)
/// Activa un movimiento en el Pokémon activo en base a su índice en la lista de movimientos.
/// </summary>
/// <param name="index">Índice del movimiento en la lista de movimientos del Pokémon activo.</param>
public void ActivateMoveInActivePokemon(Move move)
public void ActivateMoveInActivePokemon(int index)
{
if (this.ActivePokemon.Moves.Contains(move))
this.ActiveMove = move ;
//this.ActiveMove = this.ActivePokemon.Moves[index];
}

public Item UseItem(string itemName)
{
Item itemFound = null;
foreach (Item item in this.items)
{
if (item.Name.Equals(itemName, StringComparison.OrdinalIgnoreCase))
{
itemFound = item;
break; // Sale del bucle una vez encontrado
}
}

if (itemFound == null)
{
throw new ApplicationException($"No existe el ítem {itemName} en el inventario.");
}

this.items.Remove(itemFound);
return itemFound;
}
}


File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,10 @@ public static string ShowMessagePlayersWaiting(ReadOnlyCollection<Player> waitin
}
return result.ToString();
}
public static string ShowMessageCurrentTurnPlayer(string currentPlayerDisplayName)
{
return $"🎮 Es el turno de {currentPlayerDisplayName}.";
}

/// <summary>
/// Muestra un mensaje indicando que un ataque ha ocurrido, con detalles sobre el atacante, el defensor y el movimiento usado.
Expand Down
File renamed without changes.
18 changes: 18 additions & 0 deletions src/Library/Domain/Item/CompleteCure.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
namespace ClassLibrary
{
public class CuraTotal : Item
{
public CuraTotal() : base("Cura total") { }

public override string ApplyEffect(Pokemon pokemon)
{
if (pokemon == null)
{
return "No hay un Pokémon activo para curar.";
}

pokemon.HealthPoints = 100;
return $"{pokemon.Name} ha sido curado completamente.";
}
}
}
23 changes: 23 additions & 0 deletions src/Library/Domain/Item/Item.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace ClassLibrary;

public class Item
{
public string Name { get; }

public Item(string name)
{
this.Name = name;
}
/// <summary>
/// Aplica el efecto del ítem en el Pokémon especificado.
/// Este método será sobrescrito por las subclases.
/// </summary>
/// <param name="pokemon">El Pokémon al que se le aplicará el efecto.</param>
/// <returns>Un mensaje con el resultado de aplicar el efecto.</returns>
public virtual string ApplyEffect(Pokemon pokemon)
{
return $"{Name} no tiene ningún efecto.";
}
}


25 changes: 25 additions & 0 deletions src/Library/Domain/Item/Revive.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
namespace ClassLibrary
{
public class Revivir : Item
{
private const int ReviveHealth = 50;

public Revivir() : base("Revivir") { }

public override string ApplyEffect(Pokemon pokemon)
{
if (pokemon == null)
{
return "No hay un Pokémon para revivir.";
}

if (pokemon.HealthPoints > 0)
{
return $"{pokemon.Name} no puede ser revivido.";
}

pokemon.HealthPoints = ReviveHealth;
return $"{pokemon.Name} ha sido revivido con {ReviveHealth} puntos de vida.";
}
}
}
23 changes: 23 additions & 0 deletions src/Library/Domain/Item/SuperPocion.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace ClassLibrary
{
public class SuperPocion : Item
{
private const int HealingAmount = 70;

public SuperPocion() : base("Super pocion") { }

public override string ApplyEffect(Pokemon pokemon)
{
if (pokemon == null)
{
return "No hay un Pokémon activo para curar.";
}

int previousHealth = pokemon.HealthPoints;
pokemon.HealthPoints += HealingAmount;
int healthRestored = pokemon.HealthPoints - previousHealth;

return $"{pokemon.Name} ha recuperado {healthRestored} puntos de vida.";
}
}
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ namespace ClassLibrary

public class PokemonCatalog
{
// El builder crea y gestiona 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.
// 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.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ private void AddPokemonToCatalog(string name, List<IMove> moves, PokemonType.Typ
Pokemon pokemon = new Pokemon();
pokemon.Name = name;
pokemon.HealthPoints = 100;
pokemon.Moves = new List<IMove>();
pokemon.Moves = moves;
pokemon.Type = type;
this.Pokemons.Add(pokemon); // Añade el Pokémon a la lista del catálogo.
}
Expand Down
File renamed without changes.
24 changes: 23 additions & 1 deletion src/Library/Library.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 1 addition & 14 deletions test/LibraryTests/DomainClassesTests/PokemonCatalogTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,6 @@ namespace ClassLibrary.Tests
{
public class PokemonCatalogTests
{
[Test]
public void FindPokemonByName_ReturnsPokemonWithSpecialMove()
{
// Arrange
PokemonCatalog catalog = new PokemonCatalog();

// Act
Pokemon pokemon = catalog.FindPokemonByName("Blaziken");

// Assert
Assert.That(pokemon, Is.Not.Null);
Assert.That(pokemon.SpecialMoveNormal.Name, Is.EqualTo("Anillo Ígneo"));
}

[Test]
public void FindPokemonByName_NameWithSpaces_ReturnsCorrectPokemon()
Expand All @@ -40,7 +27,7 @@ public void FindPokemonByName_PokemonNotFound_ReturnsNull()
PokemonCatalog catalog = new PokemonCatalog();

// Act
Pokemon pokemon = catalog.FindPokemonByName("Pikachu");
Pokemon pokemon = catalog.FindPokemonByName("Hulalu");

// Assert
Assert.That(pokemon, Is.Null);
Expand Down
Loading

0 comments on commit 9049c64

Please sign in to comment.