コード例 #1
0
        /// <summary>
        /// OnClick function. If label is free (checkCase), put token on label (UpdateBoard())
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnClickLabel(object sender, RoutedEventArgs e)
        {
            if (btnUndo.IsEnabled == false)
            {
                btnUndo.IsEnabled = true;
            }

            Label lbl = sender as Label;

            int row = Grid.GetRow(lbl);
            int col = Grid.GetColumn(lbl);

            board.SetUndoBoard(board.GetBoard());

            //If free case
            if (rules.CheckCase(row, col, false))
            {
                rules.AnimeLabel(lbl);
                rules.CheckCase(row, col, true);
                if (isPlayer1)
                {
                    UpdateBoard(row, col, lbl, player1);
                }
                else
                {
                    UpdateBoard(row, col, lbl, player2);
                }

                nbFreeCells--;
                lbl.MouseDown -= OnClickLabel;
            }

            CheckScore();
            if (CheckIfWin())
            {
                FinishFunction();
                return;
            }

            if (!rules.CheckCases())
            {
                ChangeTurn();
                if (!rules.CheckCases())
                {
                    FinishFunction();
                }
            }
        }