コード例 #1
0
        private void btnCreate_Click(object sender, EventArgs e)
        {
            u = new Universe();
            u.Name = "Test universe";
            u.Descrip = "For testing purposes only...";
            for (int i = 0; i < nudGal.Value; i++)
            {
                Galaxy g = new Galaxy((int)nudGalX.Value, (int)nudGalY.Value, (int)nudGalZ.Value);
                g.Name = "Test Milky Way";
                int j = (int)nudStars.Value;
                while (j > 0)
                {
                    Star s = new Star(g);
                    s.StarSystemName = "Alpha Test";
                    if (g.AddStar(s, ConstantParameters.MinDistanceBetweenStars))
                    {
                        int orbits = MrRandom.rnd.Next(ConstantParameters.MaxOrbitalBodiesForStar);
                        List<int> freeOrbits = new List<int>();
                        freeOrbits.AddRange(Orbits);
                        for (int k = 0; k < orbits; k++)
                        {
                            int bodyType = MrRandom.rnd.Next(3);

                            switch (bodyType)
                            {
                                case 0:
                                    Planet p = new Planet(s._id);
                                    p.Size = (PlanetSize)MrRandom.rnd.Next((int)PlanetSize.MrRandom);
                                    p.Type = (PlanetType)MrRandom.rnd.Next((int)PlanetType.MrRandom);
                                    p.OrbitNo = freeOrbits[MrRandom.rnd.Next(freeOrbits.Count)];
                                    freeOrbits.Remove(p.OrbitNo);
                                    s.OrbitalBodies.Add(p);
                                    break;
                            case 1:
                                GasGiant gg = new GasGiant (s._id);
                                    gg.Class = (GasGiantClass)MrRandom.rnd.Next ((int)GasGiantClass.MrRandom);
                                    gg.Size = (GasGiantSize)MrRandom.rnd.Next ((int)GasGiantSize.MrRandom);
                                    gg.OrbitNo = freeOrbits[MrRandom.rnd.Next(freeOrbits.Count)];
                                    freeOrbits.Remove(gg.OrbitNo);
                                    s.OrbitalBodies.Add(gg);
                                    break;
                                case 2:
                                    AsteroidBelt a = new AsteroidBelt(s._id);
                                    a.Density = (AsteroidDensity)MrRandom.rnd.Next((int)AsteroidDensity.MrRandom);
                                    a.Type = (AsteroidType)MrRandom.rnd.Next((int)AsteroidType.MrRandom);
                                    a.OrbitNo = freeOrbits[MrRandom.rnd.Next(freeOrbits.Count)];
                                    freeOrbits.Remove(a.OrbitNo);
                                    s.OrbitalBodies.Add(a);
                                    break;
                            }
                        }
                        j = j - 1;
                    }
                }
                u.Galaxies.Add(g);
            }
            ShowStats();
        }
コード例 #2
0
ファイル: MySqlDBHelper.cs プロジェクト: GSazheniuk/HOO
        public DBCommandResult AddOrbitalBody(StarOrbitalBody sob)
        {
            DBCommandResult res = new DBCommandResult();

            if (sob is Planet)
            {
                Planet p = (Planet)sob;
                MySqlCommand com = new MySqlCommand("ADM_AddStarOrbitalBody", _dg.Connection);
                com.CommandType = CommandType.StoredProcedure;

                MySqlParameter spStarId = new MySqlParameter("pStarId", p.StarId);
                MySqlParameter spOrbitNo = new MySqlParameter("pOrbitNo", p.OrbitNo);
                MySqlParameter spBodyType = new MySqlParameter("pBodyType", 1);
                MySqlParameter spSize = new MySqlParameter("pSize", p.Size);
                MySqlParameter spType = new MySqlParameter("pClass", p.Type);

                com.Parameters.AddRange(new MySqlParameter[] { spStarId, spSize, spOrbitNo, spType, spBodyType });

                try
                {
                    DataSet ds = _dg.GetDataSet(com);
                    DataRow dr = ds.Tables[0].Rows[0];
                    Planet rp = new Planet(sob.StarId);
                    rp.OBID = Convert.ToInt32(dr["OBID"]);
                    rp.OrbitNo = Convert.ToInt32(dr["OrbitNo"]);
                    rp.Size = (PlanetSize)Convert.ToInt32(dr["Size"]);
                    rp.Type = (PlanetType)Convert.ToInt32(dr["Class"]);
                    res.Tag = rp;
                    res.ResultCode = 0;
                    res.ResultMsg = "Ok";
                }
                catch (Exception ex)
                {
                    res.ResultCode = -2;
                    res.ResultMsg = String.Format("{0} ----> {1}", ex.Message, (ex.InnerException != null)?ex.InnerException.Message:"");
                }
                return res;
            }

            if (sob is GasGiant)
            {
                GasGiant p = (GasGiant)sob;
                MySqlCommand com = new MySqlCommand("ADM_AddStarOrbitalBody", _dg.Connection);
                com.CommandType = CommandType.StoredProcedure;

                MySqlParameter spStarId = new MySqlParameter("pStarId", p.StarId);
                MySqlParameter spOrbitNo = new MySqlParameter("pOrbitNo", p.OrbitNo);
                MySqlParameter spBodyType = new MySqlParameter("pBodyType", 2);
                MySqlParameter spSize = new MySqlParameter("pSize", p.Size);
                MySqlParameter spType = new MySqlParameter("pClass", p.Class);

                com.Parameters.AddRange(new MySqlParameter[] { spStarId, spSize, spOrbitNo, spType, spBodyType });

                try
                {
                    DataSet ds = _dg.GetDataSet(com);
                    DataRow dr = ds.Tables[0].Rows[0];
                    GasGiant rg = new GasGiant(sob.StarId);
                    rg.OBID = Convert.ToInt32(dr["OBID"]);
                    rg.OrbitNo = Convert.ToInt32(dr["OrbitNo"]);
                    rg.Class = (GasGiantClass)Convert.ToInt32(dr["Class"]);
                    rg.Size = (GasGiantSize)Convert.ToInt32(dr["Size"]);
                    res.Tag = rg;
                    res.ResultCode = 0;
                    res.ResultMsg = "Ok";
                }
                catch (Exception ex)
                {
                    res.ResultCode = -2;
                    res.ResultMsg = String.Format("{0} ----> {1}", ex.Message, (ex.InnerException != null)?ex.InnerException.Message:"");
                }
                return res;
            }

            if (sob is AsteroidBelt)
            {
                AsteroidBelt p = (AsteroidBelt)sob;
                MySqlCommand com = new MySqlCommand("ADM_AddStarOrbitalBody", _dg.Connection);
                com.CommandType = CommandType.StoredProcedure;

                MySqlParameter spStarId = new MySqlParameter("pStarId", p.StarId);
                MySqlParameter spOrbitNo = new MySqlParameter("pOrbitNo", p.OrbitNo);
                MySqlParameter spBodyType = new MySqlParameter("pBodyType", 3);
                MySqlParameter spSize = new MySqlParameter("pSize", p.Density);
                MySqlParameter spType = new MySqlParameter("pClass", p.Type);

                com.Parameters.AddRange(new MySqlParameter[] { spStarId, spSize, spOrbitNo, spType, spBodyType });

                try
                {
                    DataSet ds = _dg.GetDataSet(com);
                    DataRow dr = ds.Tables[0].Rows[0];
                    AsteroidBelt ra = new AsteroidBelt(sob.StarId);
                    ra.OBID = Convert.ToInt32(dr["OBID"]);
                    ra.OrbitNo = Convert.ToInt32(dr["OrbitNo"]);
                    ra.Density = (AsteroidDensity)Convert.ToInt32(dr["Size"]);
                    ra.Type = (AsteroidType)Convert.ToInt32(dr["Class"]);

                    res.Tag = ra;
                    res.ResultCode = 0;
                    res.ResultMsg = "Ok";
                }
                catch (Exception ex)
                {
                    res.ResultCode = -2;
                    res.ResultMsg = String.Format("{0} ----> {1}", ex.Message, (ex.InnerException != null)?ex.InnerException.Message:"");
                }
                return res;
            }
            return res;
        }
コード例 #3
0
        public DBCommandResult GetStarOrbitalBodies(Star s)
        {
            DBCommandResult res = new DBCommandResult ();

            MySqlCommand com = new MySqlCommand ("ADM_GetStarOrbitalBodies", _dg.Connection);
            com.CommandType = CommandType.StoredProcedure;
            MySqlParameter spStarId = new MySqlParameter("pStarId", s.OBID);
            com.Parameters.Add(spStarId);

            try
            {
                DataSet ds = _dg.GetDataSet(com);
                s.OrbitalBodies = new List<StarOrbitalBody>();

                foreach(DataRow dr in ds.Tables[0].Rows)
                {
                    switch (Convert.ToInt32(dr["BodyType"]))
                    {
                    case 1:
                        Planet p = new Planet(s._id);
                        p.OrbitNo = Convert.ToInt32(dr["OrbitNo"]);
                        p.Size = (PlanetSize)Convert.ToInt32(dr["Size"]);
                        p.Type = (PlanetType)Convert.ToInt32(dr["Class"]);
                        p.OBID = Convert.ToInt32(dr["OBID"]);
                        s.OrbitalBodies.Add(p);
                        break;
                    case 2:
                        GasGiant g = new GasGiant(s._id);
                        g.OrbitNo = Convert.ToInt32(dr["OrbitNo"]);
                        g.Size = (GasGiantSize)Convert.ToInt32(dr["Size"]);
                        g.Class = (GasGiantClass)Convert.ToInt32(dr["Class"]);
                        g.OBID = Convert.ToInt32(dr["OBID"]);
                        s.OrbitalBodies.Add(g);
                        break;
                    case 3:
                        AsteroidBelt a = new AsteroidBelt(s._id);
                        a.OrbitNo = Convert.ToInt32(dr["OrbitNo"]);
                        a.Density = (AsteroidDensity)Convert.ToInt32(dr["Size"]);
                        a.Type = (AsteroidType)Convert.ToInt32(dr["Class"]);
                        a.OBID = Convert.ToInt32(dr["OBID"]);
                        s.OrbitalBodies.Add(a);
                        break;
                    }
                }

                res.ResultCode = 0;
                res.ResultMsg = "Ok";
                res.Tag = s;
            }
            catch (Exception ex) {
                res.ResultCode = -2;
                res.ResultMsg = String.Format ("{0} ----> {1}", ex.Message, (ex.InnerException != null) ? ex.InnerException.Message : "");
            }
            return res;
        }
コード例 #4
0
ファイル: StarHelper.cs プロジェクト: GSazheniuk/HOO
        public Star GenerateNewStar(Galaxy g)
        {
            Star s = new Star();
            s._id = g.Stars.Count;

            while (!g.AddStar(s, ConstantParameters.MinDistanceBetweenStars))
            {

            }

            s.StarSystemName = this.GenerateStarName();
            StarOrbitalBodyHelper sobHelper = new StarOrbitalBodyHelper();

            //s.Coordinates = new Point3D() { X = MrRandom.rnd.Next(1000), Y = MrRandom.rnd.Next(800), Z = MrRandom.rnd.Next(600) };
            int orbits = MrRandom.rnd.Next(ConstantParameters.MaxOrbitalBodiesForStar);
            s.OrbitalIDs = new long[orbits];
            List<int> freeOrbits = new List<int>();
            freeOrbits.AddRange(new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 });
            for (int k = 0; k < orbits; k++)
            {
                int bodyType = MrRandom.rnd.Next(3);

                switch (bodyType)
                {
                    case 0:
                        Planet p = new Planet(s._id);
                        p._id = 10 * s._id + s.OrbitalBodies.Count;
                        s.OrbitalIDs[k] = p._id;
                        p.Size = (PlanetSize)MrRandom.rnd.Next((int)PlanetSize.MrRandom);
                        p.Type = (PlanetType)MrRandom.rnd.Next((int)PlanetType.MrRandom);
                        p.OrbitNo = freeOrbits[MrRandom.rnd.Next(freeOrbits.Count)];
                        p.StarSystemName = s.StarSystemName;
                        freeOrbits.Remove(p.OrbitNo);
                        s.OrbitalBodies.Add(p);
                        sobHelper.OrbitalBody = p;
                        break;
                    case 1:
                        GasGiant gg = new GasGiant(s._id);
                        gg._id = 10 * s._id + s.OrbitalBodies.Count;
                        s.OrbitalIDs[k] = gg._id;
                        gg.Class = (GasGiantClass)MrRandom.rnd.Next((int)GasGiantClass.MrRandom);
                        gg.Size = (GasGiantSize)MrRandom.rnd.Next((int)GasGiantSize.MrRandom);
                        gg.OrbitNo = freeOrbits[MrRandom.rnd.Next(freeOrbits.Count)];
                        gg.StarSystemName = s.StarSystemName;
                        freeOrbits.Remove(gg.OrbitNo);
                        s.OrbitalBodies.Add(gg);
                        sobHelper.OrbitalBody = gg;
                        break;
                    case 2:
                        AsteroidBelt a = new AsteroidBelt(s._id);
                        a._id = 10 * s._id + s.OrbitalBodies.Count;
                        s.OrbitalIDs[k] = a._id;
                        a.Density = (AsteroidDensity)MrRandom.rnd.Next((int)AsteroidDensity.MrRandom);
                        a.Type = (AsteroidType)MrRandom.rnd.Next((int)AsteroidType.MrRandom);
                        a.OrbitNo = freeOrbits[MrRandom.rnd.Next(freeOrbits.Count)];
                        a.StarSystemName = s.StarSystemName;
                        freeOrbits.Remove(a.OrbitNo);
                        s.OrbitalBodies.Add(a);
                        sobHelper.OrbitalBody = a;
                        break;
                }
                sobHelper.Save();
            }

            SaveStar(s);
            this.Star = s;
            return s;
        }