basic mau
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user