Пример #1
0
 /// <summary>
 /// Checks the players hand for valid plays, applying
 /// events and styles to cards based on whether or not
 /// they are playable
 /// </summary>
 void EvaluateHand()
 {
     if (durakGame.River.Count > 0)
     {
         for (int i = 0; i < durakGame.Players[0].Cards.Count; i++)
         {
             CardBox            pb    = pnlPlayerBottom.Controls[i] as CardBox;
             List <PlayingCard> cards = HumanPlayer.Cards;
             bool isValid             = (HumanPlayer.TurnStatus == TurnStatus.Attacking ? durakGame.IsValidAttack(cards[i]) : durakGame.IsValidDefence(cards[i]));
             if (!isValid)
             {
                 pb.SetToMonochrome();
             }
             else
             {
                 Console.WriteLine("Adding hover event to " + cards[i].ToString());
                 pb.MouseEnter += CardPop;
                 pb.MouseLeave += CardPop;
             }
         }
     }
     else
     {
         Console.WriteLine("Fresh attack. Adding all hover event");
         foreach (Control control in pnlPlayerBottom.Controls)
         {
             control.MouseEnter += CardPop;
             control.MouseLeave += CardPop;
         }
     }
 }
Пример #2
0
        /// <summary>
        /// Initializes game, draws cards
        /// </summary>
        public void InitiateGame()
        {
            pbTrump.Image = Image.FromFile(CardBox.GetImagePathFromCard(durakGame.TrumpCard));
            //Load card image
            pbDeck.Load(CardBox.GetImagePathFromCard());

            Refresh();
            //Initialize card deck count amount
            lblDeckCount.Text = durakGame.deck.Count.ToString();

            //Play super cool sound
            //source : https://freesound.org/people/mickmon/sounds/176862/
            SoundPlayer dealSound = new System.Media.SoundPlayer(RESOURCES_PATH + "deal.wav");

            dealSound.Play();

            //Deal cards
            gameStats.cardsDrawn = gameStats.cardsDrawn + DurakGame.STARTING_CARD_COUNT;
            for (int i = 0; i < DurakGame.STARTING_CARD_COUNT; i++)
            {
                DealCardToPanel(this.pnlPlayerBottom, durakGame.Players[0].Cards[i]);
                DealCardToPanel(this.pnlPlayerTop, durakGame.Players[1].Cards[i]);
                Wait(50);
            }
            this.txtMessages.Update();
            durakGame.TurnAttack();
        }
Пример #3
0
        /// <summary>
        /// Creates a new CardBox and deals it to the specified panel
        /// </summary>
        /// <param name="panel"></param>
        public void DealCardToPanel(Panel panel, PlayingCard card)
        {
            CardBox pbCard = new CardBox(card);

            pbCard.FaceDown();
            if (panel == pnlPlayerBottom || aiCardsVisible)
            {
                pbCard.FaceUp();
            }
            panel.Controls.Add(pbCard);
            AlignCards(panel);
        }
Пример #4
0
        /// <summary>
        /// CardClick(object sender, EventArgs e)
        ///         Occurs every time a user clicks a card
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        void CardClick(object sender, EventArgs e)
        {
            CardBox cb = (CardBox)sender;

            if (HumanPlayer.TurnStatus == TurnStatus.Attacking && durakGame.IsValidAttack(cb.Card) ||
                HumanPlayer.TurnStatus == TurnStatus.Defending && durakGame.IsValidDefence(cb.Card))
            {
                durakGame.RecieveCard(cb.Card);
            }
            else
            {
                durakGame.Print("\r" + cb.Card.ToString() + " is not a valid play!");
            }
        }
Пример #5
0
        /// <summary>
        /// Give river to a players hand
        /// </summary>
        /// <param name="player">Player to give river to</param>
        public void GiveRiver(IPlayer player)
        {
            Panel toPanel     = null;
            bool  putFaceDown = false;

            lblStatus.Text = player.Name + " takes the river!";
            Wait(200);
            if (player.GetType() == typeof(Player))
            {
                toPanel = pnlPlayerBottom;
            }
            else if (player.GetType() == typeof(ComputerPlayer))
            {
                toPanel     = pnlPlayerTop;
                putFaceDown = true;
            }

            for (int slide = 0; slide < 20; slide++)
            {
                for (int i = 0; i < pnlPlayArea.Controls.Count; i++)
                {
                    pnlPlayArea.Controls[i].Top += (toPanel == pnlPlayerBottom ? slide : -slide);
                }
                Wait(3);
            }

            for (int i = pnlPlayArea.Controls.Count - 1; i >= 0; i--)
            {
                CardBox cb = (CardBox)pnlPlayArea.Controls[i];
                if (!putFaceDown || aiCardsVisible)
                {
                    cb.FaceUp();
                }
                else
                {
                    cb.FaceDown();
                }
                toPanel.Controls.Add(cb);
                AlignCards(toPanel);
                Wait(100);
            }

            if (player.TurnStatus == TurnStatus.Attacking)
            {
                durakGame.NextAttacker();
            }
        }
Пример #6
0
        /// <summary>
        /// Play a players card
        /// </summary>
        /// <param name="cardIndex">Index of card to play</param>
        /// <param name="playerIndex">Index of player</param>
        public void PlayCardAt(int cardIndex, int playerIndex)
        {
            Panel   panel = (playerIndex == 0 ? pnlPlayerBottom : pnlPlayerTop);
            CardBox cb    = panel.Controls[cardIndex] as CardBox;

            if (playerIndex == 0)
            {
                EndHumanResponse();
            }
            else
            {
                Wait(AI_ATTACK_DELAY);
                cb.FaceUp();
            }
            cb.Size = CardBox.CARD_SIZE;
            pnlPlayArea.Controls.Add(cb);
            AlignCards(panel);
            AlignCards(pnlPlayArea);
        }
Пример #7
0
 /// <summary>
 /// Discard the river
 /// </summary>
 public void DiscardCards()
 {
     lblStatus.Text = durakGame.GetAttacker().Name + " gives up attacking!";
     Wait(200);
     if (pbDiscard.Image == null)
     {
         pbDiscard.Load(CardBox.GetImagePathFromCard());
     }
     for (int slide = 0; slide < 80; slide += 2)
     {
         for (int i = 0; i < pnlPlayArea.Controls.Count; i++)
         {
             CardBox cb = (CardBox)pnlPlayArea.Controls[i];
             cb.Left += slide;
             cb.Top  -= cb.Location.Y / 10;
         }
         Wait(3);
     }
     for (int i = pnlPlayArea.Controls.Count - 1; i >= 0; i--)
     {
         CardBox cb = (CardBox)pnlPlayArea.Controls[i];
         pnlPlayArea.Controls.Remove(cb);
     }
 }