developmaunt -> mauster #1
@@ -30,7 +30,8 @@ public enum CardType
|
||||
SPADES,
|
||||
HEARTS,
|
||||
DIAMONDS,
|
||||
CLUBS
|
||||
CLUBS,
|
||||
JOKER
|
||||
}
|
||||
|
||||
public enum CardValue
|
||||
@@ -47,5 +48,7 @@ public enum CardValue
|
||||
JACK,
|
||||
QUEEN,
|
||||
KING,
|
||||
ACE
|
||||
ACE,
|
||||
RED,
|
||||
BLACK
|
||||
}
|
||||
@@ -9,8 +9,15 @@ public class Deck
|
||||
{
|
||||
foreach (CardType cardType in Enum.GetValues(typeof(CardType)))
|
||||
{
|
||||
if (cardType == CardType.JOKER)
|
||||
{
|
||||
UnusedDeck.Add(new Card(cardType, CardValue.RED));
|
||||
UnusedDeck.Add(new Card(cardType, CardValue.BLACK));
|
||||
continue;
|
||||
}
|
||||
foreach (CardValue cardValue in Enum.GetValues(typeof(CardValue)))
|
||||
{
|
||||
if (cardValue is CardValue.RED or CardValue.BLACK) continue;
|
||||
UnusedDeck.Add(new Card(cardType, cardValue));
|
||||
}
|
||||
}
|
||||
|
||||
35
Mau/Game.cs
35
Mau/Game.cs
@@ -46,6 +46,17 @@ public class Game
|
||||
PlayCard(player, card);
|
||||
break;
|
||||
}
|
||||
case "CHOOSE":
|
||||
var choice = action.Data;
|
||||
if (!Enum.TryParse(choice, out CardType cardType))
|
||||
{
|
||||
break;
|
||||
}
|
||||
CurrentCard = new Card(cardType, CardValue.JACK);
|
||||
CurrentPlayer.State = PlayerState.WAIT;
|
||||
CurrentPlayer = CurrentCard.CardType == CardType.JOKER ? GetNextPlayer() : GetNextPlayer(2);
|
||||
CurrentPlayer.State = PlayerState.TURN;
|
||||
break;
|
||||
case "DRAW":
|
||||
DrawCard(player);
|
||||
break;
|
||||
@@ -66,6 +77,18 @@ public class Game
|
||||
{
|
||||
switch (card.CardValue)
|
||||
{
|
||||
case CardValue.RED:
|
||||
case CardValue.BLACK:
|
||||
{
|
||||
var nextPlayer = GetNextPlayer();
|
||||
var cardsToDraw = Deck.DrawCards(5);
|
||||
foreach (var drawnCard in cardsToDraw)
|
||||
{
|
||||
nextPlayer.Hand.Add(drawnCard);
|
||||
}
|
||||
CurrentPlayer.State = PlayerState.CHOOSE;
|
||||
break;
|
||||
}
|
||||
case CardValue.TWO:
|
||||
{
|
||||
var nextPlayer = GetNextPlayer();
|
||||
@@ -74,14 +97,18 @@ public class Game
|
||||
{
|
||||
nextPlayer.Hand.Add(drawnCard);
|
||||
}
|
||||
CurrentPlayer.State = PlayerState.WAIT;
|
||||
CurrentPlayer = GetNextPlayer(2);
|
||||
CurrentPlayer.State = PlayerState.TURN;
|
||||
break;
|
||||
}
|
||||
case CardValue.SEVEN:
|
||||
case CardValue.KING:
|
||||
break;
|
||||
case CardValue.EIGHT:
|
||||
CurrentPlayer.State = PlayerState.WAIT;
|
||||
CurrentPlayer = GetNextPlayer(2);
|
||||
CurrentPlayer.State = PlayerState.TURN;
|
||||
break;
|
||||
case CardValue.ACE:
|
||||
if (Players.Count > 2)
|
||||
@@ -90,13 +117,15 @@ public class Game
|
||||
CurrentPlayer = GetNextPlayer();
|
||||
}
|
||||
break;
|
||||
case CardValue.JACK:
|
||||
CurrentPlayer.State = PlayerState.CHOOSE;
|
||||
break;
|
||||
case CardValue.THREE:
|
||||
case CardValue.FOUR:
|
||||
case CardValue.FIVE:
|
||||
case CardValue.SIX:
|
||||
case CardValue.NINE:
|
||||
case CardValue.TEN:
|
||||
case CardValue.JACK:
|
||||
case CardValue.QUEEN:
|
||||
default:
|
||||
CurrentPlayer = GetNextPlayer();
|
||||
@@ -108,6 +137,8 @@ public class Game
|
||||
{
|
||||
player.Hand.Add(Deck.DrawCard());
|
||||
CurrentPlayer = GetNextPlayer();
|
||||
player.State = PlayerState.WAIT;
|
||||
CurrentPlayer.State = PlayerState.TURN;
|
||||
}
|
||||
|
||||
private Player GetNextPlayer(int numberOfPlayers = 1)
|
||||
@@ -135,7 +166,7 @@ public class Game
|
||||
|
||||
private static bool IsCardPlayable(Card currentCard, Card playedCard)
|
||||
{
|
||||
return IsSameCardType(currentCard, playedCard) || IsSameCardValue(currentCard, playedCard);
|
||||
return IsSameCardType(currentCard, playedCard) || IsSameCardValue(currentCard, playedCard) || playedCard.CardType == CardType.JOKER;
|
||||
}
|
||||
|
||||
private static bool IsCardInHand(IEnumerable<Card> hand, Card card)
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
public class GameState
|
||||
{
|
||||
public string PlayerName { get; set; }
|
||||
public string CurrentState { get; set; }
|
||||
public List<string> Hand { get; set; } = new();
|
||||
public string CurrentCard { get; set; }
|
||||
public string CurrentPlayer { get; set; }
|
||||
@@ -12,6 +13,7 @@ public class GameState
|
||||
{
|
||||
var p = game.GetPlayer(playerId);
|
||||
PlayerName = p.Connection.ConnectionId;
|
||||
CurrentState = p.State.ToString();
|
||||
foreach (var card in p.Hand)
|
||||
{
|
||||
Hand.Add(card.ToString());
|
||||
@@ -23,6 +25,6 @@ public class GameState
|
||||
}
|
||||
|
||||
CurrentCard = game.CurrentCard.ToString();
|
||||
CurrentPlayer = game.CurrentPlayer.Connection.ConnectionId;;
|
||||
CurrentPlayer = game.CurrentPlayer.Connection.ConnectionId;
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,11 @@
|
||||
using System.Net.WebSockets;
|
||||
using MauMau_Server.Websockets;
|
||||
using MauMau_Server.Websockets;
|
||||
|
||||
namespace MauMau_Server.Mau;
|
||||
|
||||
public class Player
|
||||
{
|
||||
public ConnectionInstance Connection { get; set; }
|
||||
public PlayerState State { get; set; } = PlayerState.WAIT;
|
||||
public List<Card> Hand { get; set; } = new();
|
||||
|
||||
public Player(ConnectionInstance connection)
|
||||
|
||||
8
Mau/PlayerState.cs
Normal file
8
Mau/PlayerState.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace MauMau_Server.Mau;
|
||||
|
||||
public enum PlayerState
|
||||
{
|
||||
TURN,
|
||||
CHOOSE,
|
||||
WAIT
|
||||
}
|
||||
Reference in New Issue
Block a user