-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from ucudal/h2-lobby
H2 waiting y battlle list
- Loading branch information
Showing
3 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
namespace Library; | ||
using Library; | ||
|
||
public class Player | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
|
||
{ | ||
{ | ||
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
|
||
{ | ||
Random random = new Random(); | ||
int randomNumber = random.Next(0, this.Count); | ||
return this.Players[randomNumber]; | ||
} | ||
} |