Esempio n. 1
0
        private void button_Click(object sender, EventArgs e)
        {
            if (!m_Game.GameOver())
            {
                Cell cell = null;
                if (!m_Game.SecondPlayer.Turn)
                {
                    cell = getCell((Control)sender);
                }
                else if (m_Game.SecondPlayer.Turn && m_VersusComputer == true)
                {
                    m_ListOfRandomCoordinates = ChooseRandomCell();
                    m_CoordinateA             = (Cell)m_ListOfRandomCoordinates[0];
                    cell = m_Game.Board.GetCell[m_CoordinateA.RowLocation, m_CoordinateA.ColumnLocation];
                }

                switch (m_UserChoice)
                {
                case eCellChoice.FirstChoice:
                    if (m_Game.FirstPlayer.Turn)
                    {
                        m_FirstCell           = cell;
                        m_FirstCell.IsVisible = true;
                    }
                    else if (m_Game.SecondPlayer.Turn && m_VersusComputer == false)
                    {
                        m_FirstCell           = getCell((Control)sender);
                        m_FirstCell.IsVisible = true;
                    }
                    else
                    {
                        m_FirstCell           = cell;
                        m_FirstCell.IsVisible = true;
                        m_FormArrayOfControls[m_FirstCell.RowLocation, m_FirstCell.ColumnLocation].Update();
                        Thread.Sleep(400);
                    }
                    m_UserChoice = eCellChoice.SecondChoice;
                    break;

                case eCellChoice.SecondChoice:
                    if (m_Game.FirstPlayer.Turn)
                    {
                        m_SecondCell           = getCell((Control)sender);
                        m_SecondCell.IsVisible = true;
                    }
                    else if (m_Game.SecondPlayer.Turn && m_VersusComputer == false)
                    {
                        m_SecondCell           = getCell((Control)sender);
                        m_SecondCell.IsVisible = true;
                    }
                    else
                    {
                        m_CoordinateB          = (Cell)m_ListOfRandomCoordinates[0];
                        m_SecondCell           = m_Game.Board.GetCell[m_CoordinateB.RowLocation, m_CoordinateB.ColumnLocation];
                        m_SecondCell.IsVisible = true;
                    }

                    m_FormArrayOfControls[m_SecondCell.RowLocation, m_SecondCell.ColumnLocation].Update();
                    Thread.Sleep(400);
                    m_UserChoice = eCellChoice.FirstChoice;
                    if (m_Game.FirstPlayer.Turn)
                    {
                        m_isTurnChanged = m_Game.StartGame(m_Game.FirstPlayer, m_FirstCell, m_SecondCell);
                        changeButtonStatus(m_isTurnChanged);
                        UpdateArrayOfTimeCoordinatesChanged();
                    }
                    else
                    {
                        m_isTurnChanged = m_Game.StartGame(m_Game.SecondPlayer, m_FirstCell, m_SecondCell);
                        if (m_VersusComputer == true && m_isTurnChanged)
                        {
                            ComputerGuessWrong(m_Game.Board, m_CoordinateA, m_CoordinateB);
                            m_PoolOfCells.Add(m_FirstCell);
                            m_PoolOfCells.Add(m_SecondCell);
                        }
                        else
                        {
                            UpdateArrayOfTimeCoordinatesChanged();
                        }

                        changeButtonStatus(m_isTurnChanged);
                    }

                    m_FormArrayOfControls[m_SecondCell.RowLocation, m_SecondCell.ColumnLocation].Update();
                    break;
                }

                UpdateLabels(m_Game.CurrentPlayer, m_Game.FirstPlayer, m_Game.SecondPlayer);
                if (m_Game.SecondPlayer.Turn && m_VersusComputer == true)
                {
                    m_CurPlayer.Update();
                    m_SecondPlayer.Update();
                    button_Click(sender, e);
                }
            }
        }