示例#1
0
        private void ellipse_MouseDown(object sender, MouseButtonEventArgs e)
        {
            e.Handled           = true;
            selectedNodeEllipse = (Ellipse)sender;
            Cell currentCell = new Cell((int)selectedNodeEllipse.Tag);

            checkMill(2, selectedNodeEllipse);
            // if blue reached phase 3 having only 3 blue stones left, move to form mills or block red mills
            if ((Cell.count(a, 2) == 3) && (secondPhase))
            {
                thirdPhaseBlue = true;
            }
            if ((Cell.count(a, 1) == 3) && (secondPhase))
            {
                thirdPhaseRed = true;
            }
            // blue player lost
            if (secondPhase && ((Cell.count(a, 2) < 3) || (!Mill.playerCanMove(a, 2))))
            {
                gameOver("redWon");
            }
            else
            // red player lost
            if (secondPhase && ((Cell.count(a, 1) < 3) || (!Mill.playerCanMove(a, 1))))
            {
                gameOver("blueWon");
            }
            else
            // if the game reached 70 moves (sum of both players moves) and no player won, it is a draw
            if (countMoves == 70)
            {
                gameOver("draw");
            }
            else
            // if red formed mill and user clicked on blue stone then remove the blue stone
            if (redMill && (a[currentCell.i, currentCell.j] == 2))
            {
                // remove blue stone that is not inside a mill or if all the blue stones are inside mills, allow to remove from mill
                if ((!blueMill) || (blueMill && Mill.StonesOnlyInMills(a, 2)))
                {
                    drawEllipse(selectedNodeEllipse, 2, yellowColor, 15, false);
                    redMill          = false;
                    removedBlueStone = true;
                    moveBlue();
                    a[currentCell.i, currentCell.j] = 0;
                    warning.SetResourceReference(TextBox.TextProperty, "blueStoneRemoved");
                    warning.Visibility = System.Windows.Visibility.Visible;
                }
                else
                {
                    warning.SetResourceReference(TextBox.TextProperty, "stoneNotInMill");
                    warning.Visibility = System.Windows.Visibility.Visible;
                }
            }
            else


            if (!redMill)
            {
                removedBlueStone = false;
                if (secondPhase && (secondClick == false))
                {
                    if (a[currentCell.i, currentCell.j] == 1)
                    {
                        secondClick                         = true;
                        previousEllipse                     = selectedNodeEllipse;
                        selectedNodeEllipse.Stroke          = Brushes.Yellow;
                        selectedNodeEllipse.StrokeThickness = 2;
                    }
                }
                else
                if (secondPhase && secondClick)
                {
                    Cell previousCell = new Cell((int)previousEllipse.Tag);
                    if (currentCell.Equals(previousCell))
                    {
                        selectedNodeEllipse.Stroke = Brushes.Transparent;
                        warning.Text       = "";
                        warning.Visibility = System.Windows.Visibility.Hidden;
                        secondClick        = false;
                    }
                    else
                    if ((a[currentCell.i, currentCell.j] == 0 && Cell.neighbour(a, previousCell, currentCell) && (!thirdPhaseRed)) ||
                        (a[currentCell.i, currentCell.j] == 0 && thirdPhaseRed))
                    {
                        a[previousCell.i, previousCell.j] = 0;
                        warning.Text       = "";
                        warning.Visibility = System.Windows.Visibility.Hidden;
                        drawEllipse(previousEllipse, 1, yellowColor, 15, false);
                        moveRed(selectedNodeEllipse);
                        secondClick = false;
                    }
                    else
                    if (a[currentCell.i, currentCell.j] != 0 || (!Cell.neighbour(a, previousCell, currentCell)) &&
                        (!currentCell.Equals(previousCell)) && (!thirdPhaseRed))
                    {
                        warning.SetResourceReference(TextBox.TextProperty, "invalidMove");
                        warning.Visibility = System.Windows.Visibility.Visible;
                        // previousEllipse = selectedNodeEllipse;
                    }
                }
                if (!secondPhase)
                {
                    moveRed(selectedNodeEllipse);
                }
            }
        }