Exemplo n.º 1
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void btnForfeit_Click(object sender, RoutedEventArgs e)
 {
     if (GameUtil.ShallIDoThisForYou("Do you wish to forfeit your turn?"))
     {
         m_Game.ForfeitTurn();
     }
 }
Exemplo n.º 2
0
        /// <summary>
        /// Handles when the done button has been clicked
        /// </summary>
        /// <param name="bClickedByHuman"></param>
        public void DoneClicked(bool bClickedByHuman)
        {
            Round curRound = m_Rounds[m_Rounds.Count - 1];

            curRound.Expand();
            Turn curTurn  = curRound.GetCurrentTurn();
            Turn prevTurn = (Turn)curTurn.Clone();

            prevTurn--;
            Player curPlayer  = curTurn.GetPlayer();
            Player prevPlayer = prevTurn.GetPlayer();
            Hand   prevHand   = prevTurn.GetHand();
            Hand   curHand    = curTurn.GetHand();

            if (curTurn.GetPlayer().ID == prevTurn.GetPlayer().ID)
            {
                if (!curTurn.isDefending())//impossible to defend on the first turn
                {
                    if (!bClickedByHuman)
                    {
                        curHand = curPlayer.Attack(prevHand);//a player object may attack, only if it's not human
                        foreach (PlayingCard card in curHand)
                        {
                            m_Gg.m_BattleArea.AddAttackCard(new CardBox(card, Orientation.Vertical, curTurn.GetHashCode()));
                            curPlayer.m_Hand -= card;//remove the card from the player's hand
                            WriteToLog("Player " + prevTurn.GetPlayer().ID.ToString() + " " + ((!(PlayerType.human == prevTurn.GetPlayer().GetMode())) ? "computer" : "human")
                                       + " attacked using " + card.ToString());
                        }
                        curTurn.SetHand(curHand);
                        if (0 == curHand.Count)
                        {
                            WriteToLog("Player " + prevTurn.GetPlayer().ID.ToString() + " " + ((!(PlayerType.human == prevTurn.GetPlayer().GetMode())) ? "computer" : "human")
                                       + " player (prev turn) sucessfully attacked/defended");
                        }
                        m_Gg.UpdateElements(m_Players);//update UI
                    }
                }
                if (false == btnDoneGuard)
                {
                    Timed_Response(ResponseType.next_turn);//timed response gives time for the user to view cards on the table
                }
            }
            else
            {
                int iLoserId = 0;//used to track loser of this round. The loser will have the first turn in next round
                if (!bClickedByHuman)
                {
                    if (false == btnDoneGuard)
                    {
                        if (curTurn.GetPlayer().CanDefend(prevHand))
                        {
                            curHand = curPlayer.MakeDefense(prevHand);
                            foreach (PlayingCard card in curHand)
                            {
                                m_Gg.m_BattleArea.AddDefenseCard(new CardBox(card, Orientation.Vertical, curTurn.GetHashCode()));
                                curPlayer.m_Hand -= card;
                                WriteToLog("Player " + prevTurn.GetPlayer().ID.ToString() + " " + ((!(PlayerType.human == prevTurn.GetPlayer().GetMode())) ? "computer" : "human")
                                           + " defended using " + card.ToString());
                            }
                            curTurn.SetHand(curHand);//override any existing hand
                            if (0 == curHand.Count)
                            {
                                WriteToLog("Player " + prevTurn.GetPlayer().ID.ToString() + " " + ((!(PlayerType.human == prevTurn.GetPlayer().GetMode())) ? "computer" : "human")
                                           + " player (prev turn) sucessfully attacked/defended");
                                iLoserId = prevTurn.GetPlayer().ID;
                            }
                        }
                        else
                        {
                            iLoserId = ProcessLoser(prevTurn, prevHand, prevPlayer.ID, curTurn, curHand, bClickedByHuman);
                        }
                    }
                }
                //need to get the current count of cards in each player's hands
                int  ranksInPrevHand = GameUtil.getCountMaxRanksInHand(prevHand);
                int  ranksInCurHand  = GameUtil.getCountMaxRanksInHand(curHand);
                bool bTemp           = GameUtil.doHandSuitsMatch(prevHand, curHand);
                if (ranksInPrevHand == ranksInCurHand)//test for equal hands, do nothing if not equals
                {
                    if (false == btnDoneGuard)
                    {
                        if (prevHand > curHand)//compare
                        {
                            iLoserId = ProcessLoser(prevTurn, prevHand, prevPlayer.ID, curTurn, curHand, bClickedByHuman);
                        }
                        else if (curHand > prevHand)
                        {
                            iLoserId = ProcessLoser(curTurn, curHand, curPlayer.ID, prevTurn, prevHand, bClickedByHuman);
                        }
                        else
                        {//draw
                            MessageBox.Show("Draw");
                        }
                    }
                }
                else
                {
                    if (curTurn.isDefending()) //attacking humans are free to place as many cards on the board as they want, errors to be caught by Cardbox_Clicked method
                    {
                        if (bClickedByHuman)   //notify user of their mistake
                        {
                            if (GameUtil.ShallIDoThisForYou("You did not place the correct amount of cards in the battle area. Forfeit?"))
                            {
                                WriteToLog("Player " + prevTurn.GetPlayer().ID.ToString() + " " + ((!(PlayerType.human == prevTurn.GetPlayer().GetMode())) ? "computer" : "human")
                                           + " player (prev turn) sucessfully attacked/defended");
                                iLoserId = prevTurn.GetPlayer().ID;
                            }
                        }
                    }
                }
                m_Gg.UpdateElements(m_Players); //refresh gui with new placements
                DoneWithRound(iLoserId);        //iLoserId used to set player order in the next round
                curRound.m_CurrentTurn--;
            }
            curRound.m_CurrentTurn++;
            curRound.outputStatusToWindow(ref m_Gg);
            curRound.updateBoldedStatus(curRound.GetCurrentTurn(), ref m_Gg);
        }