示例#1
0
        private void populateBodies(List <string> input)
        {
            _bodies["COM"] = new OrbitalBody("COM");
            _bodies["COM"].DistanceFromCOM = 0;

            foreach (var line in input)
            {
                (string primaryBodyName, string orbitingBodyName) = parseOrbitString(line);

                if (_bodies.ContainsKey(primaryBodyName) == false)
                {
                    _bodies[primaryBodyName] = new OrbitalBody(primaryBodyName);
                }

                if (_bodies.ContainsKey(orbitingBodyName) == false)
                {
                    _bodies[orbitingBodyName] = new OrbitalBody(orbitingBodyName);
                }

                OrbitalBody primaryBody  = _bodies[primaryBodyName];
                OrbitalBody orbitingBody = _bodies[orbitingBodyName];

                primaryBody.bodiesInOrbit.Add(orbitingBody);
                orbitingBody.inOrbitOf = primaryBody;
            }
        }
示例#2
0
        private void populateDistancesFromCOM(OrbitalBody body = null)
        {
            body ??= _bodies["COM"]; // Set body to COM if null

            if (body.name == "COM")
            {
                body.DistanceFromCOM = 0;
            }
            else
            {
                body.DistanceFromCOM = body.inOrbitOf.DistanceFromCOM + 1;
            }

            body.bodiesInOrbit.ToList().ForEach(x => populateDistancesFromCOM(x));
        }