basic mau

This commit is contained in:
2023-03-16 17:11:15 +01:00
parent 4f85f6f793
commit c902493e28
5 changed files with 76 additions and 9 deletions

View File

@@ -8,9 +8,7 @@ namespace MauMau_Server.Websockets;
public class Room
{
private readonly Dictionary<string, WebSocket> _connections = new();
private readonly Deck _deck = new();
private Card currentCard;
private List<Card> hand = new();
private Game _game = new();
public async Task InstantiateConnection(WebSocket socket)
{
@@ -20,16 +18,15 @@ public class Room
private async Task HandleConnection(WebSocket socket, string socketId)
{
hand = _deck.DrawCards(8);
SendAsync(socket, JsonSerializer.Serialize(new HandDTO(hand)));
BroadcastAsync(JsonSerializer.Serialize(new GameState(_game)));
var buffer = EmptyBuffer();
var result = await ReceiveAsync(socket, buffer);
while (!result.CloseStatus.HasValue)
{
var slicedBuffer = buffer[0..result.Count];
var playedCard = JsonSerializer.Deserialize<CardDTO>(slicedBuffer).ToCard();
BroadcastAsync(JsonSerializer.Serialize(playedCard.ToString()));
SendAsync(socket, JsonSerializer.Serialize(new HandDTO(hand)));
_game.PlayCard(playedCard);
BroadcastAsync(JsonSerializer.Serialize(new GameState(_game)));
buffer = EmptyBuffer();
result = await ReceiveAsync(socket, buffer);
}