Added check to see if all players are ready before setting to inGame

This commit is contained in:
Martin Berg Alstad 2023-07-11 14:31:50 +02:00
parent 5db0af5841
commit dfd8bbfc10
2 changed files with 22 additions and 4 deletions

View File

@ -202,9 +202,24 @@ public class GameGroupTests
public void SetAllInGame_SetsStateToInGame() public void SetAllInGame_SetsStateToInGame()
{ {
AddFullParty(); AddFullParty();
Assert.That(_gameGroup.Players, Has.All.Property(nameof(IPlayer.State)).Not.EqualTo(State.Ready)); _gameGroup.Players.ForEach(player => player.State = State.Ready);
_gameGroup.SetAllInGame(); Assert.That(_gameGroup.Players, Has.All.Property(nameof(IPlayer.State)).EqualTo(State.Ready));
Assert.That(_gameGroup.Players, Has.All.Property(nameof(IPlayer.State)).EqualTo(State.InGame));
var allInGame = _gameGroup.SetAllInGame();
Assert.Multiple(() =>
{
Assert.That(allInGame, Is.True);
Assert.That(_gameGroup.Players, Has.All.Property(nameof(IPlayer.State)).EqualTo(State.InGame));
});
}
[Test]
public void SetAllInGame_SetStateToInGame_WhenNotAllReady()
{
AddFullParty();
var allInGame = _gameGroup.SetAllInGame();
Assert.That(allInGame, Is.False);
} }
[Test] [Test]

View File

@ -32,8 +32,11 @@ public class GameGroup // TODO tests
return Players; return Players;
} }
public void SetAllInGame() public bool SetAllInGame()
{ {
if (Players.Any(player => player.State != State.Ready)) return false;
foreach (var player in Players) player.State = State.InGame; foreach (var player in Players) player.State = State.InGame;
return true;
} }
} }