From 5b27e0d23511ff442e9804ef3c122dd258708ea8 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 6 Nov 2024 16:10:34 -0300 Subject: [PATCH 1/2] historias de usuario 2 y 3 --- src/Library/Facade.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/Library/Facade.cs b/src/Library/Facade.cs index ed8e1dc..24926e2 100644 --- a/src/Library/Facade.cs +++ b/src/Library/Facade.cs @@ -7,11 +7,15 @@ public static class Facade private static WaitingList WaitingList { get; } = new WaitingList(); 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 no está en ninguna partida."; + } + string result = ""; foreach (IAttack atack in player.ActivePokemon.Attacks) { result += atack.Name + "\n"; @@ -20,6 +24,7 @@ public static string ShowAtacks(string playerName) return result; } + // historia de usuario 3 public static string ShowPokemonsHP(string playerName, string playerToCheckName = null) { Player player = GameList.FindPlayerByName(playerName); @@ -45,6 +50,7 @@ public static string ShowPokemonsHP(string playerName, string playerToCheckName return result; } } + return "El jugador no pertenece a tu partida."; } } From 715fa8c865bd73f22347e71b4c9e9bdb7f6ff4a6 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 6 Nov 2024 18:17:04 -0300 Subject: [PATCH 2/2] historias 9, 10 ,11 --- src/Library/Facade.cs | 112 ++++++++++++++++++++++++++++++---------- src/Library/GameList.cs | 8 +++ 2 files changed, 93 insertions(+), 27 deletions(-) diff --git a/src/Library/Facade.cs b/src/Library/Facade.cs index b2cbc23..9e0e5dd 100644 --- a/src/Library/Facade.cs +++ b/src/Library/Facade.cs @@ -14,7 +14,7 @@ public static string ShowAtacks(string playerName) 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."; } string result = ""; foreach (IAttack atack in player.ActivePokemon.Attacks) @@ -30,7 +30,7 @@ public static string ShowPokemonsHP(string playerName, string playerToCheckName { 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 = ""; @@ -42,16 +42,14 @@ public static string ShowPokemonsHP(string playerName, string playerToCheckName { 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."; } } @@ -59,27 +57,87 @@ 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)) { - return "El jugador no está en ninguna partida."; + 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 "No hay nadie esperando"; + } + string result = "Esperan: "; + foreach (Player player in WaitingList.Players) + { + result = result + player.Name + "; "; + } + + 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) + { + Player? opponent; + if (!OpponentProvided() && !SomebodyIsWaiting()) + return "No hay nadie esperando"; + if (!OpponentProvided()) + { + opponent = WaitingList.GetAnyoneWaiting(); + return CreateGame(playerName, opponent!.Name); } - foreach (Game game in GameList.Games) + opponent = WaitingList.FindPlayerByName(opponentName!); + if (!OpponentFound()) { - 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"; - } - } + 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; } } \ No newline at end of file diff --git a/src/Library/GameList.cs b/src/Library/GameList.cs index 31e3e46..07636ab 100644 --- a/src/Library/GameList.cs +++ b/src/Library/GameList.cs @@ -19,4 +19,12 @@ public Game AddGame(Player player1, Player player2) return player; return null; } + + public Game? FindGameByPlayer(Player player) + { + foreach (Game game in this.Games) + if (game.Players.Contains(player)) + return game; + return null; + } } \ No newline at end of file