Exemplo n.º 1
0
 private static void write(SpaceObject obj, double time, List <SpaceObject> solarSystem)
 {
     Console.WriteLine("Details about the chosen planet:");
     obj.Draw();
     Console.WriteLine("Position:" + obj.calculatePosition(time));
     Console.WriteLine("Details about the childs:");
     foreach (SpaceObject child in solarSystem)
     {
         if (child.parent != null)
         {
             if (child.parent == obj)
             {
                 child.Draw();
                 Console.WriteLine("Position:" + child.calculatePosition(time));
             }
         }
     }
 }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            ArrayList a = new ArrayList();

            SpaceObject solen = new Star("Sol", "Yellow", 0, 10);

            a.Add(solen);
            a.Add(new Planet("Mercury", 0, 10, 12, solen, 3, 20));
            a.Add(new Planet("Venus"));
            a.Add(new Planet("Terra"));
            a.Add(new Moon("Luna"));

            for (int i = 0; i < a.Count; i++)
            {
                SpaceObject obj = (SpaceObject)(a[i]);
                obj.Draw();
            }

            Console.ReadLine();
        }
Exemplo n.º 3
0
        //public Action<int> delCalc;

        static void Main(string[] args)
        {
            //DelCalc dc;

            List <SpaceObject> solarSystem = new List <SpaceObject>
            {
                new Star("Sun"),                         //0
                new Planet("Mercury", 57910, 88),        //1
                new Planet("Venus", 108200, 225),        //2
                new Planet("Earth", 149600, 365),        //3
                new Planet("Mars", 227940, 687),         //4
                new Planet("Jupiter", 778330, 4333),     //5
                new Planet("Saturn", 1429400, 10760),    //6
                new Planet("Uranus", 2879889, 39685),    //7
                new Planet("Neptune", 4504300, 60190),   //8
                new DwarfPlanet("Pluto", 5913520, 90550) //9
            };
            //TODO må gjere noko betre enn dette... (ein måne MÅ ha x/y koordinatane til planeten den går rundt...) Planet har liste av måner?
            Moon moon = new Moon("The Moon", 384, 27);

            moon.PlanetOrbiting = solarSystem[3] as Planet;
            solarSystem.Add(moon);
            (solarSystem[3] as Planet).Moons.Add(moon);
            moon = new Moon("Europa", 671, 4);
            moon.PlanetOrbiting = solarSystem[5] as Planet;
            solarSystem.Add(moon);
            (solarSystem[5] as Planet).Moons.Add(moon);
            moon = new Moon("Mimas", 186, 1);
            moon.PlanetOrbiting = solarSystem[6] as Planet;
            (solarSystem[6] as Planet).Moons.Add(moon);
            solarSystem.Add(new AsteroidBelt("The Asteroid Belt"));



            Console.WriteLine("Time (number of days):");
            String strTime = Console.ReadLine();
            int    time    = int.Parse(strTime);

            foreach (SpaceObject obj in solarSystem)
            {
                obj.CalcPos(time);
                //dc += obj.CalcPos;
            }

            Console.WriteLine("Name of the planet:");
            String      name = Console.ReadLine();
            SpaceObject sObj = solarSystem.Find(s => s.Name.Equals(name));

            if (sObj is not null)
            {
                sObj.Draw();
                (sObj as Planet)?.DrawMoons();
            }
            else
            {
                //skriv ut info om berre sola og planetane
                solarSystem[0].Draw();
                solarSystem.FindAll(s => s is Planet).ForEach(s => s.Draw());
            }

            /*
             * foreach (SpaceObject obj in solarSystem)
             * {
             *  obj.Draw();
             * }
             */

            Console.ReadLine();
        }
Exemplo n.º 4
0
        public static void Main()
        {
            ArrayList a            = new ArrayList();
            ArrayList planets      = new ArrayList();
            ArrayList Earthmoons   = new ArrayList();
            ArrayList Marsmoons    = new ArrayList();
            ArrayList Jupitermoons = new ArrayList();
            ArrayList Saturnmoons  = new ArrayList();
            ArrayList Uranusmoons  = new ArrayList();
            ArrayList Neptunemoons = new ArrayList();
            ArrayList Plutomoons   = new ArrayList();



            using (var reader = new StreamReader(@"Z:\deadmaggi On My Mac\Dat154\Planeter.csv"))
            {
                while (!reader.EndOfStream)
                {
                    var line   = reader.ReadLine();
                    var values = line.Split(';');
                    if (values[1].Equals("None"))
                    {
                        a.Add(new Star(values[0], Convert.ToDouble(values[2]), Convert.ToDouble(values[3]), Convert.ToDouble(values[4]), Convert.ToDouble(values[5]), "red"));
                    }
                    if (values[1].Equals("Sun"))
                    {
                        a.Add(new Planet(values[0], Convert.ToDouble(values[2]), Convert.ToDouble(values[3]), Convert.ToDouble(values[4]), Convert.ToDouble(values[5]), "red"));
                        planets.Add(new Planet(values[0], Convert.ToDouble(values[2]), Convert.ToDouble(values[3]), Convert.ToDouble(values[4]), Convert.ToDouble(values[5]), "red"));
                    }
                    else
                    {
                        switch (values[1])
                        {
                        case "Earth":
                            Earthmoons.Add(new Moon(values[0], Convert.ToDouble(values[2]), Convert.ToDouble(values[3]), Convert.ToDouble(values[4]), Convert.ToDouble(values[5]), "red"));
                            break;

                        case "Mars":
                            Marsmoons.Add(new Moon(values[0], Convert.ToDouble(values[2]), Convert.ToDouble(values[3]), Convert.ToDouble(values[4]), Convert.ToDouble(values[5]), "red"));
                            break;

                        case "Jupiter":
                            Jupitermoons.Add(new Moon(values[0], Convert.ToDouble(values[2]), Convert.ToDouble(values[3]), Convert.ToDouble(values[4]), Convert.ToDouble(values[5]), "red"));
                            break;

                        case "Saturn":
                            Saturnmoons.Add(new Moon(values[0], Convert.ToDouble(values[2]), Convert.ToDouble(values[3]), Convert.ToDouble(values[4]), Convert.ToDouble(values[5]), "red"));
                            break;

                        case "Uranus":
                            Uranusmoons.Add(new Moon(values[0], Convert.ToDouble(values[2]), Convert.ToDouble(values[3]), Convert.ToDouble(values[4]), Convert.ToDouble(values[5]), "red"));
                            break;

                        case "Neptune":
                            Neptunemoons.Add(new Moon(values[0], Convert.ToDouble(values[2]), Convert.ToDouble(values[3]), Convert.ToDouble(values[4]), Convert.ToDouble(values[5]), "red"));
                            break;

                        case "Pluto":
                            Plutomoons.Add(new Moon(values[0], Convert.ToDouble(values[2]), Convert.ToDouble(values[3]), Convert.ToDouble(values[4]), Convert.ToDouble(values[5]), "red"));
                            break;
                        }
                    }
                }
            }

            for (int i = 0; i < a.Count; i++)
            {
                SpaceObject obj = (SpaceObject)(a[i]);
                if (obj.name.Equals("Sun"))
                {
                    obj.planets = planets;
                    goto ferdig;
                }
            }
ferdig:

            for (int i = 0; i < a.Count; i++)
            {
                SpaceObject obj = (SpaceObject)(a[i]);
                switch (obj.name)
                {
                case "Earth":
                    obj.moons = Earthmoons;
                    break;

                case "Mars":
                    obj.moons = Marsmoons;
                    break;

                case "Jupiter":
                    obj.moons = Jupitermoons;
                    break;

                case "Saturn":
                    obj.moons = Saturnmoons;
                    break;

                case "Uranus":
                    obj.moons = Uranusmoons;
                    break;

                case "Neptune":
                    obj.moons = Neptunemoons;
                    break;

                case "Pluto":
                    obj.moons = Plutomoons;
                    break;
                }
            }
            Console.WriteLine("Skriv inn ønsket planet");
            string input = Console.ReadLine();

            Console.WriteLine("Skriv inn ønsket tid");
            int tid = Convert.ToInt32(Console.ReadLine());

            for (int i = 0; i < a.Count; i++)
            {
                SpaceObject obj = (SpaceObject)(a[i]);
                if (obj.name.Equals(input) && input != "Sun")
                {
                    {
                        obj.Draw();
                        obj.Position(tid);
                        ArrayList moons = obj.moons;
                        for (int j = 0; j < moons.Count; j++)
                        {
                            SpaceObject moon = (SpaceObject)(moons[j]);
                            moon.Draw();
                            moon.Position(tid);
                        }
                        goto ferdig2;
                    }
                }
                if (obj.name.Equals("Sun") && input.Equals("") || obj.name.Equals("Sun") && input.Equals("Sun"))
                {
                    {
                        obj.Draw();
                        obj.Position(tid);
                        ArrayList planeter = obj.planets;
                        for (int j = 0; j < planeter.Count; j++)
                        {
                            SpaceObject planet = (SpaceObject)(planeter[j]); planet.Draw(); planet.Position(tid);
                        }
                        goto ferdig2;
                    }
                }
            }

ferdig2:

            Console.ReadLine();
        }