From 6cfacdf2a78607ada6b2087da47aaeab106abd1b Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 11 Oct 2024 20:20:51 -0300 Subject: [PATCH 1/2] solucion player --- src/Library/Player.cs | 30 ++++++++++++++++++++------ test/Library.Tests/PlayerTest.cs | 37 ++++++++++++++++++++++++++++++++ 2 files changed, 61 insertions(+), 6 deletions(-) create mode 100644 test/Library.Tests/PlayerTest.cs diff --git a/src/Library/Player.cs b/src/Library/Player.cs index daccd00..d8a4ee3 100644 --- a/src/Library/Player.cs +++ b/src/Library/Player.cs @@ -3,22 +3,40 @@ public class Player { - public string Name; + public string Name { get; } public List PokemonTeam { get; set;} = new List (); - IPokemon ActivePokemon; + public IPokemon ActivePokemon { get; private set; } + public Player(string name) + { + this.Name = name; + } + public IAction ChooseAction() { - + // mostrar movimientos en pantalla, podría llamar a otra + // clase para imprimir en pantalla las opciones + int x = 0;//obtengo la selección del usuario, por ejemplo le pido un int + if (x < 5) + { + return this.ActivePokemon.Moves[x - 1]; + } + else + { + IAction action = new Pokeball(); + return action;; + } + } public void AddToTeam(IPokemon pokemon) { - + if(this.PokemonTeam.Count < 6) + this.PokemonTeam.Add(pokemon); } - public void ChoosePokemon() + public void ChangeActivePokemon(IPokemon pokemon) { - + this.ActivePokemon = pokemon; } } diff --git a/test/Library.Tests/PlayerTest.cs b/test/Library.Tests/PlayerTest.cs new file mode 100644 index 0000000..0449307 --- /dev/null +++ b/test/Library.Tests/PlayerTest.cs @@ -0,0 +1,37 @@ +using Library; + +namespace Library.Tests; + +[TestFixture] +[TestOf(typeof(Player))] +public class PlayerTest +{ + private Player player; + private Charizard charizard1; + private Charizard charizard2; + + [SetUp] + public void SetUp() + { + player = new Player("jugador1"); + charizard1 = new Charizard(); + charizard2 = new Charizard(); + + } + + [Test] + public void TestAddToTeam() + { + player.AddToTeam(charizard1); + Assert.That(player.PokemonTeam.Contains(charizard1)); + player.AddToTeam(charizard2); + Assert.That(player.PokemonTeam.Count, Is.EqualTo(2)); + } + + [Test] + public void TestChangeActivePokemon() + { + player.ChangeActivePokemon(charizard1); + Assert.That(player.ActivePokemon,Is.EqualTo(charizard1)); + } +} \ No newline at end of file From 6ce9fc1dc548ea2cea9a44538acb4f7fd11f8482 Mon Sep 17 00:00:00 2001 From: unknown Date: Wed, 6 Nov 2024 09:58:51 -0300 Subject: [PATCH 2/2] waitinglist, battlelist --- src/Library/BattleList.cs | 13 ++++++++++ src/Library/WaitingList.cs | 51 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) create mode 100644 src/Library/BattleList.cs create mode 100644 src/Library/WaitingList.cs diff --git a/src/Library/BattleList.cs b/src/Library/BattleList.cs new file mode 100644 index 0000000..cadf5b7 --- /dev/null +++ b/src/Library/BattleList.cs @@ -0,0 +1,13 @@ +namespace Library; + +public class BattleList +{ + public List Games { get; private set; } = new List(); + + public Game AddGame(Player player1, Player player2) + { + Game game = new Game(player1, player2); + this.Games.Add(game); + return game; + } +} \ No newline at end of file diff --git a/src/Library/WaitingList.cs b/src/Library/WaitingList.cs new file mode 100644 index 0000000..5be3b62 --- /dev/null +++ b/src/Library/WaitingList.cs @@ -0,0 +1,51 @@ +namespace Library; + +public class WaitingList +{ + public List Players { get; private set; }= new List(); + + public int Count + { + get { return this.Players.Count; } + } + + public bool AddPlayer(string playerName) + { + if (string.IsNullOrEmpty(playerName)) + throw new ArgumentException(nameof(playerName)); + if (this.FindPlayerByName(playerName) != null) + return false; + this.Players.Add(new Player(playerName)); + return true; + } + + public bool RemovePlayer(string playerName) + { + Player? player = FindPlayerByName(playerName); + if (player == null) + return false; + this.Players.Remove(player); + return true; + } + + public Player? FindPlayerByName(string playerName) + { + { + foreach (Player player in this.Players) + { + if (player.Name == playerName) + { + return player; + } + } + + return null; + } + } + public Player? GetAnyoneWaiting() + { + Random random = new Random(); + int randomNumber = random.Next(0, this.Count); + return this.Players[randomNumber]; + } +} \ No newline at end of file