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 waiting y battlle list #8

Merged
merged 4 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
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];
}
}
Loading