Esempio n. 1
0
        private void UpdateUIBehaviours()
        {
            switch (TurnsManager.GetCurrentTurn())
            {
            case PLAYER_TURN:
                playerLogic.LogicHand.BackColor    = Color.Blue;
                compLogicLeft.LogicHand.BackColor  = Color.Gold;
                compLogicRight.LogicHand.BackColor = Color.Gold;
                gameBoard.txtMessages.Text         = "Player's Turn...";
                gameBoard.btnPlayerDone.Enabled    = true;
                gameBoard.lblPlayerNameLabel.Text  = "Player's Turn";
                gameBoard.Refresh();

                break;

            case LEFT_TURN:
                playerLogic.LogicHand.BackColor    = Color.Gold;
                compLogicLeft.LogicHand.BackColor  = Color.Blue;
                compLogicRight.LogicHand.BackColor = Color.Gold;
                gameBoard.txtMessages.Text         = "Left Computer's Turn...";
                gameBoard.btnPlayerDone.Enabled    = false;
                gameBoard.lblPlayerNameLabel.Text  = "Left Computer's Turn";
                gameBoard.Refresh();

                break;

            case RIGHT_TURN:
                playerLogic.LogicHand.BackColor    = Color.Gold;
                compLogicLeft.LogicHand.BackColor  = Color.Gold;
                compLogicRight.LogicHand.BackColor = Color.Blue;
                gameBoard.txtMessages.Text         = "Right Computer's Turn...";
                gameBoard.btnPlayerDone.Enabled    = false;
                gameBoard.lblPlayerNameLabel.Text  = "Right Computers's Turn";
                gameBoard.Refresh();

                break;
            }
        }
Esempio n. 2
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();
            }
        }