Beispiel #1
0
        /************** BONUS 1 *************/

        /* Load button click event handler. */
        private void LoadGeneration(object sender, EventArgs e)
        {
            openFileDialog1.Filter           = "Text Files (.txt)|*.txt";
            openFileDialog1.InitialDirectory = "C:\\Users\\Public\\Documents";
            openFileDialog1.FileName         = "seed.txt";

            if (openFileDialog1.ShowDialog() == DialogResult.OK)
            {
                var      fileName = openFileDialog1.FileName;
                string[] lines = File.ReadAllLines(fileName);
                int      i = 0, j = 0;

                foreach (var line in lines)
                {
                    var row = line.Split(' ');

                    foreach (var value in row)
                    {
                        currentGeneration[i, j++] = new Cell(Convert.ToInt32(value));
                    }
                    j = 0;
                    i++;
                }
            }
            Game.generationCount = 1;
            textBox1.Text        = string.Format("{0}, Generation: {1}", Game.GetCellStats(currentGeneration), Game.generationCount);
            pictureBox1.Invalidate();
        }
Beispiel #2
0
 /* Random button click event handler. */
 private void LifeRandom(object sender, EventArgs e)
 {
     currentGeneration    = Game.InitializeGame();
     Game.generationCount = 1;
     frames.Clear();
     textBox1.Text = string.Format("{0}, Generation: {1}", Game.GetCellStats(currentGeneration), Game.generationCount);
     pictureBox1.Invalidate();
 }
Beispiel #3
0
 /* Called by timer during every step of simulation of game. */
 private void timerTick(object sender, EventArgs e)
 {
     /* Save current frame before generating next generation. */
     GifUtils.SaveFrame(ref frames, pictureBox1);
     /* Generate next generation */
     Game.NewGeneration(ref currentGeneration);
     textBox1.Text = string.Format("{0}, Generation: {1}", Game.GetCellStats(currentGeneration), Game.generationCount++);
     pictureBox1.Invalidate();
 }
Beispiel #4
0
 public Form1()
 {
     InitializeComponent();
     currentGeneration = Game.InitializeGame();
     frames            = new List <byte[]>();
     timer1.Interval   = Properties.Settings.Default.TickRate;
     timer1.Tick      += new EventHandler(timerTick);
     textBox1.Text     = string.Format("{0}, Generation: {1}", Game.GetCellStats(currentGeneration), Game.generationCount++);
 }
Beispiel #5
0
 /* Clear button click event handler. */
 private void LifeClear(object sender, EventArgs e)
 {
     for (int i = 0; i < Game.COLUMNS; i++)
     {
         for (int j = 0; j < Game.COLUMNS; j++)
         {
             currentGeneration[i, j] = new Cell();
         }
     }
     Game.generationCount = 1;
     frames.Clear();
     textBox1.Text = string.Format("{0}, Generation: {1}", Game.GetCellStats(currentGeneration), Game.generationCount);
     pictureBox1.Invalidate();
 }
Beispiel #6
0
        /* PictureBox Click event handler */
        private void pictureBox1_MouseClick(object sender, MouseEventArgs e)
        {
            /* Get X and Y coordinates from event, and then map these numbers to array indexes relatively. */
            Point p = e.Location;
            var   x = (int)Math.Floor(p.X / (double)Game.CELL_SIZE);
            var   y = (int)Math.Floor(p.Y / (double)Game.CELL_SIZE);

            /* Set state of the cell ALIVE when left button of mouse is clicked. */
            if (e.Button == MouseButtons.Left)
            {
                currentGeneration[x, y] = new Cell(Cell.ALIVE);
            }
            /* Set state of the cell DEAD when right button of mouse is clicked. */
            else if (e.Button == MouseButtons.Right)
            {
                currentGeneration[x, y] = new Cell(Cell.DEAD);
            }
            textBox1.Text = string.Format("{0}, Generation: {1}", Game.GetCellStats(currentGeneration), Game.generationCount);
            /* Redraw everything on PictureBox */
            pictureBox1.Invalidate();
        }