Esempio n. 1
0
        private void ComputerMoves()
        {
            while (won == false && TurnsManager.GetCurrentTurn() != PLAYER_TURN)
            {
                fourburn = false;
                Card burncheckfour          = null;
                bool HighestCardChangeCheck = false;
                Thread.Sleep(1000);
                switch (TurnsManager.GetCurrentTurn())
                {
                case LEFT_TURN:
                {
                    if (!leftWin)
                    {
                        if (passTimes == 2)
                        {
                            kupaLogic.DeleteAllKupaCards();
                            gameBoard.Refresh();
                            Thread.Sleep(1000);
                            HighestCardChangeCheck = true;
                        }

                        if (kupaLogic.KupaCards.Count != 0)
                        {
                            compLogicLeft.ChooseSelectedCard(leftCards, kupaLogic.LastCard.CardType, roundType);
                        }
                        else
                        {
                            compLogicLeft.ChooseStartSelectedCards(leftCards);
                        }

                        cardsPassedToKupa = leftCards.Where(c => c.Selected).ToList();
                        foreach (Card card in cardsPassedToKupa)
                        {
                            compLogicLeft.RemoveCard(card);
                            leftCards.Remove(card);
                        }

                        if (cardsPassedToKupa.Count() > 0)
                        {
                            passTimes = 0;

                            leftCards.Sort();

                            if (cardsPassedToKupa.Count == 1)
                            {
                                if (kupaLogic.KupaCards.Count == 0 ||
                                    cardsPassedToKupa[0].CardType != kupaLogic.LastCard.CardType)
                                {
                                    oneBurnTimes = 0;
                                }
                                else if (cardsPassedToKupa[0].CardType == kupaLogic.LastCard.CardType)
                                {
                                    oneBurnTimes++;
                                }
                            }

                            if (kupaLogic.KupaCards.Count > 0)
                            {
                                burncheckfour = kupaLogic.LastCard;
                            }

                            roundType = cardsPassedToKupa.Count();
                            kupaLogic.AddCardsToKupa(cardsPassedToKupa);

                            compLogicLeft.AddCardsToComputerHand(leftCards);
                            gameBoard.Refresh();
                            Thread.Sleep(1000);
                            if (cardsPassedToKupa.Count == 4)
                            {
                                kupaLogic.DeleteAllKupaCards();
                                TurnsManager.BackTurn();
                                HighestCardChangeCheck = true;
                            }
                            if (cardsPassedToKupa.Count == 2)
                            {
                                if (kupaLogic.KupaCards.Count > 1)
                                {
                                    if (burncheckfour != null &&
                                        burncheckfour.CardType == cardsPassedToKupa[0].CardType)
                                    {
                                        gameBoard.Refresh();
                                        kupaLogic.DeleteAllKupaCards();
                                        TurnsManager.BackTurn();
                                        HighestCardChangeCheck = true;
                                    }
                                }
                            }
                            if (oneBurnTimes == 3)
                            {
                                kupaLogic.DeleteAllKupaCards();
                                TurnsManager.BackTurn();
                                oneBurnTimes           = 0;
                                HighestCardChangeCheck = true;
                            }
                        }
                        else
                        {
                            Card tempcard = new Card(1);
                            foreach (Card card in leftCards)
                            {
                                if (card.CardType == Card.CardTypeEnum.Two)
                                {
                                    tempcard = card;
                                }
                            }
                            if (tempcard.CardId != 1)
                            {
                                cardsPassedToKupa.Add(tempcard);
                                leftCards.Sort();
                                leftCards = leftCards.Where(c => c != tempcard).ToList();
                                compLogicLeft.RemoveCard(cardsPassedToKupa[0]);
                                leftCards.Remove(cardsPassedToKupa[0]);
                                kupaLogic.AddCardsToKupa(cardsPassedToKupa);
                                compLogicLeft.SortCards();
                                compLogicLeft.AddCardsToComputerHand(leftCards);
                                gameBoard.txtMessages.Text = "Left Computer Burned The Deck.";
                                gameBoard.Refresh();
                                Thread.Sleep(1000);
                                kupaLogic.DeleteAllKupaCards();
                                TurnsManager.BackTurn();
                                HighestCardChangeCheck = true;
                            }
                            else
                            {
                                gameBoard.txtMessages.Text = "Left Computer Passed Is Turn...";
                                gameBoard.Refresh();
                                passTimes++;
                                Thread.Sleep(1000);
                            }
                        }
                        if (HighestCardChangeCheck == true)
                        {
                            playerLogic.HighestCardType = Card.CardTypeEnum.Ace;
                        }
                        else
                        {
                            playerLogic.HighestCardType = kupaLogic.LastCard.CardType;
                        }
                        if (leftCards.Count == 0)
                        {
                            won       = true;
                            president = LEFT_COMP;
                            leftWin   = true;
                            playerLogic.HighestCardType = Card.CardTypeEnum.Ace;
                        }
                    }
                    else
                    {
                        passTimes++;
                    }
                    checkWinners();
                    break;
                }

                case RIGHT_TURN:
                {
                    if (!rightWin)
                    {
                        if (passTimes == 2)
                        {
                            kupaLogic.DeleteAllKupaCards();
                            HighestCardChangeCheck = true;
                            gameBoard.Refresh();
                            Thread.Sleep(1000);
                        }

                        if (kupaLogic.KupaCards.Count != 0)
                        {
                            compLogicRight.ChooseSelectedCard(rightCards, kupaLogic.LastCard.CardType, roundType);
                        }
                        else
                        {
                            compLogicRight.ChooseStartSelectedCards(rightCards);
                        }
                        cardsPassedToKupa = rightCards.Where(c => c.Selected).ToList();
                        foreach (Card card in cardsPassedToKupa)
                        {
                            compLogicRight.RemoveCard(card);
                            rightCards.Remove(card);
                        }
                        if (cardsPassedToKupa.Count() > 0)
                        {
                            passTimes = 0;
                            rightCards.Sort();
                            if (cardsPassedToKupa.Count == 1)
                            {
                                if (kupaLogic.KupaCards.Count == 0 ||
                                    cardsPassedToKupa[0].CardType != kupaLogic.LastCard.CardType)
                                {
                                    oneBurnTimes = 0;
                                }
                                else if (cardsPassedToKupa[0].CardType == kupaLogic.LastCard.CardType)
                                {
                                    oneBurnTimes++;
                                }
                            }
                            rightCards = rightCards.Where(c => !c.Selected).ToList();
                            if (kupaLogic.KupaCards.Count > 0)
                            {
                                burncheckfour = kupaLogic.LastCard;
                            }

                            roundType = cardsPassedToKupa.Count;
                            kupaLogic.AddCardsToKupa(cardsPassedToKupa);
                            compLogicRight.SortCards();
                            compLogicRight.AddCardsToComputerHand(rightCards);
                            gameBoard.Refresh();
                            Thread.Sleep(1000);
                            if (cardsPassedToKupa.Count == 4)
                            {
                                kupaLogic.DeleteAllKupaCards();
                                TurnsManager.BackTurn();
                                HighestCardChangeCheck = true;
                            }
                            if (cardsPassedToKupa.Count == 2)
                            {
                                if (kupaLogic.KupaCards.Count > 1)
                                {
                                    if (burncheckfour != null &&
                                        burncheckfour.CardType == cardsPassedToKupa[0].CardType)
                                    {
                                        gameBoard.Refresh();
                                        kupaLogic.DeleteAllKupaCards();
                                        TurnsManager.BackTurn();
                                        HighestCardChangeCheck = true;
                                    }
                                }
                            }
                            if (oneBurnTimes == 3)
                            {
                                kupaLogic.DeleteAllKupaCards();
                                TurnsManager.BackTurn();
                                oneBurnTimes           = 0;
                                HighestCardChangeCheck = true;
                            }
                        }

                        else
                        {
                            Card tempcard = new Card(1);
                            foreach (Card card in rightCards)
                            {
                                if ((int)card.CardType == 1)
                                {
                                    tempcard = card;
                                }
                            }
                            if (tempcard.CardId != 1)
                            {
                                cardsPassedToKupa.Add(tempcard);
                                rightCards.Sort();
                                rightCards = rightCards.Where(c => c != tempcard).ToList();
                                compLogicRight.RemoveCard(cardsPassedToKupa[0]);
                                rightCards.Remove(cardsPassedToKupa[0]);
                                kupaLogic.AddCardsToKupa(cardsPassedToKupa);
                                compLogicRight.SortCards();
                                compLogicRight.AddCardsToComputerHand(rightCards);
                                gameBoard.txtMessages.Text = "Right Computer Burned The Deck.";
                                gameBoard.Refresh();
                                Thread.Sleep(1000);
                                kupaLogic.DeleteAllKupaCards();
                                TurnsManager.BackTurn();
                                HighestCardChangeCheck = true;
                            }
                            else
                            {
                                gameBoard.txtMessages.Text = "Right Computer Passed Is Turn...";
                                gameBoard.Refresh();
                                passTimes++;
                                Thread.Sleep(1000);
                            }
                        }
                        if (HighestCardChangeCheck == true)
                        {
                            playerLogic.HighestCardType = Card.CardTypeEnum.Ace;
                        }
                        else
                        {
                            playerLogic.HighestCardType = kupaLogic.LastCard.CardType;        //check maybe don't need tp indent inside 'else'
                        }
                        if (rightCards.Count == 0)
                        {
                            won       = true;
                            president = RIGHT_COMP;
                            rightWin  = true;
                            playerLogic.HighestCardType = Card.CardTypeEnum.Ace;
                        }
                    }
                    else
                    {
                        passTimes++;
                    }
                    checkWinners();
                    break;
                }
                }
                gameBoard.Refresh();
                SystemSounds.Beep.Play();
                TurnsManager.AdvanceTurn();
                UpdateUIBehaviours();
            }
            if (playerWin)
            {
                passTimes++;
                TurnsManager.AdvanceTurn();
            }
        }
Esempio n. 2
0
        private void btnPlayerDone_Click(object sender, EventArgs e)
        {
            bool okmove = true;

            fourburn = false;
            Card burnchecktwo = new Card(1);
            Card burncheckfour;

            cardsPassedToKupa = playerCards.Where(c => c.Selected).ToList();

            if (kupaLogic.KupaCards.Count != 0 && cardsPassedToKupa.Count != 0)
            {
                bool containsTwo =
                    cardsPassedToKupa.Where(c => c.CardType == Card.CardTypeEnum.Two).ToList().Count > 0;
                if (!containsTwo)
                {
                    if (cardsPassedToKupa.Count != roundType)
                    {
                        okmove = false;
                        switch (roundType)
                        {
                        case 1:
                            gameBoard.Message("You must put one card only!");
                            break;

                        default:
                            gameBoard.Message("you must put " + roundType + " cards only!");
                            break;
                        }
                    }
                }
            }
            if (okmove == true)
            {
                foreach (Card card in cardsPassedToKupa)
                {
                    card.Clickable = false;
                }

                switch (cardsPassedToKupa.Count)
                {
                case 0:
                {
                    passTimes++;
                    gameBoard.txtMessages.Text = "Player Passed His Turn...";
                }
                break;

                case 1:
                {
                    roundType    = 1;
                    passTimes    = 0;
                    burnchecktwo = cardsPassedToKupa[0];
                    if (kupaLogic.KupaCards.Count == 0 ||
                        cardsPassedToKupa[0].CardType != kupaLogic.LastCard.CardType)
                    {
                        oneBurnTimes = 0;
                    }
                    else if (cardsPassedToKupa[0].CardType == kupaLogic.LastCard.CardType)
                    {
                        oneBurnTimes++;
                    }
                }
                break;

                case 2:
                {
                    roundType = 2;
                    passTimes = 0;
                    if (kupaLogic.KupaCards.Count > 0)
                    {
                        burncheckfour = kupaLogic.LastCard;
                        if (burncheckfour.CardType == cardsPassedToKupa[0].CardType)
                        {
                            fourburn = true;
                        }
                    }
                }
                break;

                case 3:
                {
                    roundType = 3;
                    passTimes = 0;
                }
                break;

                case 4:
                {
                    fourburn = true;
                }
                break;
                }

                foreach (Card card in cardsPassedToKupa)
                {
                    playerLogic.RemoveCard(card);
                    playerCards.Remove(card);
                }

                kupaLogic.AddCardsToKupa(cardsPassedToKupa);
                cardsPassedToKupa.Clear();

                playerCards.Sort();
                playerCards = playerCards.Where(c => !c.Selected).ToList();
                gameBoard.Refresh();

                if (fourburn == true)
                {
                    DeleteAllKupaCardsSet();
                    playerLogic.HighestCardType = Card.CardTypeEnum.Ace;
                }
                if (oneBurnTimes == 3)
                {
                    Thread.Sleep(1000);
                    kupaLogic.DeleteAllKupaCards();
                    TurnsManager.BackTurn();
                    oneBurnTimes = 0;
                    playerLogic.HighestCardType = Card.CardTypeEnum.Ace;
                }
                if (burnchecktwo.CardType == Card.CardTypeEnum.Two)
                {
                    Thread.Sleep(1000);
                    kupaLogic.DeleteAllKupaCards();
                    TurnsManager.BackTurn();
                    playerLogic.HighestCardType = Card.CardTypeEnum.Ace;
                    gameBoard.txtMessages.Text  = "Player Burned The Deck";
                }
                if (playerCards.Count == 0)
                {
                    won       = true;
                    president = PLAYER;
                    playerWin = true;
                }
                gameBoard.Refresh();
                checkWinners();

                if (won == false)
                {
                    TurnsManager.AdvanceTurn();
                    Thread.Sleep(1000);
                    UpdateUIBehaviours();
                    SystemSounds.Beep.Play();
                    ComputerMoves();
                    if (passTimes == 2)
                    {
                        Thread.Sleep(1000);
                        kupaLogic.DeleteAllKupaCards();
                        playerLogic.HighestCardType = Card.CardTypeEnum.Ace;
                    }
                }
            }
        }