/// <summary>
        /// Determines if the player can attack
        /// </summary>
        /// <param name="card"></param>
        /// <param name="game"></param>
        /// <returns></returns>
        public virtual bool Attack(Card card, CardGame game)
        {
            PlayArea area = (game as Durak).PlayArea;

            if (area.Count % 2 == 0 && this.Hand.AttackOptions(area).Contains(card)) // if the card can be played
            {
                return(true);
            }
            return(false);
        }
Exemple #2
0
        /// <summary>
        /// Initialize the game of durak
        /// </summary>
        public override void Initialize()
        {
            CurrentDeck = new Deck(this);
            CurrentDeck.Shuffle();
            TrumpCard = CurrentDeck.DrawCard(0); // first card drawn from deck at start of game
            TrumpSuit = TrumpCard.Suit;

            cardsInPlay = new PlayArea(this);
            discard     = new Cards();

            players = CurrentDeck.Deal(players);
        }
Exemple #3
0
        /// <summary>
        /// Returns the cards in this hand that can be played as a defence
        /// </summary>
        /// <param name="area"></param>
        /// <returns></returns>
        public Cards DefenceOptions(PlayArea area)
        {
            Cards playable = new Cards();
            Card  areaCard = area[area.Count - 1]; // last card played

            foreach (Card handCard in this)
            {
                if ((handCard.Suit == areaCard.Suit || handCard.Suit == CurrentGame.TrumpSuit) && handCard.Usable(areaCard, CurrentGame)) // same suit or trump suit and usable
                {
                    playable.Add(handCard);
                }
            }
            return(playable);
        }
Exemple #4
0
        /// <summary>
        /// Start a new turn
        /// </summary>
        /// <returns></returns>
        public override CardGame NextTurn()
        {
            if (PlayArea.Count % 2 == 0) // even amount of cards in PlayArea
            {
                foreach (Card card in PlayArea)
                {
                    Discard.Add(card); // discard the cards
                }
                PlayArea.Clear();
            }
            else
            {
                foreach (Player player in Players)
                {
                    if (player.Defender) // this player is defending
                    {
                        foreach (Card card in PlayArea)
                        {
                            player.Hand.Add(card); // player picks up PlayArea cards
                        }
                    }
                }
            }
            foreach (Player player in Players)
            {
                player.Hand.Equilize(CurrentDeck); // draws cards to desired hand amount
            }

            //Switch player roles
            bool temp = Players[0].Defender;

            Players[0].Attacker = Players[1].Attacker;
            Players[1].Defender = temp;

            PlayArea.Clear();
            MoveCount++;
            return(this);
        }
Exemple #5
0
        /// <summary>
        /// Returns the cards in this hand that can be played as an attack
        /// </summary>
        /// <param name="area"></param>
        /// <returns></returns>
        public Cards AttackOptions(PlayArea area)
        {
            Cards playable = new Cards();

            if (area.Count == 0) // no cards in play
            {
                playable = this; // all cards are playable
            }
            else
            {
                foreach (Card areaCard in area)
                {
                    foreach (Card handCard in this)
                    {
                        if (areaCard.Rank == handCard.Rank) // if the rank is in play
                        {
                            playable.Add(handCard);
                        }
                    }
                }
            }
            return(playable);
        }