예제 #1
0
        private void StartButton_Click(object sender, EventArgs e)
        {
            var width  = int.Parse(WidthInput.Text);
            var height = int.Parse(HeightInput.Text);
            var randomElementsNumber = int.Parse(RandomElementsNumberInput.Text);
            var interval             = int.Parse(IntervalInput.Text);
            var gridValidator        = new GridValidator();

            if (!gridValidator.Validate(width, height, randomElementsNumber, interval))
            {
                return;
            }
            PauseButton.Enabled = true;
            Grid = null;
            Timer?.Dispose();
            GlobalWidth      = width;
            GlobalHeight     = height;
            Grid             = new Grid(width, height, randomElementsNumber);
            PauseButton.Text = "Pause";
            Timer            = new Timer {
                Interval = interval
            };
            Timer.Tick += (localSender, locale) => Simulation();
            Timer.Start();
        }
예제 #2
0
        private void StartButton_Click(object sender, EventArgs e)
        {
            var width  = int.Parse(WidthInput.Text);
            var height = int.Parse(HeightInput.Text);
            var randomElementsNumber = 0;

            if (InitialSetting.SelectedItem.ToString() == "Random" ||
                InitialSetting.SelectedItem.ToString() == "Evenly" ||
                InitialSetting.SelectedItem.ToString() == "Circle area")
            {
                randomElementsNumber = int.Parse(RandomElementsNumberInput.Text);
            }

            var interval      = int.Parse(IntervalInput.Text);
            var gridValidator = new GridValidator();

            if (!gridValidator.Validate(width, height, randomElementsNumber, interval))
            {
                return;
            }
            PauseButton.Enabled = true;
            Grid = null;
            Timer?.Dispose();
            GlobalWidth  = width;
            GlobalHeight = height;
            var selectedStartType    = InitialSetting.SelectedItem.ToString();
            var selectedNeighborhood = NeighborhoodType.SelectedItem.ToString();
            var periodicValues       = checkBoxPeriodical.Checked;

            Grid = new Grid(width, height, randomElementsNumber, periodicValues, selectedStartType,
                            selectedNeighborhood, ToDrawValues);
            _bitmap = new Bitmap(_maxWidth, _maxWidth / GlobalWidth * GlobalHeight);
            boardPictureBox.Width  = _bitmap.Width;
            boardPictureBox.Height = _bitmap.Height;
            _grainedElementsNumber = Grid.Grained.Count;
            PauseButton.Text       = "Pause";
            Timer = new Timer {
                Interval = interval
            };
            Timer.Tick += (localSender, locale) => Simulation();
            Timer.Start();
        }