public PlayerTurnContext( BaseRoundState state, Card trumpCard, int cardsLeftInDeck) { this.State = state; this.TrumpCard = trumpCard; this.CardsLeftInDeck = cardsLeftInDeck; }
public static bool CanChangeTrump(bool isThePlayerFirst, BaseRoundState state, Card trumpCard, ICollection<Card> playerCards) { if (!isThePlayerFirst) { return false; } if (!state.CanChangeTrump) { return false; } return playerCards.Contains(new Card(trumpCard.Suit, CardType.Nine)); }
public GameHand(PlayerPosition whoWillPlayFirst, IPlayer firstPlayer, IList<Card> firstPlayerCards, IPlayer secondPlayer, IList<Card> secondPlayerCards, BaseRoundState state, IDeck deck) { this.whoWillPlayFirst = whoWillPlayFirst; this.firstPlayer = firstPlayer; this.secondPlayer = secondPlayer; this.state = state; this.deck = deck; this.actionValidater = new PlayerActionValidater(); this.firstPlayerCards = firstPlayerCards; this.secondPlayerCards = secondPlayerCards; this.whoClosedTheGame = PlayerPosition.NoOne; }
public static bool CanCloseGame(bool isThePlayerFirst, BaseRoundState state) { return isThePlayerFirst && state.CanClose; }
public void SetState(BaseRoundState newState) { this.state = newState; }
private PlayerAction FirstPlayerTurn(IPlayer firstToPlay, PlayerTurnContext context ) { var firstToPlayTurn = firstToPlay.GetTurn( context, this.actionValidater); if (firstToPlayTurn.Type == PlayerActionType.CloseGame) { this.state.Close(); context.State = new FinalRoundState(); this.state = new FinalRoundState(); if (firstToPlay == this.firstPlayer) { this.whoClosedTheGame = PlayerPosition.FirstPlayer; } else { this.whoClosedTheGame = PlayerPosition.SecondPlayer; } } if (firstToPlayTurn.Type == PlayerActionType.ChangeTrump) { var changeTrump = new Card(this.deck.GetTrumpCard.Suit, CardType.Nine); var oldTrump = this.deck.GetTrumpCard; context.TrumpCard = oldTrump; this.deck.ChangeTrumpCard(changeTrump); if (firstToPlay == this.firstPlayer) { this.firstPlayerCards.Remove(changeTrump); this.firstPlayerCards.Add(oldTrump); this.firstPlayer.AddCard(oldTrump); } else { this.secondPlayerCards.Remove(changeTrump); this.secondPlayerCards.Add(oldTrump); this.secondPlayer.AddCard(oldTrump); } } return firstToPlayTurn; }