Skip to content

Commit

Permalink
Merge pull request #21 from ucudal/Pokemon-Tests
Browse files Browse the repository at this point in the history
Pokemon tests
  • Loading branch information
mariaines-barral authored Nov 7, 2024
2 parents f397cc4 + 32eee16 commit 95b0f61
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 41 deletions.
3 changes: 1 addition & 2 deletions src/Library/DamageCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,12 +165,11 @@ public static double CalculateDamage(Pokemon attackedPokemon, Attack attack)
if (randomDouble <= attack.Accuracy)
{
double power = attack.Power;
double effectivness = GetEffectivness(attack.Type, attackedPokemon.Type);
double effectivness = GetEffectivness(attack.Type, attackedPokemon.GetTypes());
double critical = CriticalCheck();
SpecialCheck(attackedPokemon, attack);
return power*effectivness*critical;
}

return 0.0;
}
}
48 changes: 29 additions & 19 deletions src/Library/Facade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,18 @@ 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)
{

Player player = GameList.FindPlayerByName(playerName);
if (player != null)
if (player == null)
{
return $"El jugador {playerName} no está en ninguna partida.";
}
string result = "";
foreach (IAttack atack in player.ActivePokemon.Attacks)
foreach (IAttack atack in player.ActivePokemon.GetAttacks())
{
result += atack.Name + "\n";
}
Expand All @@ -35,7 +34,7 @@ public static string ShowPokemonsHP(string playerName, string playerToCheckName
if (playerToCheckName == null)
{
string result = "";
foreach (Pokemon pokemon in player.PokemonTeam)
foreach (Pokemon pokemon in player.GetPokemonTeam())
result += pokemon.Name + ": " + pokemon.GetLife() + "\n";
return result;
}
Expand All @@ -44,9 +43,9 @@ public static string ShowPokemonsHP(string playerName, string playerToCheckName
Player playerToCheck = GameList.FindPlayerByName(playerToCheckName);
string result = "";
Game game = GameList.FindGameByPlayer(player);
if (game.Players.Contains(player) && game.Players.Contains(playerToCheck))
if (game != null && game.Players.Contains(player) && game.Players.Contains(playerToCheck))
{
foreach (Pokemon pokemon in playerToCheck.PokemonTeam)
foreach (Pokemon pokemon in playerToCheck.GetPokemonTeam())
result += pokemon.Name + ": " + pokemon.GetLife() + "\n";
return result;
}
Expand All @@ -62,7 +61,7 @@ public static string CheckTurn(string playerName)
return $"El jugador {playerName} no está en ninguna partida.";
Game game = GameList.FindGameByPlayer(player);
string opciones = $"1- !Attack (ver los ataques con el pokemon activo)\n 2- !Item (ver los items disponibles)\n 3- !Change (ver pokemons disp. a cambiar)";
if (game.Players.Contains(player))
if (game != null && game.Players.Contains(player))
{
int activePlayerIndex = game.ActivePlayer;
Player activePlayer = game.Players[activePlayerIndex];
Expand Down Expand Up @@ -107,7 +106,7 @@ public static string GetAllPlayersWaiting()
}

string result = "Esperan: ";
foreach (Player player in WaitingList.Players)
foreach (Player player in WaitingList.GetWaitingList())
{
result = result + player.Name + "; ";
}
Expand Down Expand Up @@ -141,14 +140,17 @@ public static string StartBattle(string playerName, string? opponentName)
return $"{opponentName} no está esperando";
}
return CreateGame(playerName, opponent!.Name);

bool OpponentProvided()
{
return !string.IsNullOrEmpty(opponentName);
}

bool SomebodyIsWaiting()
{
return WaitingList.Count != 0;
}

bool OpponentFound()
{
return opponent != null;
Expand All @@ -159,28 +161,36 @@ bool OpponentFound()

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.PokemonTeam.Contains(pokemon))
foreach (Pokemon pokemon in PokemonCatalogue.PokemonList)
{
player.AddToTeam(pokemon);
return $"El pokemon {cPokemon} fue añadido al equipo";
}
else if (player.PokemonTeam.Contains(pokemon))
{
return $"El pokemon {cPokemon} ya está en el equipo, no puedes volver a añadirlo";
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))
{
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()
Expand Down
8 changes: 4 additions & 4 deletions src/Library/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public bool GameStatus()
foreach (var player in Players)
{
bool Ongoing = false;
foreach (var pokemon in player.PokemonTeam)
foreach (var pokemon in player.GetPokemonTeam())
{
if (pokemon.CurrentLife > 0)
{
Expand All @@ -44,7 +44,7 @@ public string Winner()
{

int winner = 0;
foreach (var pokemon in Players[1].PokemonTeam)
foreach (var pokemon in Players[1].GetPokemonTeam())
{
if (pokemon.CurrentLife > 0)
{
Expand All @@ -61,9 +61,9 @@ public void CooldownCheck()
{
foreach (var player in Players)
{
foreach (var pokemon in player.PokemonTeam)
foreach (var pokemon in player.GetPokemonTeam())
{
foreach (var attack in pokemon.Attacks)
foreach (var attack in pokemon.GetAttacks())
{
if (attack is SpecialAttack specialAttack)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Library/GameList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Library;

public class GameList
{
public List<Game> Games { get; private set; } = new List<Game>();
private List<Game> Games { get; set; } = new List<Game>();

public Game AddGame(Player player1, Player player2)
{
Expand Down
16 changes: 13 additions & 3 deletions src/Library/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
public class Player
{
public string Name { get; }
public List<Pokemon> PokemonTeam { get; private set;}
public List<IItem> Items { get; private set;}
private List<Pokemon> PokemonTeam { get; set;}
private List<IItem> Items { get; set;}
public Pokemon ActivePokemon { get; private set; }

public Player(string name)
Expand Down Expand Up @@ -63,7 +63,7 @@ public void SetActivePokemon(Pokemon pokemon)

public IAttack? ChooseAttack(string strAttack)

Check warning on line 64 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.Attacks)
foreach (IAttack attack in this.ActivePokemon.GetAttacks())
{
if (attack.Name == strAttack)
{
Expand All @@ -73,5 +73,15 @@ public void SetActivePokemon(Pokemon pokemon)

return null;
}

public List<Pokemon> GetPokemonTeam()
{
return this.PokemonTeam;
}

public List<IItem> GetItemList()
{
return this.Items;
}

}
23 changes: 16 additions & 7 deletions src/Library/Pokemon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ namespace Library;
public abstract class Pokemon
{
public string Name { get; set; }
public List<IAttack> Attacks { get; private set; }
public List<Type> Type { get; private set; }
private List<IAttack> Attacks { get; set; }
private List<Type> Type { get; set; }
public State? CurrentState { get; set; }

public int AsleepTurns { get; set; }
public double BaseLife { get; private set; }
public double CurrentLife { get; set; }


protected Pokemon(string name, double life, Type type)
protected Pokemon(string name, double life, Type type, IAttack attack1, IAttack attack2, IAttack attack3, IAttack attack4)
{
//Aplicamos Creator
this.Name = name;
Expand All @@ -25,10 +25,10 @@ protected Pokemon(string name, double life, Type type)
this.AsleepTurns = 0;
// 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.Attacks.Add(attack1);
this.Attacks.Add(attack2);
this.Attacks.Add(attack3);
this.Attacks.Add(attack4);

}

Expand Down Expand Up @@ -56,5 +56,14 @@ public string GetLife()
{
return $"{this.CurrentLife}/{this.BaseLife}";
}

public List<IAttack> GetAttacks()
{
return this.Attacks;
}

public List<Type> GetTypes()
{
return this.Type;
}
}
7 changes: 6 additions & 1 deletion src/Library/WaitingList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ namespace Library;

public class WaitingList
{
public List<Player> Players { get; private set; }= new List<Player>();
private List<Player> Players { get; set; }= new List<Player>();

public int Count
{
Expand Down Expand Up @@ -42,4 +42,9 @@ public bool RemovePlayer(string playerName)
int randomNumber = random.Next(0, this.Count);
return this.Players[randomNumber];
}

public List<Player> GetWaitingList()
{
return this.Players;
}
}
7 changes: 3 additions & 4 deletions test/LibraryTests/PlayerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,14 @@ public void SetUp()
public void TestAddToTeam()
{
player.AddToTeam(charizard1);
Assert.That(player.PokemonTeam.Contains(charizard1));
Assert.That(player.GetPokemonTeam().Contains(charizard1));
player.AddToTeam(charizard2);
Assert.That(player.PokemonTeam.Count, Is.EqualTo(2));
Assert.That(player.GetPokemonTeam().Count, Is.EqualTo(2));
}

[Test]
public void TestChangeActivePokemon()
{
player.ChangeActivePokemon(charizard1);
Assert.That(player.ActivePokemon,Is.EqualTo(charizard1));

}
}

0 comments on commit 95b0f61

Please sign in to comment.