GameGroup implements IEnumerable, removed Getters from ActionService Properties

This commit is contained in:
Martin Berg Alstad 2023-07-12 21:33:52 +02:00
parent ab52179b5a
commit 0dc4a7b846
3 changed files with 11 additions and 6 deletions

View File

@ -141,8 +141,8 @@ public class ActionServiceTests
[Test]
public void Ready_TwoReady()
{
_service.Group.AddPlayer(_blackPlayer);
_service.Group.AddPlayer(_whitePlayer);
var group = new GameGroup { Players = { _blackPlayer, _whitePlayer } };
_service.Group = group;
_service.Player = _blackPlayer;
var result = _service.Ready();

View File

@ -9,15 +9,15 @@ namespace pacMan.Services;
public interface IActionService
{
IPlayer Player { get; set; }
GameGroup Group { get; set; }
IPlayer Player { set; }
GameGroup Group { set; }
void DoAction(ActionMessage message);
List<int> RollDice();
List<IPlayer> SetPlayerInfo(ActionMessage message);
object Ready();
}
public class ActionService : IActionService // TODO tests
public class ActionService : IActionService
{
private readonly IDiceCup _diceCup;
private readonly ILogger<ActionService> _logger;

View File

@ -1,15 +1,20 @@
using System.Collections;
using pacMan.Exceptions;
using pacMan.Game;
using pacMan.Game.Interfaces;
namespace pacMan.Services;
public class GameGroup
public class GameGroup : IEnumerable<IPlayer>
{
private readonly Random _random = new();
public List<IPlayer> Players { get; } = new();
public IPlayer RandomPlayer => Players[_random.Next(Players.Count)];
public IEnumerator<IPlayer> GetEnumerator() => Players.GetEnumerator();
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
public event Func<ArraySegment<byte>, Task>? Connections;
public bool AddPlayer(IPlayer player) // TODO if name exists, use that player instead