Added the ability to choose your cardtype when playing a jack or the newly added joker
All checks were successful
Build Mau & Deploy Mau / build (push) Successful in 1m14s
Build Mau & Deploy Mau / deploy (push) Has been skipped

This commit is contained in:
DTieman
2024-04-19 22:10:21 +02:00
parent b3d8bbd50e
commit 56034b921f
6 changed files with 58 additions and 7 deletions

View File

@@ -30,7 +30,8 @@ public enum CardType
SPADES, SPADES,
HEARTS, HEARTS,
DIAMONDS, DIAMONDS,
CLUBS CLUBS,
JOKER
} }
public enum CardValue public enum CardValue
@@ -47,5 +48,7 @@ public enum CardValue
JACK, JACK,
QUEEN, QUEEN,
KING, KING,
ACE ACE,
RED,
BLACK
} }

View File

@@ -9,8 +9,15 @@ public class Deck
{ {
foreach (CardType cardType in Enum.GetValues(typeof(CardType))) 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))) foreach (CardValue cardValue in Enum.GetValues(typeof(CardValue)))
{ {
if (cardValue is CardValue.RED or CardValue.BLACK) continue;
UnusedDeck.Add(new Card(cardType, cardValue)); UnusedDeck.Add(new Card(cardType, cardValue));
} }
} }

View File

@@ -46,6 +46,17 @@ public class Game
PlayCard(player, card); PlayCard(player, card);
break; 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": case "DRAW":
DrawCard(player); DrawCard(player);
break; break;
@@ -66,6 +77,18 @@ public class Game
{ {
switch (card.CardValue) 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: case CardValue.TWO:
{ {
var nextPlayer = GetNextPlayer(); var nextPlayer = GetNextPlayer();
@@ -74,14 +97,18 @@ public class Game
{ {
nextPlayer.Hand.Add(drawnCard); nextPlayer.Hand.Add(drawnCard);
} }
CurrentPlayer.State = PlayerState.WAIT;
CurrentPlayer = GetNextPlayer(2); CurrentPlayer = GetNextPlayer(2);
CurrentPlayer.State = PlayerState.TURN;
break; break;
} }
case CardValue.SEVEN: case CardValue.SEVEN:
case CardValue.KING: case CardValue.KING:
break; break;
case CardValue.EIGHT: case CardValue.EIGHT:
CurrentPlayer.State = PlayerState.WAIT;
CurrentPlayer = GetNextPlayer(2); CurrentPlayer = GetNextPlayer(2);
CurrentPlayer.State = PlayerState.TURN;
break; break;
case CardValue.ACE: case CardValue.ACE:
if (Players.Count > 2) if (Players.Count > 2)
@@ -90,13 +117,15 @@ public class Game
CurrentPlayer = GetNextPlayer(); CurrentPlayer = GetNextPlayer();
} }
break; break;
case CardValue.JACK:
CurrentPlayer.State = PlayerState.CHOOSE;
break;
case CardValue.THREE: case CardValue.THREE:
case CardValue.FOUR: case CardValue.FOUR:
case CardValue.FIVE: case CardValue.FIVE:
case CardValue.SIX: case CardValue.SIX:
case CardValue.NINE: case CardValue.NINE:
case CardValue.TEN: case CardValue.TEN:
case CardValue.JACK:
case CardValue.QUEEN: case CardValue.QUEEN:
default: default:
CurrentPlayer = GetNextPlayer(); CurrentPlayer = GetNextPlayer();
@@ -108,6 +137,8 @@ public class Game
{ {
player.Hand.Add(Deck.DrawCard()); player.Hand.Add(Deck.DrawCard());
CurrentPlayer = GetNextPlayer(); CurrentPlayer = GetNextPlayer();
player.State = PlayerState.WAIT;
CurrentPlayer.State = PlayerState.TURN;
} }
private Player GetNextPlayer(int numberOfPlayers = 1) private Player GetNextPlayer(int numberOfPlayers = 1)
@@ -135,7 +166,7 @@ public class Game
private static bool IsCardPlayable(Card currentCard, Card playedCard) 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) private static bool IsCardInHand(IEnumerable<Card> hand, Card card)

View File

@@ -3,6 +3,7 @@
public class GameState public class GameState
{ {
public string PlayerName { get; set; } public string PlayerName { get; set; }
public string CurrentState { get; set; }
public List<string> Hand { get; set; } = new(); public List<string> Hand { get; set; } = new();
public string CurrentCard { get; set; } public string CurrentCard { get; set; }
public string CurrentPlayer { get; set; } public string CurrentPlayer { get; set; }
@@ -12,6 +13,7 @@ public class GameState
{ {
var p = game.GetPlayer(playerId); var p = game.GetPlayer(playerId);
PlayerName = p.Connection.ConnectionId; PlayerName = p.Connection.ConnectionId;
CurrentState = p.State.ToString();
foreach (var card in p.Hand) foreach (var card in p.Hand)
{ {
Hand.Add(card.ToString()); Hand.Add(card.ToString());
@@ -23,6 +25,6 @@ public class GameState
} }
CurrentCard = game.CurrentCard.ToString(); CurrentCard = game.CurrentCard.ToString();
CurrentPlayer = game.CurrentPlayer.Connection.ConnectionId;; CurrentPlayer = game.CurrentPlayer.Connection.ConnectionId;
} }
} }

View File

@@ -1,11 +1,11 @@
using System.Net.WebSockets; using MauMau_Server.Websockets;
using MauMau_Server.Websockets;
namespace MauMau_Server.Mau; namespace MauMau_Server.Mau;
public class Player public class Player
{ {
public ConnectionInstance Connection { get; set; } public ConnectionInstance Connection { get; set; }
public PlayerState State { get; set; } = PlayerState.WAIT;
public List<Card> Hand { get; set; } = new(); public List<Card> Hand { get; set; } = new();
public Player(ConnectionInstance connection) public Player(ConnectionInstance connection)

8
Mau/PlayerState.cs Normal file
View File

@@ -0,0 +1,8 @@
namespace MauMau_Server.Mau;
public enum PlayerState
{
TURN,
CHOOSE,
WAIT
}