Ejemplo n.º 1
0
        /// <summary>
        /// Displays on the console information about world at the specified position.
        /// </summary>
        /// <param name="world">Information about the worlds.</param>
        /// <param name="position">Position.</param>
        private void Print(int number, WorldMemento world, Point position)
        {
            var left      = position.X;
            var top       = position.Y;
            var worldSize = world.Generation.WorldSize();


            Console.SetCursorPosition(left, top);
            var deadOrAlive = world.IsAlive ? "Alive" : "Dead";

            Print($"ID:{number} G:{world.GenerationNumber} L:{world.AliveCells} {deadOrAlive}");
            top++;

            for (int i = 0; i < worldSize.Rows; i++)
            {
                var stringBuilder = new StringBuilder();
                for (int j = 0; j < worldSize.Columns; j++)
                {
                    if (world.Generation[i, j] == CellStatus.Alive)
                    {
                        stringBuilder.Append(AliveCell);
                    }
                    else
                    {
                        stringBuilder.Append(DeadCell);
                    }
                }

                Console.SetCursorPosition(left, top);
                Print(stringBuilder.ToString(), world.IsAlive ? ConsoleColor.Green : ConsoleColor.Red);
                top++;
            }
        }
Ejemplo n.º 2
0
 /// <summary>
 /// Restores world's state
 /// </summary>
 public void RestoreState(WorldMemento memento)
 {
     Generation       = memento.Generation;
     GenerationNumber = memento.GenerationNumber;
     AliveCells       = memento.AliveCells;
     Size             = memento.Size;
     IsAlive          = memento.IsAlive;
 }