Skip to content

Commit

Permalink
Merge pull request #16 from ucudal/hd-ongoing-game
Browse files Browse the repository at this point in the history
Hd ongoing game
  • Loading branch information
mateogutierrezo authored Nov 6, 2024
2 parents c328dc1 + d95182c commit e1ae562
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 94 deletions.
4 changes: 2 additions & 2 deletions src/Library/Attack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ namespace Library;
public class Attack : IAttack
{
public string Name { get; private set;}
public Type types{get; private set;}
public Type Type { get; }
public double Accuracy {get; private set;}
public int Power {get; private set;}

public Attack(string name, Type type, int Accuracy, int Power)
{
this.Name = name;
this.types = type;
this.Type = type;
this.Accuracy = Accuracy;
this.Power = Power;

Expand Down
2 changes: 1 addition & 1 deletion src/Library/DamageCalculator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public static void SpecialCheck(Pokemon attackedPokemon, Attack attack)
if (attack is SpecialAttack specialAttack && attackedPokemon.CurrentState == null)
{
attackedPokemon.CurrentState = specialAttack.SpecialEffect;
specialAttack.Cooldown = 2;
specialAttack.SetCooldown();
}
}

Expand Down
3 changes: 2 additions & 1 deletion src/Library/FullHealth.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ namespace Library;
public class FullHealth : IItem
{
public string Name { get; }
public void Use(Pokemon pokemon)
public string Use(Pokemon pokemon)
{
pokemon.CurrentState = null;
return $"{pokemon} ya no tiene ningún estado negativo.";
}
}
128 changes: 63 additions & 65 deletions src/Library/Game.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,40 @@ namespace Library;

public class Game
{
public List<Player> Players {get; private set;}//Cambiar a Array
public int ActivePlayer {get; private set;}
public int TurnCount {get; private set;}
List<Player> players = new List<Player> (); //Cambiar a Array
public int ActivePlayer;
public int TurnCount;

public Game(Player player1, Player player2)
{
this.Players = new List<Player>();
this.Players.Add(player1);
this.Players.Add(player2);
this.players.Add(player1);
this.players.Add(player2);
this.ActivePlayer = 0;
this.TurnCount = 0;
}
public void NextTurn()

public bool OngoingGameCheck()
{
this.TurnCount++;
foreach (var player in players)
{
bool Ongoing = false;
foreach (var pokemon in player.PokemonTeam)
{
if (pokemon.CurrentLife > 0)
{
Ongoing = true;
}
}
if (!Ongoing)
{
return false;
}
}
return true;
}

public void CooldownCheck()
{
foreach (var player in players)
{
foreach (var pokemon in player.PokemonTeam)
Expand All @@ -31,76 +49,56 @@ public void NextTurn()
}
}
}
this.ActivePlayer = (this.ActivePlayer + 1) % 2;
}

public string? ExecuteAction()
public void NextTurn()
{
IAction action = this.Players[ActivePlayer].ChooseAction();
if (action is Attack attack)
{
bool asleep = StateLogic.AsleepEffect(Players[ActivePlayer].ActivePokemon);
bool paralized = StateLogic.ParalizedEffect(Players[ActivePlayer].ActivePokemon);
if (!asleep & !paralized)
{
this.Players[(this.ActivePlayer + 1) % 2].ActivePokemon.TakeDamage(
DamageCalculator.CalculateDamage(this.Players[(this.ActivePlayer + 1) % 2].ActivePokemon, attack));
}
else
return
$"{this.Players[ActivePlayer].ActivePokemon} is {this.Players[ActivePlayer].ActivePokemon.CurrentState}";
}
else return $"{this.players[ActivePlayer].ActivePokemon} is {this.players[ActivePlayer].ActivePokemon.CurrentState}";
}
else if (action is Backpack backpack)
if (OngoingGameCheck())
{

this.TurnCount++;
CooldownCheck();
this.ActivePlayer = (this.ActivePlayer + 1) % 2;
}
}

else if (action is Pokeball pokeball)
public string ExecuteAttack(Attack attack)
{
bool asleep = StateLogic.AsleepEffect(players[ActivePlayer].ActivePokemon);
bool paralized = StateLogic.ParalizedEffect(players[ActivePlayer].ActivePokemon);
if (!asleep & !paralized)
{
pokeball.ChangePokemon(this.players[ActivePlayer]);
Pokemon attackedPokemon = this.players[(this.ActivePlayer + 1) % 2].ActivePokemon;
double damage = DamageCalculator.CalculateDamage(attackedPokemon, attack);
attackedPokemon.TakeDamage(damage);
return $"{attackedPokemon} recibió {damage} puntos de daño";
}
return "accion no reconocida, introduzcala nuevamente";
StateLogic.PoisonedEffect(players[ActivePlayer].ActivePokemon);
StateLogic.BurnedEffect(players[ActivePlayer].ActivePokemon);

else return $"{this.players[ActivePlayer].ActivePokemon} está {this.players[ActivePlayer].ActivePokemon.CurrentState}";
}

public void MenuCambioPokemon()

public string UseItem(IItem item, Pokemon pokemon)
{

int n = 1;
Console.WriteLine($"Que pokemon va a luchar?:");
foreach (var pokemon in this.players[ActivePlayer].PokemonTeam)
{
Console.WriteLine($"{n}) {pokemon.Name}");
n++;
}
while (true)
{
if (item == null)
{
return "Ese item no está en tu inventario.";
}

pokeball.ChangePokemon(this.Players[ActivePlayer]);
}
return "accion no reconocida, introduzcala nuevamente";
StateLogic.PoisonedEffect(Players[ActivePlayer].ActivePokemon);
StateLogic.BurnedEffect(Players[ActivePlayer].ActivePokemon);
if (pokemon == null)
{
return "Ese Pokemon no está en tu equipo.";
}


Console.Write(">");
int R = Convert.ToInt32(Console.ReadLine());//posible error si se ingresa str
if (R > 1 && R <= n)
{
this.players[ActivePlayer].ChangeActivePokemon(players[ActivePlayer].PokemonTeam[R - 1]);
return;
}
else
{
Console.WriteLine("Opcion invalida");
}
}

return item.Use(pokemon);
}

public string ChangePokemon(Pokemon pokemon)
{
if (pokemon == null)
{
return "Ese Pokemon no está en tu equipo.";
}
this.players[ActivePlayer].SetActivePokemon(pokemon);
return $"{pokemon.Name} es tu nuevo Pokemon activo.";
}

}
2 changes: 1 addition & 1 deletion src/Library/IItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ namespace Library;
public interface IItem
{
string Name { get; }
void Use(Pokemon pokemon);
string Use(Pokemon pokemon);
}
64 changes: 42 additions & 22 deletions src/Library/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,36 +22,56 @@ public Player(string name)
this.Items.Add(new FullHealth());
}

public IAction ChooseAction()
{
// mostrar movimientos en pantalla, podría llamar a otra
// clase para imprimir en pantalla las opciones
//obtengo la selección del usuario, por ejemplo le pido un int
// x=0
// if (x < 5)
// {
// return this.ActivePokemon.Moves[x - 1];
// }
// else
// {
// IAction action = new Pokeball();
// return action;
// }

IAction action = new Pokeball();
return action;
}

public void AddToTeam(Pokemon pokemon)
{
if (this.PokemonTeam.Count < 6)
{
this.PokemonTeam.Add(pokemon);
}
}
public void ChangeActivePokemon(Pokemon pokemon)

public void SetActivePokemon(Pokemon pokemon)
{
this.ActivePokemon = pokemon;
}

public Pokemon ChoosePokemon(string strPokemon)
{
foreach (Pokemon pokemon in this.PokemonTeam)
{
if (pokemon.Name == strPokemon)
{
return pokemon;
}
}

return null;
}

public IItem ChooseItem(string strItem)
{
foreach (IItem item in this.Items)
{
if (item.Name == strItem)
{
return item;
}
}

return null;
}

public IAttack ChooseAttack(string strAttack)
{
foreach (IAttack attack in this.ActivePokemon.Attacks)
{
if (attack.Name == strAttack)
{
return attack;
}
}

return null;
}

}
1 change: 1 addition & 0 deletions src/Library/Pokemon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ protected Pokemon(string name, double life, Type type)
//Aplicamos Creator
this.Name = name;
this.BaseLife = life;
this.CurrentState = null;
this.CurrentLife = BaseLife;
this.Type = new List<Type>();
this.Attacks = new List<IAttack>();
Expand Down
3 changes: 2 additions & 1 deletion src/Library/Revive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ namespace Library;
public class Revive : IItem
{
public string Name { get; }
public void Use(Pokemon pokemon)
public string Use(Pokemon pokemon)
{
pokemon.CurrentLife = (pokemon.BaseLife / 2);
return $"{pokemon} ha revivido.";
}
}
5 changes: 5 additions & 0 deletions src/Library/SpecialAttack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,9 @@ public void LowerCooldown()
Cooldown -= 1;
}
}

public void SetCooldown()
{
Cooldown = 2;
}
}
3 changes: 2 additions & 1 deletion src/Library/SuperPotion.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ namespace Library;
public class SuperPotion : IItem
{
public string Name { get; }
public void Use(Pokemon pokemon)
public string Use(Pokemon pokemon)
{
pokemon.CurrentLife += 70;
return $"{pokemon} ha ganado 70HP.";
}
}

0 comments on commit e1ae562

Please sign in to comment.