コード例 #1
0
ファイル: Program.cs プロジェクト: vonwenm/Jibu
        static void Main()
        {
            // The size of the world
            int columns = 150;
            int rows = 150;

            // Each cell will have width and length = 2 * cellPadding 
            int cellPadding = 2;

            // The number of LifeForms to begin with
            int numLifeForms = 100;

            // Set this to false to run the 
            // game sequentially.
            // If the game is run on a computer
            // with multiple cores, then the
            // speed difference should obvious.
            bool parallel = true;

            LifeForm[] lifeForms = new LifeForm[numLifeForms];
            Random rand = new Random();

            // Generate some life forms that
            // will be placed randomly
            for (int i = 0; i < numLifeForms; i++)
            {
                int x = rand.Next(columns);
                int y = rand.Next(rows);

                if (i < numLifeForms / 3)
                    lifeForms[i] = LifeForm.CreateGlider(x, y);
                else if (i < numLifeForms / 2)
                    lifeForms[i] = LifeForm.CreatePulsar(x, y);
                else
                    lifeForms[i] = LifeForm.CreateLightweightSpaceship(x, y);

            }

            World w = new World(columns, rows);
            w.AddLifeForms(lifeForms);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new GameOfLife(new GamePanel(w, cellPadding,parallel)));



            // For a text-based version uncomment the loop below.
            /* 
             
            for (int i = 0; i < 10; i++)
            {
                w.ParallelTransition();
                w.ConsoleDraw();
            }
             */

        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: hdraganovski/game-of-life
        private void newToolStripMenuItem_Click(object sender, EventArgs e)
        {
            LifeForm child = new LifeForm();

            child.Text      = "Game " + childN.ToString();
            child.MdiParent = this;
            child.Show();
            childN++;
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: Erhannis/Jibu
        static void Main()
        {
            // The size of the world
            int columns = 150;
            int rows    = 150;

            // Each cell will have width and length = 2 * cellPadding
            int cellPadding = 2;

            // The number of LifeForms to begin with
            int numLifeForms = 100;

            // Set this to false to run the
            // game sequentially.
            // If the game is run on a computer
            // with multiple cores, then the
            // speed difference should obvious.
            bool parallel = true;

            LifeForm[] lifeForms = new LifeForm[numLifeForms];
            Random     rand      = new Random();

            // Generate some life forms that
            // will be placed randomly
            for (int i = 0; i < numLifeForms; i++)
            {
                int x = rand.Next(columns);
                int y = rand.Next(rows);

                if (i < numLifeForms / 3)
                {
                    lifeForms[i] = LifeForm.CreateGlider(x, y);
                }
                else if (i < numLifeForms / 2)
                {
                    lifeForms[i] = LifeForm.CreatePulsar(x, y);
                }
                else
                {
                    lifeForms[i] = LifeForm.CreateLightweightSpaceship(x, y);
                }
            }

            World w = new World(columns, rows);

            w.AddLifeForms(lifeForms);

            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new GameOfLife(new GamePanel(w, cellPadding, parallel)));



            // For a text-based version uncomment the loop below.

            /*
             *
             * for (int i = 0; i < 10; i++)
             * {
             *  w.ParallelTransition();
             *  w.ConsoleDraw();
             * }
             */
        }
コード例 #4
0
ファイル: World.cs プロジェクト: vonwenm/Jibu
        /**************************************
         * Adds an array of LifeForms to the
         * world.
         **************************************/
        public void AddLifeForms(LifeForm[] lifeForms)
        {
            foreach (LifeForm lf in lifeForms)
            {
                int xOffset = lf.Offset.x;
                int yOffset = lf.Offset.y;

                foreach (Point p in lf.Points)
                {
                    SetAlive(p.x + xOffset, p.y + yOffset);
                }
            }
        }