public List <SpaceObjects> InitSolarSystem() { List <SpaceObjects> solarSystem = new List <SpaceObjects>(); String file = "ObjectInfo.txt"; String path = @"C:\Users\Fredrik Mathisen\source\repos\SolarSystem"; String fullPath = System.IO.Path.Combine(path, file); String[] lines = System.IO.File.ReadAllLines(fullPath); String[][] jaggedArray = lines.Select(line => line.Split('\t').ToArray()).ToArray(); foreach (string[] line in jaggedArray) { string obj = line[0]; string Name = line[1]; Double orbRadius = Double.Parse(line[2]); int orbitalPeriode = int.Parse(line[3]); int planetRadius = int.Parse(line[4]); double rotPeriode = Double.Parse(line[5]); String color = line[6]; switch (obj) { case "Star": solarSystem.Add(new Star(Name, orbRadius, orbitalPeriode, planetRadius, rotPeriode, color)); break; case "Moon": SpaceObjects parent = FindParent(line[7], solarSystem); solarSystem.Add(new Moon(Name, orbRadius, orbitalPeriode, planetRadius, rotPeriode, color, parent)); break; case "DwarfPlanet": solarSystem.Add(new DwarfPlanet(Name, orbRadius, orbitalPeriode, planetRadius, rotPeriode, color)); break; default: solarSystem.Add(new Planet(Name, orbRadius, orbitalPeriode, planetRadius, rotPeriode, color)); break; } } return(solarSystem); }
public void Moons() { string file = "MoonObjects.txt"; string path = @"C:\Users\Fredrik Mathisen\source\repos\SolarSystem"; string fullPath = System.IO.Path.Combine(path, file); string[] lines = System.IO.File.ReadAllLines(fullPath); foreach (string s in lines) { string[] attribs = s.Split('\t'); string name = attribs[0]; double orbRadius = double.Parse(attribs[1]); int orbitalPeriode = int.Parse(attribs[2]); int moonRadius = int.Parse(attribs[3]); double rotPeriode = double.Parse(attribs[4]); string color = attribs[5]; SpaceObjects parent = FindParent(attribs[6], solarSystem); planetMoons.Add(new Moon(name, orbRadius, orbitalPeriode, moonRadius, rotPeriode, color, parent)); } }
public Moon(String name, double orbitalRadius, int orbitalPeriode, int objRadius, double rotationPeriode, String color, SpaceObjects parent) : base(name, orbitalRadius, orbitalPeriode, objRadius, rotationPeriode, color) { this.parent = parent; }