Exemple #1
0
        private void _startButton_Click(object sender, RoutedEventArgs e)
        {
            timer          = new DispatcherTimer();
            timer.Interval = new TimeSpan(0, 0, 0, 0, 300);
            timer.Tick    += Timer_Tick;
            int size = 0;

            int.TryParse(_gridSize.Text, out size);
            double probablity = 0;

            double.TryParse(_lifeGeneration.Text, out probablity);
            if (size != 0 && probablity != 0)
            {
                sizeOfGrid = size;
                Cells      = new Dictionary <Coordinates, CellState>();
                Cells      = GLife.GenerateLife(sizeOfGrid, probablity);
                initBitmap();
                _pDishImg.Source = ConvertBitmap(gridBitmap);

                /*
                 * oldway
                 * ClearGrid();
                 * CreateGrids(sizeOfGrid);
                 * PopulateGrid(Cells);
                 */
                timer.Start();
                isGenerated = true;
            }
        }
Exemple #2
0
        public MainWindow()
        {
            InitializeComponent();
            CreateGrids(16);
            Dictionary <Coordinates, CellState> InitialCells = new Dictionary <Coordinates, CellState>();

            InitialCells = GLife.GenerateLife(16);
            PopulateGrid(InitialCells);
            isGenerated = false;
            _pDishImg.SnapsToDevicePixels = true;
        }
Exemple #3
0
        private void Timer_Tick(object sender, EventArgs e)
        {
            if (isGenerated)
            {
                isGenerated = false;
                Cells       = GLife.NextGen(sizeOfGrid, Cells);
                generation++;
                _generationLabel.Content = string.Format("GENERATION: {0}", generation.ToString());

                /*
                 * ClearGrid();
                 * PopulateGrid(Cells);
                 */
                initBitmap();
                _pDishImg.Source = ConvertBitmap(gridBitmap);
                //gridBitmap.Save(@"C:\Users\Jericho Masigan\Documents\Test Environment\gameoflife\" + generation.ToString() + ".bmp", System.Drawing.Imaging.ImageFormat.Bmp);
                isGenerated = true;
            }
        }