Added some playerstates
This commit is contained in:
parent
49b8d05f97
commit
eaf17ef484
@ -5,6 +5,7 @@ using pacMan.Game;
|
|||||||
using pacMan.Game.Interfaces;
|
using pacMan.Game.Interfaces;
|
||||||
using pacMan.Game.Items;
|
using pacMan.Game.Items;
|
||||||
using pacMan.Interfaces;
|
using pacMan.Interfaces;
|
||||||
|
using pacMan.Services;
|
||||||
using pacMan.Utils;
|
using pacMan.Utils;
|
||||||
|
|
||||||
namespace pacMan.Controllers;
|
namespace pacMan.Controllers;
|
||||||
@ -14,6 +15,8 @@ namespace pacMan.Controllers;
|
|||||||
public class GameController : GenericController
|
public class GameController : GenericController
|
||||||
{
|
{
|
||||||
private readonly IDiceCup _diceCup;
|
private readonly IDiceCup _diceCup;
|
||||||
|
private GameGroup _group = new();
|
||||||
|
private IPlayer? _player;
|
||||||
|
|
||||||
public GameController(ILogger<GameController> logger, IWebSocketService wsService) : base(logger, wsService)
|
public GameController(ILogger<GameController> logger, IWebSocketService wsService) : base(logger, wsService)
|
||||||
{
|
{
|
||||||
@ -48,13 +51,17 @@ public class GameController : GenericController
|
|||||||
message.Data = rolls;
|
message.Data = rolls;
|
||||||
break;
|
break;
|
||||||
case GameAction.PlayerInfo:
|
case GameAction.PlayerInfo:
|
||||||
Player player = JsonSerializer.Deserialize<Player>(message.Data);
|
_player = JsonSerializer.Deserialize<Player>(message.Data);
|
||||||
var group = WsService.AddPlayer(player); // TODO missing some data?
|
_group = WsService.AddPlayer(_player); // TODO missing some data?
|
||||||
|
|
||||||
message.Data = group.Players;
|
message.Data = _group.Players;
|
||||||
break;
|
break;
|
||||||
case GameAction.Ready:
|
case GameAction.Ready:
|
||||||
// TODO select starter player
|
if (_player != null) _group.SetReady(_player);
|
||||||
|
if (_group.AllReady())
|
||||||
|
{
|
||||||
|
// TODO select starter player and send response
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Logger.Log(LogLevel.Information, "Forwarding message to all clients");
|
Logger.Log(LogLevel.Information, "Forwarding message to all clients");
|
||||||
|
@ -8,4 +8,12 @@ public interface IPlayer
|
|||||||
Character PacMan { get; init; }
|
Character PacMan { get; init; }
|
||||||
string Colour { get; init; }
|
string Colour { get; init; }
|
||||||
Box Box { get; init; }
|
Box Box { get; init; }
|
||||||
|
State State { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum State
|
||||||
|
{
|
||||||
|
WaitingForPlayers,
|
||||||
|
Ready,
|
||||||
|
InGame
|
||||||
}
|
}
|
@ -8,4 +8,5 @@ public class Player : IPlayer
|
|||||||
public required Character PacMan { get; init; }
|
public required Character PacMan { get; init; }
|
||||||
public required string Colour { get; init; }
|
public required string Colour { get; init; }
|
||||||
public required Box Box { get; init; }
|
public required Box Box { get; init; }
|
||||||
|
public State State { get; set; } = State.WaitingForPlayers;
|
||||||
}
|
}
|
@ -13,6 +13,7 @@ public class GameGroup
|
|||||||
if (Players.Count >= Rules.MaxPlayers) return false;
|
if (Players.Count >= Rules.MaxPlayers) return false;
|
||||||
if (Players.Exists(p => p.Name == player.Name)) return false;
|
if (Players.Exists(p => p.Name == player.Name)) return false;
|
||||||
|
|
||||||
|
player.State = State.WaitingForPlayers;
|
||||||
Players.Add(player);
|
Players.Add(player);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -21,4 +22,14 @@ public class GameGroup
|
|||||||
{
|
{
|
||||||
Connections?.Invoke(segment);
|
Connections?.Invoke(segment);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool AllReady()
|
||||||
|
{
|
||||||
|
return Players.All(p => p.State == State.Ready);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetReady(IPlayer player)
|
||||||
|
{
|
||||||
|
player.State = State.Ready;
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user