Ejemplo n.º 1
0
        private void MouseButtonUpEvent(object sender, MouseButtonEventArgs mouse)
        {
            if (!Clickable)
            {
                return;
            }

            SmileButton.Image = smileyButton;

            ButtonPressed = false;
            PressedButton = MouseButton.None;

            int x = (mouse.X / board.squareSize);
            int y = (mouse.Y / board.squareSize);

            if (x >= board.SizeX || x < 0 || y < 0 || y >= board.SizeY)
            {
                board.doubleClicked = false;
                board.clickedX      = -1;
                board.clickedY      = -1;
                gEngine.DrawScreen(board, surfaceControl1);
                return;
            }

            if (mouse.Button == MouseButton.PrimaryButton)
            {
                board.clickedX = -1;
                board.clickedY = -1;
                if (board.data[x, y].displayInfo == DisplayInfo.SquareUnclicked ||
                    board.data[x, y].displayInfo == DisplayInfo.QuestionFlag)
                {
                    if (board.IsEmpty)
                    {
                        board.CreateBoard(x, y);
                        thread2 = new Thread(new ThreadStart(TimerThread));
                        thread2.IsBackground = true;
                        thread2.Name         = "TimerThread";
                        thread2.Priority     = ThreadPriority.Normal;
                        thread2.Start();
                    }
                    ClickSquare(x, y);
                }
            }
            else if (mouse.Button == MouseButton.SecondaryButton)
            {
                if (board.data[x, y].displayInfo == DisplayInfo.SquareUnclicked)
                {
                    board.data[x, y].displayInfo = DisplayInfo.BombFlag;
                    prvMines--;
                }
                else if (board.data[x, y].displayInfo == DisplayInfo.BombFlag)
                {
                    board.data[x, y].displayInfo = DisplayInfo.QuestionFlag;
                    prvMines++;
                }
                else if (board.data[x, y].displayInfo == DisplayInfo.QuestionFlag)
                {
                    board.data[x, y].displayInfo = DisplayInfo.SquareUnclicked;
                }
            }

            if (board.data[x, y].displayInfo == DisplayInfo.SquareClicked && board.doubleClicked)
            {
                if (board.GetNumberOfAdjoiningFlags(x, y) == board.data[x, y].Value)
                {
                    ClickSurroundingSquares(x, y);
                }
                else
                {
                    if (board.ErrorFlag[0] == -1)
                    {
                        /*board.ErrorFlag[0] = x; board.ErrorFlag[1] = y;
                         * if (thread3 == null)
                         * {
                         *  thread3 = new Thread(new ThreadStart(DisplayErrorThread));
                         *  thread3.IsBackground = true;
                         *  thread3.Name = "ErrorThread";
                         *  thread3.Priority = ThreadPriority.Normal;
                         *  thread3.Start();
                         * }
                         * else if (!thread3.IsAlive)
                         * {
                         *  thread3 = new Thread(new ThreadStart(DisplayErrorThread));
                         *  thread3.IsBackground = true;
                         *  thread3.Name = "ErrorThread";
                         *  thread3.Priority = ThreadPriority.Normal;
                         *  thread3.Start();
                         * }*/
                    }
                }
            }

            board.doubleClicked = false;
            UpdateMinesLabel(prvMines.ToString(CultureInfo.CurrentCulture), Color.Red);

            gEngine.DrawScreen(board, surfaceControl1);
        }