Exemplo n.º 1
0
 private void computerTurn()
 {
     System.Threading.Thread.Sleep(1000);
     if (r_GameManager.Board.NumberOfCells != (r_GameManager.FirstPlayer.Points + r_GameManager.SecondPlayer.Points) * 2)
     {
         if (r_GameManager.FirstPlayer.Turn == false && r_GameManager.SecondPlayer.Name.Equals("- computer -"))
         {
             string buttonLocation = r_GameManager.ComputerClick();
             int    row            = OperationWithCards.ExtractRow(buttonLocation);
             int    column         = OperationWithCards.ExtractColumn(buttonLocation);
             takeFocus(r_Board[row, column]);
             r_Board[row, column].PerformClick();
         }
     }
 }
Exemplo n.º 2
0
        private void button_Click(object sender, EventArgs e)
        {
            Button button = sender as Button;

            if (button.Text.Equals(string.Empty))
            {
                int buttonRow    = OperationWithCards.ExtractRow(button.Name);
                int buttonColumn = OperationWithCards.ExtractColumn(button.Name);
                r_GameManager.MakeMove(buttonRow, buttonColumn);
                if (m_MouseClickStatus.Equals(eClickMode.UnClickedMouse))
                {
                    firstMove = button;
                    firstPartOfMove();
                    computerTurn();
                }
                else
                {
                    secondPartOfMove(button);
                    r_GameManager.CheckIfGameEnded();
                    computerTurn();
                }
            }
        }
Exemplo n.º 3
0
        private void secondPartOfMove(Button i_Button)
        {
            bool isMatch = OperationWithCards.CheckIfMatch(i_Button.Name, firstMove.Name, r_GameManager.Board);

            if (isMatch)
            {
                r_GameManager.CurrentPlayer.AddPointToPlayer();
                updatePlayersLabel();
            }
            else
            {
                System.Threading.Thread.Sleep(2000);
                firstMove.Image = null;
                i_Button.Image  = null;
                Refresh();
                r_GameManager.Board.FlipDownCardInBoard(OperationWithCards.ExtractRow(firstMove.Name), OperationWithCards.ExtractColumn(firstMove.Name));
                r_GameManager.Board.FlipDownCardInBoard(OperationWithCards.ExtractRow(i_Button.Name), OperationWithCards.ExtractColumn(i_Button.Name));
                r_GameManager.SwitchTurn();
                updateCurrentPlayerLabel();
            }

            m_MouseClickStatus = eClickMode.UnClickedMouse;
            takeFocus(null);
        }