コード例 #1
0
ファイル: FormGame.cs プロジェクト: ChenLu1211/memory-game
        // $G$ DSN-003 (-3) This method is too long. Should be split into several methods.
        private void pictureBox_Click(object sender, EventArgs e)
        {
            bool isGameOver = false;

            if (!isGameOver)
            {
                bool isPair = false;

                switch (m_ClickIndex)
                {
                case eClickIndex.FirstChoice:

                    getClickedCell((Control)sender);
                    m_FirstCellChoice = m_CurrentCellChoice;
                    firstChoice();
                    m_ClickIndex = eClickIndex.SecondChoice;
                    break;

                case eClickIndex.SecondChoice:

                    getClickedCell((Control)sender);
                    m_SecondCellChoice = m_CurrentCellChoice;
                    secondChoice(ref isPair);
                    Thread.Sleep(600);
                    m_ClickIndex = eClickIndex.CheckPair;
                    break;
                }

                if (m_ClickIndex == eClickIndex.CheckPair)
                {
                    if (!isPair)
                    {
                        turnOffButton();
                        refreshLabelsState();
                        while (m_GameManagement.CurrentPlayer.Name == k_Computer && !m_GameManagement.IsGameOver())
                        {
                            computerMoves(ref isPair);
                            Thread.Sleep(300);
                            refreshLabelsState();
                        }
                    }

                    m_ClickIndex = eClickIndex.FirstChoice;
                }

                refreshLabelsState();
                isGameOver = m_GameManagement.IsGameOver();
                if (isGameOver)
                {
                    this.Hide();
                    string theWinner = m_GameManagement.TheWinner();
                    displayEndDialog(theWinner);
                }
            }
        }
コード例 #2
0
ファイル: FormGame.cs プロジェクト: ChenLu1211/memory-game
 private void getClickedCell(Control i_ClickedCell)
 {
     for (int row = 0; row < m_GameManagement.GameBoard.Width; row++)
     {
         for (int column = 0; column < m_GameManagement.GameBoard.Height; column++)
         {
             if (m_Controls[row, column].Equals(i_ClickedCell))
             {
                 m_CurrentCellChoice = m_GameManagement.GameBoard.Cells[row, column];
             }
         }
     }
 }