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); }
public void Update() { // on each update (each second) positions of stars are recalculated based on their velocity foreach (Star star in Stars) { star.Position = new Values((star.Position.x + star.Velocity.x), (star.Position.y + star.Velocity.y)); } // on each update (each second) maximal distances of X and Y are recalculated by current positions of stars DistanceX = Stars.Max(s => s.Position.x) - Stars.Min(s => s.Position.x); // distance between min and max X position of stars DistanceY = Stars.Max(s => s.Position.y) - Stars.Min(s => s.Position.y); // distance between min and max Y position of stars }