Skip to content

Commit

Permalink
cambio en tests
Browse files Browse the repository at this point in the history
  • Loading branch information
matiasdcl committed Nov 7, 2024
2 parents be930ae + 95b0f61 commit 7e6a277
Show file tree
Hide file tree
Showing 8 changed files with 108 additions and 38 deletions.
2 changes: 1 addition & 1 deletion src/Library/DamageCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ public static double CalculateDamage(Pokemon attackedPokemon, IAttack 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;
Expand Down
57 changes: 40 additions & 17 deletions src/Library/Facade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,11 @@ 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)
{
Expand All @@ -29,7 +28,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 @@ -38,24 +37,25 @@ 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;
}
return $"El jugador {playerToCheckName} no está en tu partida.";
}
}

//Historia de usuario 5
public static string CheckTurn(string playerName)
{
Player player = GameList.FindPlayerByName(playerName);
if (player == null)
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 All @@ -65,6 +65,18 @@ public static string CheckTurn(string playerName)
}
return null;
}

//Historia de usuario 6
public static string ChckGameStatus(Game game)
{
if (game.GameStatus())
{
return "Próximo turno";
}
return game.Winner();
}


// historia de usuario 9
public static string AddPlayerToWaitingList(string playerName)
{
Expand All @@ -90,7 +102,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 @@ -124,14 +136,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 @@ -142,28 +157,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))
{
player.AddToTeam(pokemon);
return $"El pokemon {cPokemon} fue añadido al equipo";
}
else if (player.PokemonTeam.Contains(pokemon))
foreach (Pokemon pokemon in PokemonCatalogue.PokemonList)
{
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
35 changes: 29 additions & 6 deletions src/Library/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,22 @@ public Game(Player player1, Player player2)
{
this.Players.Add(player1);
this.Players.Add(player2);
this.ActivePlayer = 0;
this.ActivePlayer = Random1or2();
this.TurnCount = 0;
}

public bool OngoingGameCheck()
public int Random1or2()
{
Random random = new Random();
return random.Next(0, 2);
}

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 @@ -34,13 +40,30 @@ public bool OngoingGameCheck()
return true;
}

public string Winner()
{

int winner = 0;
foreach (var pokemon in Players[1].GetPokemonTeam())
{
if (pokemon.CurrentLife > 0)
{
winner = 1;
}
}

int loser = (winner + 1) % 2;
return $"Ganador: {Players[winner]}. Perdedor: {Players[loser]}";

}

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 All @@ -53,7 +76,7 @@ public void CooldownCheck()

public void NextTurn()
{
if (OngoingGameCheck())
if (GameStatus())
{
this.TurnCount++;
CooldownCheck();
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 @@ -74,6 +74,16 @@ public void SetActivePokemon(Pokemon pokemon)
return null;
}

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

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

public string GetPokemonAttacks()
{
string result = "";
Expand Down
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;
}
}
4 changes: 2 additions & 2 deletions test/LibraryTests/PlayerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ 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));
}
Expand Down

0 comments on commit 7e6a277

Please sign in to comment.