コード例 #1
0
        private void cardButton_Click(object i_Sender, EventArgs i_EventArgs)
        {
            MemoryGameCard currentCardRevealed;

            MemoryGameCardButtuon memoryCardButton = i_Sender as MemoryGameCardButtuon;

            if (!memoryCardButton.ImageInCard.Visible)
            {
                m_NumberOfCardsRevealed++;
                currentCardRevealed = m_GameManager.RevealCardByPlayer(m_GameBoard, memoryCardButton.RowNumber, memoryCardButton.ColumnNumber, m_ComputerMemory);
                this.Update();
                if (m_NumberOfCardsRevealed % 2 == 0)
                {
                    m_NumberOfCardsRevealed = 0;
                    if (m_LastCardRevealed.CardValue == currentCardRevealed.CardValue)
                    {
                        runSeccessfulTurn(currentCardRevealed);
                    }
                    else
                    {
                        runUnSeccessfulTurn(currentCardRevealed, m_LastCardRevealed);
                    }

                    while (m_IsAgainstComputer && m_CurrentPlayer.Name == "Computer" && !m_GameBoard.IsBoardFull())
                    {
                        TwoPairsOfIndexes indexes;
                        m_GameManager.MakeAComputerMove(m_GameBoard, ref m_ComputerMemory, out indexes);
                        Thread.Sleep(1000);
                        if (m_GameBoard.BoardMatrix[(int)indexes.FirstRowIndex, (int)indexes.FirstColoumnIndex].CardValue == m_GameBoard.BoardMatrix[(int)indexes.SecondRowIndex, (int)indexes.SecondColoumnIndex].CardValue)
                        {
                            runSeccessfulTurn(m_GameBoard.BoardMatrix[(int)indexes.FirstRowIndex, (int)indexes.FirstColoumnIndex]);
                        }
                        else
                        {
                            runUnSeccessfulTurn(m_GameBoard.BoardMatrix[(int)indexes.FirstRowIndex, (int)indexes.FirstColoumnIndex], m_GameBoard.BoardMatrix[(int)indexes.SecondRowIndex, (int)indexes.SecondColoumnIndex]);
                        }
                    }
                }
                else
                {
                    m_LastCardRevealed = currentCardRevealed;
                }
            }
        }
コード例 #2
0
        private void setButtonsOnBoard()
        {
            int leftLocation   = this.Left;
            int BottomLocation = this.Top;

            for (int i = 0; i < m_NumberOfRows; i++)
            {
                for (int j = 0; j < m_NumberOfColumns; j++)
                {
                    m_CardsButtons[i, j]      = new MemoryGameCardButtuon(m_GameBoard.BoardMatrix[i, j], i, j);
                    m_CardsButtons[i, j].Size = new System.Drawing.Size(100, 100);
                    m_CardsButtons[i, j].Left = leftLocation + 10;
                    m_CardsButtons[i, j].Top  = BottomLocation + 10;
                    this.Controls.Add(m_CardsButtons[i, j]);
                    m_CardsButtons[i, j].Click += cardButton_Click;
                    leftLocation = m_CardsButtons[i, j].Right;
                }

                leftLocation   = this.Left;
                BottomLocation = m_CardsButtons[i, m_NumberOfColumns - 1].Bottom;
            }

            this.Width = m_CardsButtons[m_NumberOfRows - 1, m_NumberOfColumns - 1].Right + 30;
        }