Exemple #1
0
        private void updatBoardButtons()
        {
            for (int i = 0; i < m_MemoryGame.GameBoard.Rows; i++)
            {
                for (int j = 0; j < m_MemoryGame.GameBoard.Cols; j++)
                {
                    m_CardsButtons[i, j] = new MemoryGameCardButton(m_MemoryGame.GameBoard.Board[i, j], i, j, m_MemoryGame.GameBoard.Board[i, j].Data);
                    if (i == 0)
                    {
                        m_CardsButtons[i, j].Top = this.Top + 10;
                    }
                    else
                    {
                        m_CardsButtons[i, j].Top = m_CardsButtons[i - 1, j].Bottom + 10;
                    }

                    if (j == 0)
                    {
                        m_CardsButtons[i, j].Left = this.Left + 10;
                    }
                    else
                    {
                        m_CardsButtons[i, j].Left = m_CardsButtons[i, j - 1].Right + 10;
                    }

                    m_CardsButtons[i, j].Size = new Size(100, 100);
                    Controls.Add(m_CardsButtons[i, j]);
                    m_CardsButtons[i, j].Click += CardsButtons_Click;
                }
            }
        }
Exemple #2
0
        public void CardsButtons_Click(object sender, EventArgs e)
        {
            MemoryGameCardButton memoryCardButton = sender as MemoryGameCardButton;

            if (m_MemoryGame.GameBoard.Board[memoryCardButton.RowNumber, memoryCardButton.ColNumber].IsClose == true)
            {
                memoryCardButton.FlatAppearance.BorderColor = m_CurrentPlayerTurnLabel.BackColor;
                memoryCardButton.ImageVisible();
                this.Update();
                if (firstPos.RowNum == -1)
                {
                    firstPos = new Position(memoryCardButton.RowNumber, memoryCardButton.ColNumber);
                    m_MemoryGame.GameBoard.OpenCard(firstPos);
                }
                else
                {
                    secondPos = new Position(memoryCardButton.RowNumber, memoryCardButton.ColNumber);
                    m_MemoryGame.GameBoard.OpenCard(secondPos);
                }
            }
            runMemoryGame();

            if (m_MemoryGame.IsGameOver != true)
            {
                while (m_MemoryGame.Turn.IsPlayer2Turn() && m_MemoryGame.GameType.IsAgainstTheComputer() == true)
                {
                    computerTurn();
                }
            }
            else
            {
                this.Close();
            }
        }