コード例 #1
0
        private void runTest(int gridSize)
        {
            LifeGame lifeSim = new LifeGame(gridSize);

            lifeSim.Randomize(.25);

            int startCount = lifeSim.LiveCellCount;

            _startTime = DateTime.Now;
            for (int i = 0; i < 1000; i++)
            {
                lifeSim.Step();
            }
            _stopTime = DateTime.Now;

            MessageBox.Show("Initial population of " + startCount +
                            ".\n\n1000 random generations took " + (_stopTime - _startTime));
        }
コード例 #2
0
        public GameOfLife()
        {
            InitializeComponent();
            _probability = 0.25;
            _gridSize    = 250;
            _stepNumber  = 0;

            _zoomStartX = pnlScroller.Width;
            _zoomStartY = pnlScroller.Height;
            _zoomMax    = 5;
            _zoomRate   = 1.5;
            _zoomCount  = 0;

            _lifeGame  = new LifeGame(_gridSize);
            _timer     = new Timer();
            _gameRules = new List <string>();

            lifeGrid.Columns = _gridSize;
            lifeGrid.Rows    = _gridSize;

            _timer.Enabled  = false;
            _timer.Interval = 1;

            _timer.Tick += new EventHandler(_timer_Tick);

            lifeGrid.MouseDown += new MouseEventHandler(lifeGrid_MouseDown);

            btnStart.Click += new EventHandler(btnStart_Click);
            btnStop.Click  += new EventHandler(btnStop_Click);
            btnStep.Click  += new EventHandler(btnStep_Click);

            btnReset.Click     += new EventHandler(btnReset_Click);
            btnClear.Click     += new EventHandler(btnClear_Click);
            btnRandomize.Click += new EventHandler(btnRandomize_Click);

            btnZoomIn.Click  += new EventHandler(btnZoomIn_Click);
            btnZoomOut.Click += new EventHandler(btnZoomOut_Click);
        }