예제 #1
0
        /// <summary>
        /// Event handler for when the user lifts the mouse button.
        /// If it is left, reveal the tile (possibly ending the game).
        /// If it is right, try to flag or unflag a tile.
        /// </summary>
        private void Button_MouseUp(object sender, MouseEventArgs e)
        {
            MineSweeperButton button = (MineSweeperButton)sender;
            Tile tile = button.Tile;

            // double click
            //TODO
            if (e.Button == MouseButtons.Left)
            {
                HandleLeftClick(tile);
            }
            else if (e.Button == MouseButtons.Right)
            {
                HandleRightClick(tile);
            }

            button.ReplaceImage();
        }
예제 #2
0
        private void LinkButtonsToTiles(int numCols, int numRows)
        {
            FastChangeGamePanel(gp =>
            {
                for (int x = 0; x < numCols; x++)
                {
                    for (int y = 0; y < numRows; y++)
                    {
                        // Add a new connection.
                        Tile tile = _field.GetTile(x, y);
                        MineSweeperButton button = new MineSweeperButton(tile);
                        _connections.Add(tile, button);

                        gp.Controls.Add(button, x, y);
                        button.MouseUp     += Button_MouseUp;
                        button.DoubleClick += Button_DoubleClick;
                    }
                }
            });
        }