GameGroup implements IEnumerable, removed Getters from ActionService Properties
This commit is contained in:
parent
ab52179b5a
commit
0dc4a7b846
@ -141,8 +141,8 @@ public class ActionServiceTests
|
|||||||
[Test]
|
[Test]
|
||||||
public void Ready_TwoReady()
|
public void Ready_TwoReady()
|
||||||
{
|
{
|
||||||
_service.Group.AddPlayer(_blackPlayer);
|
var group = new GameGroup { Players = { _blackPlayer, _whitePlayer } };
|
||||||
_service.Group.AddPlayer(_whitePlayer);
|
_service.Group = group;
|
||||||
_service.Player = _blackPlayer;
|
_service.Player = _blackPlayer;
|
||||||
|
|
||||||
var result = _service.Ready();
|
var result = _service.Ready();
|
||||||
|
@ -9,15 +9,15 @@ namespace pacMan.Services;
|
|||||||
|
|
||||||
public interface IActionService
|
public interface IActionService
|
||||||
{
|
{
|
||||||
IPlayer Player { get; set; }
|
IPlayer Player { set; }
|
||||||
GameGroup Group { get; set; }
|
GameGroup Group { set; }
|
||||||
void DoAction(ActionMessage message);
|
void DoAction(ActionMessage message);
|
||||||
List<int> RollDice();
|
List<int> RollDice();
|
||||||
List<IPlayer> SetPlayerInfo(ActionMessage message);
|
List<IPlayer> SetPlayerInfo(ActionMessage message);
|
||||||
object Ready();
|
object Ready();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class ActionService : IActionService // TODO tests
|
public class ActionService : IActionService
|
||||||
{
|
{
|
||||||
private readonly IDiceCup _diceCup;
|
private readonly IDiceCup _diceCup;
|
||||||
private readonly ILogger<ActionService> _logger;
|
private readonly ILogger<ActionService> _logger;
|
||||||
|
@ -1,15 +1,20 @@
|
|||||||
|
using System.Collections;
|
||||||
using pacMan.Exceptions;
|
using pacMan.Exceptions;
|
||||||
using pacMan.Game;
|
using pacMan.Game;
|
||||||
using pacMan.Game.Interfaces;
|
using pacMan.Game.Interfaces;
|
||||||
|
|
||||||
namespace pacMan.Services;
|
namespace pacMan.Services;
|
||||||
|
|
||||||
public class GameGroup
|
public class GameGroup : IEnumerable<IPlayer>
|
||||||
{
|
{
|
||||||
private readonly Random _random = new();
|
private readonly Random _random = new();
|
||||||
public List<IPlayer> Players { get; } = new();
|
public List<IPlayer> Players { get; } = new();
|
||||||
|
|
||||||
public IPlayer RandomPlayer => Players[_random.Next(Players.Count)];
|
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 event Func<ArraySegment<byte>, Task>? Connections;
|
||||||
|
|
||||||
public bool AddPlayer(IPlayer player) // TODO if name exists, use that player instead
|
public bool AddPlayer(IPlayer player) // TODO if name exists, use that player instead
|
||||||
|
Loading…
x
Reference in New Issue
Block a user