コード例 #1
0
        static void Main(string[] args)
        {
            try
            {
                //planet
                AstronomicalBody astBody = new AstronomicalBody("Kepler", 345.45F, 23.5F, 321.5F, 2.5900000000000000F);

                //asteroids
                AstronomicalBody ceres   = new AstronomicalBody("Ceres", 3345.4F, 789.4F, 347.83F, 7.3600000000000000F);
                AstronomicalBody fortuna = new AstronomicalBody("Fortuna", 795.67F, 41.3F, 78.4F, 9.3400000000000000F);

                //space ship
                SpaceShip ship = new SpaceShip("Millenium falcon", 23.5645F, 19945645.45F, astBody);

                //asteroid belt
                AsteroidBelt sp = new AsteroidBelt(ship);

                ship.Hit();


                Console.ReadKey();
            }
            catch (InvalidAstBodyNameException e)
            {
                Console.WriteLine("Custom exception " + e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
コード例 #2
0
 public GasGiant(string name, float x, float y, float z, float weight, string adjective, int satellites, float rotationPeriod, bool spots, bool rings) : base(name, x, y, z, weight, adjective, satellites, rotationPeriod)
 {
     this.Kind  = Type.GasGiant;
     this.spots = spots;
     this.rings = rings;
     AstronomicalBody.AddAstBody();
 }
コード例 #3
0
 public GasGiant(string name, float location, float weight, string adjective, int satellites, float rotationPeriod, bool spots, bool rings) : base(name, location, weight, adjective, satellites, rotationPeriod)
 {
     this.Kind  = "GasGiant";
     this.spots = spots;
     this.rings = rings;
     AstronomicalBody.AddAstBody();
 }
コード例 #4
0
ファイル: Star.cs プロジェクト: triabokon/OOP
 public Star(string name, float location, float weight, string type, string composition, float temperature) : base(name, location, weight)
 {
     this.Kind        = "Star";
     this.type        = type;
     this.composition = composition;
     this.temperature = temperature;
     AstronomicalBody.AddAstBody();
 }
コード例 #5
0
 public Star(string name, float x, float y, float z, float weight, string type, string composition, float temperature) : base(name, x, y, z, weight)
 {
     this.Kind        = Lab1_OOP.Type.Star;
     this.type        = type;
     this.composition = composition;
     this.temperature = temperature;
     AstronomicalBody.AddAstBody();
 }
コード例 #6
0
ファイル: Planet.cs プロジェクト: triabokon/OOP
 public Planet(string name, float x, float y, float z, float weight, string adjective, int satellites, float rotationPeriod) : base(name, x, y, z, weight)
 {
     this.Kind           = Type.Planet;
     this.adjective      = adjective;
     this.satellites     = satellites;
     this.rotationPeriod = rotationPeriod;
     AstronomicalBody.AddAstBody();
 }
コード例 #7
0
 public Planet(string name, float location, float weight, string adjective, int satellites, float rotationPeriod) : base(name, location, weight)
 {
     this.Kind           = "Planet";
     this.adjective      = adjective;
     this.satellites     = satellites;
     this.rotationPeriod = rotationPeriod;
     AstronomicalBody.AddAstBody();
 }
コード例 #8
0
ファイル: Program.cs プロジェクト: triabokon/OOP
        static void Main(string[] args)
        {
            try
            {
                //create a star
                Star star = new Star("Sun", 334.45567F, 345.5F, 456.2F, 2354436456.234435F, "Star", "He", 34546456.24F);

                //planet
                AstronomicalBody astBody = new AstronomicalBody("Kepler", 345.45F, 23.5F, 321.5F, 2.5900000000000000F);

                //asteroids
                AstronomicalBody ceres   = new AstronomicalBody("Ceres", 3345.4F, 789.4F, 347.83F, 7.3600000000000000F);
                AstronomicalBody fortuna = new AstronomicalBody("Fortuna", 795.67F, 41.3F, 78.4F, 9.3400000000000000F);

                Console.WriteLine("Start of the test: {0}", GC.GetTotalMemory(true));

                //create new system
                PlanetarySystem <AstronomicalBody> system = new PlanetarySystem <AstronomicalBody>(star);

                del Add = x => system.Add(x);

                //system forming
                Add(astBody);
                Add(ceres);
                Add(fortuna);

                Console.WriteLine("Сreating an object: {0}", GC.GetTotalMemory(true));

                GC.Collect();
                GC.WaitForPendingFinalizers();

                WeakReference wr = WR();
                Console.WriteLine("Is first object alive : " + wr.IsAlive.ToString());

                GC.Collect(2, GCCollectionMode.Forced);

                Console.WriteLine("Is first object alive : " + wr.IsAlive.ToString());

                system.Dispose();
                Console.WriteLine("System does not exist: " + (system.astBodies == null));// Ccилка  на список null
                Console.WriteLine(system.ToString());


                Console.ReadKey();
            }
            catch (InvalidAstBodyNameException e)
            {
                Console.WriteLine("Custom exception " + e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
コード例 #9
0
ファイル: PlanetSysExt.cs プロジェクト: triabokon/OOP
        public static AstronomicalBody getSmallestBody(this PlanetarySystem <AstronomicalBody> body)
        {
            AstronomicalBody smallestBody = body[0];

            for (int i = 0; i < body.Count; i++)
            {
                if (body[i].Weight < smallestBody.Weight)
                {
                    smallestBody = body[i];
                }
            }
            return(smallestBody);
        }
コード例 #10
0
ファイル: PlanetSysExt.cs プロジェクト: triabokon/OOP
        public static AstronomicalBody getBiggestBody(this PlanetarySystem <AstronomicalBody> body)
        {
            AstronomicalBody biggestBody = body[0];

            for (int i = 0; i < body.Count; i++)
            {
                if (body[i].Weight > biggestBody.Weight)
                {
                    biggestBody = body[i];
                }
            }
            return(biggestBody);
        }
コード例 #11
0
 static void Main(string[] args)
 {
     try
     {
         AstronomicalBody astBody   = new AstronomicalBody("4 Vesta", 345.45F, 2.5900000000000000F);
         Planet           earth     = new Planet("Earth", 2342.35F, 0.000023F, "-", 1, 0.997F);
         Star             sun       = new Star("Sun", 1.346F, 1.988000000000000000F, "G-type main-sequence star", "Hydrogen  Helium  Oxygen  Carbon", 1.570000000F);
         RedGiant         aldebaran = new RedGiant("Aldebaran", 23.56564F, 1.5F, "Hydrogen Carbon Titanium", 3910.34F, "new", false);
         GasGiant         saturn    = new GasGiant("Saturn", 34.245F, 5.680000000000F, "Cronian", 62, 10.55F, true, true);
         Console.WriteLine(astBody.ToString());
         Console.WriteLine(earth.ToString());
         Console.WriteLine(sun.ToString());
         Console.WriteLine(aldebaran.ToString());
         Console.WriteLine(saturn.ToString());
         Console.ReadKey();
     }
     catch (Exception e)
     {
         Console.WriteLine(e.Message);
     }
 }
コード例 #12
0
 public Planet()
 {
     this.Kind = "Planet";
     AstronomicalBody.AddAstBody();
 }
コード例 #13
0
 public Star()
 {
     this.Kind = "Star";
     AstronomicalBody.AddAstBody();
 }
コード例 #14
0
ファイル: SpaceShip.cs プロジェクト: triabokon/OOP
 public SpaceShip(string name, float location, float weight, AstronomicalBody start)
 {
     this.Name   = name;
     this.Weight = weight;
     this.Start  = start;
 }
コード例 #15
0
ファイル: Planet.cs プロジェクト: triabokon/OOP
 public Planet()
 {
     this.Kind = Type.Planet;
     AstronomicalBody.AddAstBody();
 }
コード例 #16
0
 private GasGiant()
 {
     this.Kind = Type.GasGiant; AstronomicalBody.AddAstBody();
 }
コード例 #17
0
ファイル: Program.cs プロジェクト: triabokon/OOP
        static void Main(string[] args)
        {
            try
            {
                //create a star
                Star star = new Star("Sun", 334.45567F, 345.5F, 456.2F, 2354436456.234435F, "Star", "He", 34546456.24F);
                //create new system
                PlanetarySystem <AstronomicalBody> system = new PlanetarySystem <AstronomicalBody>(star);
                //planet
                AstronomicalBody astBody = new AstronomicalBody("Kepler", 345.45F, 23.5F, 321.5F, 2.5900000000000000F);

                //asteroids
                AstronomicalBody ceres   = new AstronomicalBody("Ceres", 3345.4F, 789.4F, 347.83F, 7.3600000000000000F);
                AstronomicalBody fortuna = new AstronomicalBody("Fortuna", 795.67F, 41.3F, 78.4F, 9.3400000000000000F);

                del Add = x => system.Add(x);

                //system forming
                Add(astBody);
                Add(ceres);
                Add(fortuna);

                //show the new system
                Console.WriteLine("New System forms\n");
                int i = 0;
                while (i < system.Count)
                {
                    Console.WriteLine("{0}\n", system[i]);
                    i++;
                }

                //get the biggest body
                AstronomicalBody biggest = system.getBiggestBody();
                Console.WriteLine("Biggest body in system " + biggest.Name);

                Thread t1 = new Thread
                                (delegate()
                {
                    //save to file
                    Console.WriteLine("\n\nSave to file\n\n");
                    Serialization fileManager = new Serialization();
                    fileManager.WriteToFileFromClass(system.Bodies, @"D:\КПИ\ООП\OOP\lab3\Lab1_OOP\data\out.json");
                    Serialization.XmlSerialization(system);
                    PlanetarySystem <AstronomicalBody> system1 = new PlanetarySystem <AstronomicalBody>(star);
                    Serialization.XmlDeserialization(system1);
                });
                t1.Start();
                //space ship
                SpaceShip ship = new SpaceShip("Millenium falcon", 23.5645F, 19945645.45F, astBody);

                Console.WriteLine("\nShip {0} started from {1}\n", ship.Name, ship.Start.Name);

                //asteroid belt
                AsteroidBelt sp = new AsteroidBelt(ship);

                Thread.Sleep(2000);

                Console.WriteLine("Ship hit the asteroid belt\n");
                ship.Hit();

                Console.ReadKey();
            }
            catch (InvalidAstBodyNameException e)
            {
                Console.WriteLine("Custom exception " + e.Message);
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
コード例 #18
0
 public Star()
 {
     this.Kind = Lab1_OOP.Type.Star;
     AstronomicalBody.AddAstBody();
 }
コード例 #19
0
 public RedGiant(string name, float x, float y, float z, float weight, string composition, float temperature, string ageCategory, bool instability) : base(name, x, y, z, weight, "RedGiant", composition, temperature)
 {
     this.ageCategory = ageCategory;
     this.instability = instability;
     AstronomicalBody.AddAstBody();
 }
コード例 #20
0
 public RedGiant()
 {
     this.Kind = Lab1_OOP.Type.RedGiant; AstronomicalBody.AddAstBody();
 }
コード例 #21
0
 public RedGiant()
 {
     this.Kind = "RedGiant"; AstronomicalBody.AddAstBody();
 }
コード例 #22
0
 private GasGiant()
 {
     this.Kind = "GasGiant"; AstronomicalBody.AddAstBody();
 }