예제 #1
0
        public MainForm()
        {
            InitializeComponent();
            FormClosing      += MainForm_FormClosing;
            panel.Resize     += (sender, e) => panel.Refresh();
            panel.Paint      += (sender, e) => ResizeWorld(e.Graphics);
            panel.MouseClick += Panel_MouseClick;
            bordersToolStripMenuItem.Click += (sender, e) => panel.Refresh();

            world = World.GetWorld(0, 0);
            world.OnLifeChange += (x, y, alive) => DrawCell(x, y, alive);
            game = new Game();

            void SetTimer() => timer.Interval = 1000 * 1 / (int)speedNumericUpDown.Value;

            timer       = new Timer();
            timer.Tick += (sender, e) => game.Tick();
            speedNumericUpDown.ValueChanged += (sender, e) => SetTimer();

            bordersToolStripMenuItem.Checked = Properties.Settings.Default.DrawBorders;
            color  = Properties.Settings.Default.Color;
            Width  = Properties.Settings.Default.Width;
            Height = Properties.Settings.Default.Height;
            speedNumericUpDown.Value = Properties.Settings.Default.Speed;
            SetTimer(); //Make sure timer is set, even if the loaded value is the same as the control's initial value.
        }
예제 #2
0
        static void Main(string[] args)
        {
            int noOfTicks; string readLine;

            do
            {
                Console.WriteLine("Please enter the number of ticks:");
                readLine = Console.ReadLine();
                if (!IsValidNumber(readLine, out noOfTicks))
                {
                    Console.WriteLine("'{0}' is not a valid number.", readLine);
                }
            } while (!IsValidNumber(readLine, out noOfTicks));

            var game = new Game(60);
            foreach (Point point in GetSeed())
            {
                game.BringCellToLifeAt(point.X, point.Y);
            }

            for (int i = 0; i < noOfTicks; i++)
            {
                Console.Clear();
                game.Tick();
                Console.WriteLine(game.ToString());
                Thread.Sleep(300);
            }

            Console.ReadKey();
        }
 protected override void OnRenderFrame(FrameEventArgs e)
 {
     // called once per frame; render
     game.Tick();
     GL.BindTexture(TextureTarget.Texture2D, screenID);
     GL.TexImage2D(TextureTarget.Texture2D,
                   0,
                   PixelInternalFormat.Rgba,
                   game.screen.width,
                   game.screen.height,
                   0,
                   OpenTK.Graphics.OpenGL.PixelFormat.Bgra,
                   PixelType.UnsignedByte,
                   game.screen.pixels
                   );
     GL.Clear(ClearBufferMask.ColorBufferBit);
     GL.MatrixMode(MatrixMode.Modelview);
     GL.LoadIdentity();
     GL.BindTexture(TextureTarget.Texture2D, screenID);
     GL.Begin(PrimitiveType.Quads);
     GL.TexCoord2(0.0f, 1.0f); GL.Vertex2(-1.0f, -1.0f);
     GL.TexCoord2(1.0f, 1.0f); GL.Vertex2(1.0f, -1.0f);
     GL.TexCoord2(1.0f, 0.0f); GL.Vertex2(1.0f, 1.0f);
     GL.TexCoord2(0.0f, 0.0f); GL.Vertex2(-1.0f, 1.0f);
     GL.End();
     game.Render();
     SwapBuffers();
 }
예제 #4
0
 public void WorstPossibleGameOfLifeEverythingStaysDead()
 {
     game.Tick();
     for (int x = 0; x < 3; x++)
     {
         for (int y = 0; y < 3; y++)
         {
             Assert.That(game.IsAlive(x, y), Is.False);
         }
     }
 }
예제 #5
0
        static void Main(string[] args)
        {
            (int width, int height, int maxFps) = MainMenu();
            Stopwatch sw        = new Stopwatch();
            long      frameWait = Stopwatch.Frequency / maxFps;

            var game = new Game(width, height);

            game.RandomSeed();
            var running = true;
            var wrap    = true;

            while (running)
            {
                sw.Restart();
                if (wrap)
                {
                    game.TickWrap();
                }
                else
                {
                    game.Tick();
                }

                game.Render();
                do
                {
                    if (Console.KeyAvailable)
                    {
                        ConsoleKey key = Console.ReadKey(true).Key;
                        switch (key)
                        {
                        case ConsoleKey.Escape:
                            running = false;
                            break;

                        case ConsoleKey.Enter:
                            game.RandomSeed();
                            break;

                        case ConsoleKey.Spacebar:
                            wrap = !wrap;
                            break;

                        case ConsoleKey.Tab:
                            NextColor();
                            break;
                        }
                    }
                } while (sw.ElapsedTicks < frameWait);
            }
        }
예제 #6
0
        public void Glider()
        {
            game = new Game(20, 20);
            game.Set(0, 2, true);
            game.Set(1, 3, true);
            game.Set(2, 1, true);
            game.Set(2, 2, true);
            game.Set(2, 3, true);

            for (int i = 0; i < 100; i++)
            {
                game.Tick();
                game.Draw();
                Thread.Sleep(100);
            }
        }
        public static void Main()
        {
            var game = new Game(80, 26);

            // Glider
            game.Set(0, 2, true);
            game.Set(1, 3, true);
            game.Set(2, 1, true);
            game.Set(2, 2, true);
            game.Set(2, 3, true);
            while (true)
            {
                game.Tick();
                game.Draw();
                Thread.Sleep(100);
            }
        }
예제 #8
0
        private static void Ticking()
        {
            FileWriter fileWriter = new FileWriter(Constants.FilePathOutput);

            Io.PrintWorld(Game.World);

            while (Game.IsWorldDead() && Io.KeepTicking())
            {
                if (Io.IfSave())
                {
                    string[] worldString = GenerateOutput.GetOutput(Game.World);
                    fileWriter.Save(worldString);
                }
                Game.Tick();
                Io.PrintWorld(Game.World);
            }
        }