Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

H2 facade #17

Merged
merged 7 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
124 changes: 94 additions & 30 deletions src/Library/Facade.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,19 @@

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

public static GameList GameList{ get;} = new GameList();
public static GameList GameList{ get; } = new GameList();
// historia de usuario 2
public static string ShowAtacks(string playerName)
{
//chequear que este en la partida
string result = "";

Player player = GameList.FindPlayerByName(playerName);
if (player != null)
{
return $"El jugador {playerName} no está en ninguna partida.";
}
string result = "";
foreach (IAttack atack in player.ActivePokemon.Attacks)
{
result += atack.Name + "\n";
Expand All @@ -20,11 +25,12 @@
return result;
}

// historia de usuario 3
public static string ShowPokemonsHP(string playerName, string playerToCheckName = null)
{
Player player = GameList.FindPlayerByName(playerName);
if (player == null)
return "El jugador no está en ninguna partida.";
return $"El jugador {playerName} no está en ninguna partida.";
if (playerToCheckName == null)
{
string result = "";
Expand All @@ -36,44 +42,102 @@
{
Player playerToCheck = GameList.FindPlayerByName(playerToCheckName);
string result = "";
foreach (Game game in GameList.Games)
Game game = GameList.FindGameByPlayer(player);
if (game.Players.Contains(player) && game.Players.Contains(playerToCheck))
{
if (game.Players.Contains(player) && game.Players.Contains(playerToCheck))
{
foreach (Pokemon pokemon in playerToCheck.PokemonTeam)
result += pokemon.Name + ": " + pokemon.GetLife() + "\n";
return result;
}
foreach (Pokemon pokemon in playerToCheck.PokemonTeam)
result += pokemon.Name + ": " + pokemon.GetLife() + "\n";
return result;
}
return "El jugador no pertenece a tu partida.";
return $"El jugador {playerToCheckName} no está en tu partida.";
}
}

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))
{
int activePlayerIndex = game.ActivePlayer;
Player activePlayer = game.Players[activePlayerIndex];
if (activePlayer.Name == playerName)
return "Es tu turno:\n" + opciones;
return "No es tu turno";
}
return null;
}
// historia de usuario 9
public static string AddPlayerToWaitingList(string playerName)
{
if (WaitingList.AddPlayer(playerName))
return $"{playerName} agregado a la lista de espera";
return $"{playerName} ya está en la lista de espera";
}

public static string RemovePlayerFromWaitingList(string playerName)
{
if (WaitingList.RemovePlayer(playerName))
return $"{playerName} removido de la lista de espera";
return $"{playerName} no está en la lista de espera";
}
//historia de usuario 10
public static string GetAllPlayersWaiting()
{
if (WaitingList.Count == 0)
{
return "El jugador no está en ninguna partida.";
return "No hay nadie esperando";
}

string result = "Esperan: ";
foreach (Player player in WaitingList.Players)
{
result = result + player.Name + "; ";
}
foreach (Game game in GameList.Games)

return result;
}
//historia de usuario 11
private static string CreateGame(string playerName, string opponentName)
{
Player player = WaitingList.FindPlayerByName(playerName);
Player opponent = WaitingList.FindPlayerByName(opponentName);
WaitingList.RemovePlayer(playerName);
WaitingList.RemovePlayer(opponentName);
GameList.AddGame(player, opponent);
return $"Comienza {playerName} vs {opponentName}";
}

public static string StartBattle(string playerName, string? opponentName)

Check warning on line 114 in src/Library/Facade.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.
{
Player? opponent;

Check warning on line 116 in src/Library/Facade.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.
if (!OpponentProvided() && !SomebodyIsWaiting())
return "No hay nadie esperando";
if (!OpponentProvided())
{
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))
{
int activePlayerIndex = game.ActivePlayer;
Player activePlayer = game.Players[activePlayerIndex];
if (activePlayer.Name == playerName)
{
return "Es tu turno:\n" + opciones;
}
else
{
return "no puedes jugar porque no es tu turno";
}
}
opponent = WaitingList.GetAnyoneWaiting();
return CreateGame(playerName, opponent!.Name);
}
opponent = WaitingList.FindPlayerByName(opponentName!);
if (!OpponentFound())
{
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;
}
return null;
}
}
8 changes: 8 additions & 0 deletions src/Library/GameList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
return game;
}

public Player? FindPlayerByName(string playerName)

Check warning on line 14 in src/Library/GameList.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 (Game game in this.Games)
foreach (Player player in game.Players)
Expand All @@ -19,4 +19,12 @@
return player;
return null;
}

public Game? FindGameByPlayer(Player player)

Check warning on line 23 in src/Library/GameList.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 (Game game in this.Games)
if (game.Players.Contains(player))
return game;
return null;
}
}
Loading