Beispiel #1
0
        internal bool RunGame()
        {
            bool       endGame       = false;
            int        currentPlayer = new Random().Next(0, k_NumberOfPlayers);
            SingleGame game          = new SingleGame(r_GameBoard, r_GamePlayers, r_PlayWithComputer, r_ComputerPlayer);
            bool       anotherGame;
            bool       qFlag           = false;
            bool       isGoodCardMatch = false;

            while (!endGame)
            {
                Console.Clear();
                printBoard(r_GameBoard);
                string firstCard, secondCard;
                bool   computerTurn = r_PlayWithComputer && (currentPlayer == k_PlayerOneIndex);
                if (computerTurn)
                {
                    computerChoice(out firstCard, out secondCard);
                }
                else
                {
                    playerChoice(currentPlayer, out firstCard, out secondCard);
                }

                if (firstCard.Equals(k_Quit) || secondCard.Equals(k_Quit))
                {
                    qFlag = true;
                    break;
                }

                endGame = game.RunTurnPlayer(currentPlayer, firstCard, secondCard, ref isGoodCardMatch);
                if (isGoodCardMatch)
                {
                    goodMatch(r_GamePlayers[currentPlayer].GetPlayerNumber());
                }
                else
                {
                    badMatch();
                }

                currentPlayer = 1 - currentPlayer;
            }

            if (qFlag)
            {
                anotherGame = false;
            }
            else
            {
                game.GetWinner(out int winner, out int winnerScore);
                announceWinner(winner, winnerScore, out anotherGame);
            }

            return(anotherGame);
        }
        private void currentButton_Click(object sender, EventArgs e)
        {
            GameButton button = sender as GameButton;

            button.BackColor             = r_PlayerColor[m_CurrentGame.CurrentPlayer];
            button.BackgroundImage       = r_PicturesMap.GetPathByKey(m_CurrentGame.GetKey(button.Location));
            button.BackgroundImageLayout = ImageLayout.Stretch;
            button.Enabled = false;
            if (!m_FirstChosen.Equals(string.Empty))
            {
                if (m_CurrentGame.RunTurnPlayer(m_FirstChosen, button.Location))
                {
                    return;
                }

                m_SecondChosen = button.Location;
                setCurrentPlayerLabel(m_CurrentGame.CurrentPlayer);
            }
            else
            {
                m_FirstChosen = button.Location;
            }
        }