refactor and chat base

This commit is contained in:
2023-04-22 12:42:02 +02:00
parent 2c7e7303bc
commit e4769d4b99
11 changed files with 231 additions and 144 deletions

View File

@@ -1,5 +1,6 @@
using System.Net.WebSockets;
using System.Text.Json;
using MauMau_Server.Websockets;
namespace MauMau_Server.Mau;
@@ -17,9 +18,9 @@ public class Game
Deck.AddCardToUsedDeck(CurrentCard);
}
public void AddPlayerToGame(string playerId, WebSocket socket)
public void AddPlayerToGame(ConnectionInstance connection)
{
var player = new Player("Koetje " + playerId.Split('-')[0], playerId, socket)
var player = new Player(connection)
{
Hand = Deck.DrawCards(8)
};

View File

@@ -11,7 +11,7 @@ public class GameState
public GameState(Game game, string playerId)
{
var p = game.GetPlayer(playerId);
PlayerName = p.Name;
PlayerName = p.Connection.ConnectionId;
foreach (var card in p.Hand)
{
Hand.Add(card.ToString());
@@ -19,10 +19,10 @@ public class GameState
foreach (var player in game.Players)
{
Players.Add(player.Name);
Players.Add(p.Connection.ConnectionId);
}
CurrentCard = game.CurrentCard.ToString();
CurrentPlayer = game.CurrentPlayer.Name;
CurrentPlayer = game.CurrentPlayer.Connection.ConnectionId;;
}
}

View File

@@ -1,20 +1,17 @@
using System.Net.WebSockets;
using MauMau_Server.Websockets;
namespace MauMau_Server.Mau;
public class Player
{
public string Name { get; set; }
public string PlayerId { get; set; }
public WebSocket Socket { get; set; }
public ConnectionInstance Connection { get; set; }
public List<Card> Hand { get; set; } = new();
public Player(string name, string playerId, WebSocket socket)
public Player(ConnectionInstance connection)
{
Name = name;
PlayerId = playerId;
Socket = socket;
Connection = connection;
}
public bool IsMe(string playerId) => PlayerId == playerId;
public bool IsMe(string playerId) => Connection.ConnectionId == playerId;
}