Beispiel #1
0
        private void NewGame()
        {
            FormHelper.SetNewField(_hCount, _wCount, _scale, this);

            _space = new Space(_hCount, _wCount);

            Invalidate();
        }
Beispiel #2
0
        public void BuildGlider()
        {
            // Given

            var space = new Space(4, 4);

            // When

            space[0, 1].Reanimate();
            space[1, 2].Reanimate();
            space[2, 0].Reanimate();
            space[2, 1].Reanimate();
            space[2, 2].Reanimate();

            // Then

            // Beginning
            Assert.AreEqual(space, GetGeneration("beginning"));

            // 1'st generation
            space.NewGeneration();

            Assert.AreEqual(space, GetGeneration("first"));

            // 2'nd generation
            space.NewGeneration();

            Assert.AreEqual(space, GetGeneration("second"));

            // 3'th generation
            space.NewGeneration();

            Assert.AreEqual(space, GetGeneration("thirth"));

            // 4'th generation
            space.NewGeneration();

            Assert.AreEqual(space, GetGeneration("fourth"));

            // Schema
            /*
                Beginning

                1 0 1 1
                1 1 0 1
                0 0 0 1
                1 1 1 1

                1'st generation
                
                1 1 1 1
                0 1 0 1
                1 0 0 1
                1 0 1 1

                2'nd generation
                
                1 1 1 1
                1 1 0 1
                0 1 0 1
                1 0 0 1

                3'th generation
                
                1 1 1 1
                1 0 1 1
                1 1 0 0
                1 0 0 1

                4'th generation

                1 1 1 1
                1 1 0 1
                1 1 1 0
                1 0 0 0
            */
        }
Beispiel #3
0
        private void RegisterActions()
        {
            Action action;

            // Key 'Space'

            action = () =>
            {
                timer.Enabled = !timer.Enabled;
            };

            _hotKeysActions.Add(32, action);

            // Key 'Enter'

            action = () =>
            {
                if (!timer.Enabled)
                {
                    _space.RandomGenerate();

                    Invalidate();
                }
            };

            _hotKeysActions.Add(13, action);

            // Key 'H'

            action = () =>
            {
                (new HotKeys(_hotKeys)).ShowDialog();
            };

            _hotKeysActions.Add(72, action);
            _hotKeysActions.Add(104, action);
            _hotKeysActions.Add(1056, action);
            _hotKeysActions.Add(1088, action);

            // Key 'S'

            action = () =>
            {
                var f = new SettingsForm(_scale, _hCount, _wCount, timer.Interval);

                f.ShowDialog();

                if (f.DialogResult == DialogResult.OK)
                {
                    _scale = f.Scale;
                    _hCount = f.HeightCount;
                    _wCount = f.WidthCount;
                    timer.Interval = f.TimerInterval;

                    NewGame();
                }
            };

            _hotKeysActions.Add(83, action);
            _hotKeysActions.Add(115, action);
            _hotKeysActions.Add(1067, action);
            _hotKeysActions.Add(1099, action);

            // Key 'C'

            action = () =>
            {
                if (!timer.Enabled)
                {
                    NewGame();
                }
            };

            _hotKeysActions.Add(67, action);
            _hotKeysActions.Add(99, action);
            _hotKeysActions.Add(1057, action);
            _hotKeysActions.Add(1089, action);

            // Key 'P'

            action = () =>
            {
                var dialogResult = MessageBox.Show(
                    @"Do you want to run performance testing?",
                    @"Warning",
                    MessageBoxButtons.YesNoCancel,
                    MessageBoxIcon.Question);

                if (dialogResult == DialogResult.Yes)
                {
                    (new PerformanceTesting()).ShowDialog();
                }
            };

            _hotKeysActions.Add(80, action);
            _hotKeysActions.Add(112, action);
            _hotKeysActions.Add(1047, action);
            _hotKeysActions.Add(1079, action);

            // Key 'X'

            action = () =>
            {
                if (!timer.Enabled)
                {
                    var f = new Patterns();

                    f.ShowDialog();

                    if (f.SelectedPattern != null)
                    {
                        _space = f.SelectedPattern.BuildSpace(_hCount, _wCount);

                        _hCount = _space.HeightCount;
                        _wCount = _space.WidthCount;

                        FormHelper.SetNewField(_hCount, _wCount, _scale, this);

                        Invalidate();
                    }
                }
            };

            _hotKeysActions.Add(88, action);
            _hotKeysActions.Add(120, action);
            _hotKeysActions.Add(1063, action);
            _hotKeysActions.Add(1095, action);

            // Debug

            action = () =>
            {
                var line = "";

                for (var i = 0; i < _space.HeightCount; i++)
                {
                    for (var j = 0; j < _space.WidthCount; j++)
                    {
                        if (_space[i, j].Alive)
                        {
                            line += $"{i}, {j}, ";
                        }
                    }
                }

                if (line != "")
                {
                    line = line.Substring(0, line.Length - 2);
                }

                throw new Exception();
            };

            _hotKeysActions.Add(8, action);
        }