Example #1
0
 private static void OnTimedEvent(Object source, ElapsedEventArgs e)
 {
     Console.WriteLine("The Elapsed event was raised at {0:HH:mm:ss.fff}", e.SignalTime);
     Console.SetCursorPosition(0, 0);
     PrintValues(game.World, game.Grid);
     game = GetNewWorld(game);
 }
Example #2
0
        public static LifeGame GetNewWorld(LifeGame world)
        {
            LifeGame cloneWorld = new LifeGame(world.Size);

            for (int i = 0; i < cloneWorld.Size; i++)  // Acme World copier loop
            {
                cloneWorld.World[i] = world.World[i];
            }
            for (int i = 0; i < world.Size; i++)
            {
                cloneWorld.World[i] = LiveOrDie(world, i);
            }

            return(cloneWorld);
        }
Example #3
0
        public static bool LiveOrDie(LifeGame world, int square)
        {
            int[] outskirts   = world.SurrondingCells(square);
            int   lifeTracker = 0;

            for (int i = 0; i < 8; i++)
            {
                int j = outskirts[i];
                if (world.World[j])
                {
                    lifeTracker++;
                }
            }


            if (world.World[square])
            {
                if (lifeTracker < 2 || lifeTracker > 3)
                {
                    return(false);
                }
                else
                {
                    return(true);
                }
            }
            else
            {
                if (lifeTracker == 3)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
        }