Skip to content

Commit

Permalink
Merge pull request #8 from ucudal/h2-lobby
Browse files Browse the repository at this point in the history
H2 waiting y battlle list
  • Loading branch information
mariaines-barral authored Nov 6, 2024
2 parents 15b2b96 + 6ce9fc1 commit 8b80d98
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/Library/BattleList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Library;

public class BattleList
{
public List<Game> Games { get; private set; } = new List<Game>();

public Game AddGame(Player player1, Player player2)
{
Game game = new Game(player1, player2);
this.Games.Add(game);
return game;
}
}
1 change: 1 addition & 0 deletions src/Library/Player.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
namespace Library;
using Library;

public class Player
{
Expand Down
51 changes: 51 additions & 0 deletions src/Library/WaitingList.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
namespace Library;

public class WaitingList
{
public List<Player> Players { get; private set; }= new List<Player>();

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)

Check warning on line 31 in src/Library/WaitingList.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.

Check warning on line 31 in src/Library/WaitingList.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 (Player player in this.Players)
{
if (player.Name == playerName)
{
return player;
}
}

return null;
}
}
public Player? GetAnyoneWaiting()

Check warning on line 45 in src/Library/WaitingList.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.

Check warning on line 45 in src/Library/WaitingList.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.
{
Random random = new Random();
int randomNumber = random.Next(0, this.Count);
return this.Players[randomNumber];
}
}

0 comments on commit 8b80d98

Please sign in to comment.