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

@@ -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)