Example #1
0
        private void boardSquare_Clicked(object sender, EventArgs e)
        {
            BoardSquare clickedSquare = sender as BoardSquare;

            if (clickedSquare.Enabled == true)
            {
                if (boardSquareActiveSquare == null && clickedSquare.BoardSquareType != BoardSquare.eBoardSquareType.None)
                {   // board has no active square
                    clickedSquare.SetActive();
                    boardSquareActiveSquare = clickedSquare;
                }
                else if (boardSquareActiveSquare != null)
                {
                    // board has an active square, check if its a move or we click on the same square again to inactive
                    if (clickedSquare == boardSquareActiveSquare)
                    {
                        clickedSquare.SetInActive();
                        boardSquareActiveSquare = null;
                    }
                    else
                    {
                        // if we got to here, that means the user wanted to make a move
                        // Human turn
                        handleHumanTurn(clickedSquare);

                        // Initialize the timer before computer turn
                        if (r_LogicUnit.Mode == LogicUnit.eGameMode.PlayerVsComputer)
                        {
                            r_Timer.Start();
                        }

                        // update the boards graphics
                        updateBoardGraphics();
                    }
                }
            }
        }