Esempio n. 1
0
        public List <string> GenerateView()
        {
            int MinX = Stars.Min(s => s.Position.x);
            int MaxX = Stars.Max(s => s.Position.x);
            int MinY = Stars.Min(s => s.Position.y);
            int MaxY = Stars.Max(s => s.Position.y);

            List <string> rows = new List <string>();

            // it is enough to draw only that part of the sky where there are currently stars
            for (int y = MinY; y < MaxY + 1; y++)
            {
                string row = "";
                for (int x = MinX; x < MaxX + 1; x++)
                {
                    // if any star has the current position, it's expressed by 'X'
                    if (Stars.Any(pos => pos.Position.x == x && pos.Position.y == y))
                    {
                        row += "X";
                    }
                    else
                    {
                        row += " ";
                    }
                }
                rows.Add(row);
            }

            return(rows);
        }