Exemplo n.º 1
0
        public void BeginGame(int gameSize)
        {
            ResetTimer();

            var numRows = gameSize + 6;
            var numCols = gameSize + 6;

            var moduloValueOnRight = numRows - 1;

            mineLand.Recreate(numRows, numCols, defaultDifficultyLevel);

            SetupMainLayout(defaultButtonHeight, defaultButtonWidth, numRows, numCols);
            SetAndCenterGameInfo("", Color.Black);
            SetAndCenterTimeElapsedTextBox();
            SetRemainingFlagsLabel();

            foreach (MineSquare mineSquare in mineLand.GetEachMineSquare())
            {
                var tempPos = mineSquare.GetIndex();
                var button  = CreateUntouchedMineSquareButton(mineSquare);
                if (tempPos % numRows == moduloValueOnRight)
                {
                    MineFlowPanel.SetFlowBreak(button, true);
                }
                MineFlowPanel.Controls.Add(button);
            }

            timeElapsed.Start();
        }
Exemplo n.º 2
0
        private void SetupMainLayout(int rowSize, int colSize, int numRows, int numCols)
        {
            //clearing each component takes hundreds of ms execution time, so disposing entire flowLayoutPanel is better (only a few ms)
            MineFlowPanel.Visible = false;

            var prevLocation = MineFlowPanel.Location;

            MineFlowPanel.Dispose();

            var padding = 2;

            MineFlowPanel               = new FlowLayoutPanel();
            MineFlowPanel.Location      = prevLocation;
            MineFlowPanel.Width         = colSize * numCols + padding;
            MineFlowPanel.Height        = rowSize * numRows + padding;
            MineFlowPanel.FlowDirection = FlowDirection.LeftToRight;
            MineFlowPanel.BorderStyle   = BorderStyle.FixedSingle;
            MineFlowPanel.Margin        = new Padding(2);

            Controls.Add(MineFlowPanel);
            Width  = MineFlowPanel.Width + (padding * 20);
            Height = MineFlowPanel.Height + prevLocation.Y + 50;

            prevLocation.X = ((Width / 2) - (MineFlowPanel.Width / 2)) / 2;

            MineFlowPanel.Location = prevLocation;

            foreach (Control button in MineFlowPanel.Controls)
            {
                button.MouseDown -= new MouseEventHandler(MineSquareButton_Click);
                button.Dispose();
            }

            MineFlowPanel.Controls.Clear();
            MineFlowPanel.Visible = true;
        }