Skip to content

Commit

Permalink
Merge pull request #27 from ucudal/Pokemon-TestS
Browse files Browse the repository at this point in the history
Pokemon test s
  • Loading branch information
mateogutierrezo authored Nov 8, 2024
2 parents 30eaa4c + 87dceed commit 8017f7c
Show file tree
Hide file tree
Showing 15 changed files with 210 additions and 37 deletions.
2 changes: 1 addition & 1 deletion src/Library/Attack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public class Attack : IAttack
/// <param name="type">Tipo del ataque a crear.</param>
/// <param name="accuracy">Precisión del ataque a crear.</param>
/// <param name="power">Potencia del ataque a crear.</param>
public Attack(string name, Type type, int accuracy, int power)
public Attack(string name, Type type, double accuracy, int power)
{
this.Name = name;
this.Type = type;
Expand Down
2 changes: 1 addition & 1 deletion src/Library/Caterpie.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Library;

public class Caterpie: Pokemon
{
public Caterpie():base(name: "Caterpie", life: 40, type: Library.Type.Bug)
public Caterpie():base(name: "Caterpie", life: 40, type: Library.Type.Bug, new Attack("Bug bite", Type.Bug, 1,20),new Attack("Tackle",Type.Normal,1,30),new SpecialAttack("Bug stomp", Type.Bug, 0.95,70, State.Paralized),new Attack("String shot", Type.Bug, 1,15))
{

}
Expand Down
2 changes: 1 addition & 1 deletion src/Library/Charizard.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Library;

public class Charizard : Pokemon
{
public Charizard():base(name: "Charizard", life: 100, type: Library.Type.Fire)
public Charizard():base(name: "Charizard", life: 360, type: Type.Fire, new Attack("Dragon claw",Type.Dragon,1,55),new SpecialAttack("Flamethrower",Type.Fire,0.95,75, State.Burned), new Attack("Wing Attack",Type.Flying,0.9,40), new Attack("Fire punch",Type.Fire,1,50))
{

}
Expand Down
2 changes: 1 addition & 1 deletion src/Library/Chikorita.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Library;

public class Chikorita : Pokemon
{
public Chikorita():base(name: "Chikorita", life: 60, type: Library.Type.Grass)
public Chikorita():base(name: "Chikorita", life: 294, type: Type.Grass,new Attack("Razor leaf",Type.Grass,0.9,35),new Attack("Magical leaf", Type.Grass,1,45),new SpecialAttack("Giga Drain",Type.Grass,0.95,70,State.Paralized), new Attack("Body slam",Type.Normal,1,55))
{

}
Expand Down
2 changes: 1 addition & 1 deletion src/Library/DamageCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public static void SpecialCheck(Pokemon attackedPokemon, Attack attack)
{
if (attack is SpecialAttack specialAttack && attackedPokemon.CurrentState == null)
{
attackedPokemon.CurrentState = specialAttack.SpecialEffect;
attackedPokemon.EditState(specialAttack.SpecialEffect);
specialAttack.SetCooldown();
}
}
Expand Down
78 changes: 60 additions & 18 deletions src/Library/Facade.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
using System.Runtime.CompilerServices;

namespace Library;

public static class Facade
{
private static WaitingList WaitingList { get; } = new WaitingList();

public static GameList GameList{ get; } = new GameList();
private static GameList GameList{ get; } = new GameList();

// historia de usuario 2
public static string ShowAtacks(string playerName)
Expand Down Expand Up @@ -39,7 +37,7 @@ public static string ShowPokemonsHP(string playerName, string playerToCheckName
Player playerToCheck = GameList.FindPlayerByName(playerToCheckName);
string result = "";
Game game = GameList.FindGameByPlayer(player);
if (game.GetPlayers().Contains(player) && game.GetPlayers().Contains(playerToCheck))
if (playerToCheck != null && game != null && game.GetPlayers().Contains(player) && game.GetPlayers().Contains(playerToCheck))
{
foreach (Pokemon pokemon in playerToCheck.GetPokemonTeam())
result += pokemon.Name + ": " + pokemon.GetLife() + "\n";
Expand Down Expand Up @@ -69,15 +67,57 @@ public static string CheckTurn(string playerName)
}

//Historia de usuario 6
public static string ChckGameStatus(Game game)
public static string CheckGameStatus(Game game)
{
if (game.GameStatus())
if (game != null)
{
return "Próximo turno";
if (game.GameStatus())
{
return $"Próximo turno, ahora es el turno de {game.GetPlayers()[game.ActivePlayer]}";
}
//eliminar game de la lista de games, ya que este finalizó
return game.Winner();
}
return game.Winner();
return "La partida no pudo ser encontrada";
}

//Historia de usuario 7
public static string ChangePokemon(string playerName, string pokemonName)
{
Player player = GameList.FindPlayerByName(playerName);
if (player == null)
{
return $"El jugador {playerName} no está en ninguna partida.";
}
Game game = GameList.FindGameByPlayer(player);
if (game == null)
{
return "La partida no pudo ser encontrada";
}

if (game.GetPlayers()[game.ActivePlayer].Name == playerName)
{
if (game.GetPlayers()[game.ActivePlayer].GetPokemonTeam().Count < 6)
{
return "Tu equipo pokemon está incompleto, elige hasta tener 6 pokemones en tu equipo";
}
Pokemon choosenPokemon = player.ChoosePokemon(pokemonName);
if (choosenPokemon == null)
{
return $"El pokemon {pokemonName} no fue encontrado en tu equipo";
}
string result = game.ChangePokemon(choosenPokemon);
if (result == "Ese Pokemon no está en tu equipo.")
{
return result;
}
game.NextTurn();
string nextTurn = CheckGameStatus(game);
return result + "\n" + nextTurn;
}
return "No eres el jugador activo, no puedes realizar acciones";
}

//Historia de usuario 8
public static string UseAnItem(string playerName, string item, string pokemon)
{
Expand Down Expand Up @@ -169,31 +209,33 @@ public static string ChooseTeam(string playerName, string cPokemon)
{
PokemonCatalogue.SetCatalogue();
Player player = GameList.FindPlayerByName(playerName);

if (player == null)
{
return "Para poder elegir un equipo, primero debes estar en una batalla";
}
else if (cPokemon != null)
if (player.GetPokemonTeam().Count < 6)
{
foreach (Pokemon pokemon in PokemonCatalogue.PokemonList)
if (cPokemon != null)
{
if (pokemon.Name == cPokemon && !player.GetPokemonTeam().Contains(pokemon))
{
player.AddToTeam(pokemon);
return $"El pokemon {cPokemon} fue añadido al equipo";
}
else if (player.GetPokemonTeam().Contains(pokemon))
foreach (Pokemon pokemon in PokemonCatalogue.SetCatalogue())
{
if (pokemon.Name == cPokemon && !player.GetPokemonTeam().Contains(pokemon))
{
player.AddToTeam(pokemon);
return $"El pokemon {cPokemon} fue añadido al equipo";
}
return $"El pokemon {cPokemon} ya está en el equipo, no puedes volver a añadirlo";
}
}
return $"El pokemon {cPokemon} no fue encontrado";
}
return $"El pokemon {cPokemon} no fue encontrado";

return "El equipo está incompleto, por favor elige 6 pokemones para poder comenzar la batalla";
}

public static string ShowCatalogue()
{
PokemonCatalogue.SetCatalogue();
return PokemonCatalogue.ShowCatalogue();
}

Expand Down
2 changes: 1 addition & 1 deletion src/Library/FullHealth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class FullHealth : IItem
public string Name { get; }
public string Use(Pokemon pokemon)
{
pokemon.CurrentState = null;
pokemon.EditState(null);
return $"{pokemon} ya no tiene ningún estado negativo.";
}
}
1 change: 0 additions & 1 deletion src/Library/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ public string ExecuteAttack(Attack attack)
}
else return $"{this.Players[ActivePlayer].ActivePokemon} está {this.Players[ActivePlayer].ActivePokemon.CurrentState}";
}

return null;
}

Expand Down
2 changes: 1 addition & 1 deletion src/Library/Gengar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Library;

public class Gengar : Pokemon
{
public Gengar():base(name: "Gengar", life: 80, type: Library.Type.Ghost)
public Gengar():base(name: "Gengar", life: 324, type: Type.Ghost, new Attack("Shadow Ball",Type.Ghost,1,60),new SpecialAttack("Sludge Bomb", Type.Poison,0.95,70,State.Poisoned), new Attack("Shadow Punch", Type.Ghost, 0.75,100),new Attack("Focus Punch", Type.Normal, 0.45,155))
{

}
Expand Down
6 changes: 3 additions & 3 deletions src/Library/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ public bool SetActivePokemon(Pokemon pokemon)
/// <returns>
/// <c>null</c> si el ataque no se encuentra en la lista de ataques.
/// </returns>
public IAttack? ChooseAttack(string strAttack)
public Attack? ChooseAttack(string strAttack)

Check warning on line 127 in src/Library/Player.cs

View workflow job for this annotation

GitHub Actions / build-test-generate-docs

The annotation for nullable reference types should only be used in code within a '#nullable' annotations context.
{
foreach (IAttack attack in this.ActivePokemon.GetAttacks())
{
if (attack.Name == strAttack)
if (attack.Name == strAttack && attack is Attack attack2)
{
return attack;
return attack2;
}
}
return null;
Expand Down
35 changes: 31 additions & 4 deletions src/Library/Pokemon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ protected Pokemon(string name, double life, Type type, IAttack attack1, IAttack
// La lista de IMoves aplica LSP, ya que el Pokemon puede tener movimientos de daño (DamageMove) o
// movimientos de buffeo (StatChangerMove)
// y el funcionamiento de la lista es el mismo.
this.Attacks.Add(attack1);
this.Attacks.Add(attack2);
this.Attacks.Add(attack3);
this.Attacks.Add(attack4);
this.AddAttack(attack1);
this.AddAttack(attack2);
this.AddAttack(attack3);
this.AddAttack(attack4);

}

Expand Down Expand Up @@ -128,4 +128,31 @@ public List<Type> GetTypes()
{
return this.Type;
}

public void EditState(State? state)
{
this.CurrentState = state;
}

public void AddAttack(IAttack attack)
{
if (this.Attacks.Count < 4)
{
this.Attacks.Add(attack);
}
}

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

}

return null;
}
}
5 changes: 3 additions & 2 deletions src/Library/PokemonCatalogue.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ namespace Library;

public static class PokemonCatalogue
{
public static List<Pokemon> PokemonList { get; private set; }
private static List<Pokemon> PokemonList { get; set; }

public static string ShowCatalogue()
{
List<Pokemon> pokedex = SetCatalogue();
string pokemonsAvailable = "";
foreach (Pokemon pokemon in PokemonList)
foreach (Pokemon pokemon in pokedex)
{
pokemonsAvailable += pokemon.Name +"\n";
}
Expand Down
2 changes: 1 addition & 1 deletion src/Library/SpecialAttack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ public class SpecialAttack : Attack
public State SpecialEffect { get; private set; }
public int Cooldown { get; private set; }

public SpecialAttack(string name, Type type, int accuracy, int power, State specialEffect): base(name, type, accuracy, power)
public SpecialAttack(string name, Type type, double accuracy, int power, State specialEffect): base(name, type, accuracy, power)
{
this.Cooldown = 0;
this.SpecialEffect = specialEffect;
Expand Down
2 changes: 1 addition & 1 deletion src/Library/StateLogic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static bool AsleepEffect(Pokemon pokemon)

if (pokemon.AsleepTurns == 0)
{
pokemon.CurrentState = null;
pokemon.EditState(null);
}
}

Expand Down
Loading

0 comments on commit 8017f7c

Please sign in to comment.