示例#1
0
        private void RandomlyCreateSolarSystem(Random random, int i)
        {
            var solarSystem = new SolarSystem();
            solarSystem.Name = this.RandomlyCreateSolarSystemName(random, i);
            solarSystem.Coordinates = new Coordinates
            {
                X = random.Next(2000) - 1000,
                Y = random.Next(2000) - 1000,
                Z = 0
            };

            _solarSystems.CreateSolarSystem(solarSystem);
        }
示例#2
0
        public Int64 CreateJourney(SolarSystem from, SolarSystem to, string description, DateTime start, TimeSpan duration)
        {
            var jobID = this.CreateJob(description, start, duration);
            using(var cmd = this.SessionManager.GetCurrentUnitOfWork().CreateCommand("INSERT INTO Journeys (JobID, StartSolarSystemID, EndSolarSystemID) VALUES (@JobID, @StartSolarSystemID, @EndSolarSystemID)"))
            {
                cmd.AddParameter("JobID", DbType.Int64, jobID);
                cmd.AddParameter("StartSolarSystemID", DbType.Int64, from.SolarSystemID);
                cmd.AddParameter("EndSolarSystemID", DbType.Int64, to.SolarSystemID);

                cmd.ExecuteNonQuery();

                return jobID;
            }
        }
示例#3
0
        public SolarSystem CreateSolarSystem(SolarSystem solarSystem)
        {
            if(solarSystem == null) throw new ArgumentNullException("solarSystem");

            var query = "INSERT INTO SolarSystems (Name, X, Y, Z) VALUES (@Name, @X, @Y, @Z) select scope_identity()";

            using (var cmd = this.SessionManager.GetCurrentUnitOfWork().CreateCommand(query))
            {
                cmd.AddParameter("Name", DbType.String, solarSystem.Name);
                cmd.AddParameter("X", DbType.Int64, solarSystem.Coordinates.X);
                cmd.AddParameter("Y", DbType.Int64, solarSystem.Coordinates.Y);
                cmd.AddParameter("Z", DbType.Int64, solarSystem.Coordinates.Z);

                solarSystem.SolarSystemID = (long)(decimal)cmd.ExecuteScalar();

                return solarSystem;
            }
        }
示例#4
0
        public Ship CreateShip(SolarSystem located, UserAccount owner, string name)
        {
            int id;
            var query = string.Concat("INSERT INTO Ships (", string.Join(", ", RequiredFields), ") VALUES (", string.Join(", ", RequiredFields.Select(f => string.Concat("@", f))), ") SELECT Scope_Identity()");
            using (var cmd = this.SessionManager.GetCurrentUnitOfWork().CreateCommand(query))
            {
                cmd.AddParameter("UserAccountID", DbType.Int32, owner.UserAccountID);
                cmd.AddParameter("Name", DbType.String, name);
                cmd.AddParameter("SolarSystemID", DbType.Int64, located.SolarSystemID);
                cmd.AddParameter("IsSelected", DbType.Boolean, 0);
                cmd.AddParameter("JobID", DbType.Int64, DBNull.Value);
                cmd.AddParameter("EmpireID", DbType.Int32, owner.EmpireID);

                id = (int)(decimal)cmd.ExecuteScalar();
            }

            return this.GetShip(id);
        }
 private static NavigationManager CreateNavigationManagerToReturnSolarSystem(SolarSystem solarSystem, UserAccount userAccount = null)
 {
     var securityManager = new Mock<ISecurityManager>();
     securityManager.SetupGetCurrentUserAccountToReturnUserAccount(userAccount);
     var solarSystems = new Mock<ISolarSystems>();
     solarSystems.SetupFindSystemsInLocalArea(solarSystem);
     var manager = Create.BusinessLogicClass.NavigationManager(securityManager.Object, solarSystems.Object);
     return manager;
 }
 private static void AssertCoordinatesAreCorrect(SolarSystem solarSystem, LocalAreaViewResult result)
 {
     Assert.AreEqual(solarSystem.Coordinates.X, result.SolarSystems.Single().Coordinates.X);
     Assert.AreEqual(solarSystem.Coordinates.Y, result.SolarSystems.Single().Coordinates.Y);
     Assert.AreEqual(solarSystem.Coordinates.Z, result.SolarSystems.Single().Coordinates.Z);
 }
示例#7
0
 private SolarSystem InflateSolarSystem(IDataReader dr)
 {
     var solarSystem = new SolarSystem();
     this.CopyCoreProperties(solarSystem, dr);
     return solarSystem;
 }
示例#8
0
 private void CopyCoreProperties(SolarSystem solarSystem, IDataReader dr)
 {
     solarSystem.SolarSystemID = dr.GetInt64("SolarSystemID");
     solarSystem.Name = dr.GetString("Name");
     solarSystem.Coordinates = new Coordinates
     {
         X = dr.GetInt64("X"),
         Y = dr.GetInt64("Y"),
         Z = dr.GetInt64("Z")
     };
 }
示例#9
0
        private TimeSpan GetDurationOfJourney(SolarSystem startSolarSystem, SolarSystem destinationSolarSystem, IEnumerable<Ship> shipsAtThatLocation)
        {
            const int timeItTakesToCrossASquare = 5; // how long does it take to cross one square
            var diffX = startSolarSystem.Coordinates.X - destinationSolarSystem.Coordinates.X;
            var diffY = startSolarSystem.Coordinates.Y - destinationSolarSystem.Coordinates.Y;
            var diffZ = startSolarSystem.Coordinates.Z - destinationSolarSystem.Coordinates.Z;
            var flatDistance = Math.Sqrt(Math.Pow(diffX, 2) + Math.Pow(diffY, 2));
            var threeDDistance = Math.Sqrt(Math.Pow(flatDistance, 2) + Math.Pow(diffZ, 2)); // the distance we're travelling

            // Working out the various speeds (ship and game)
            var minSpeed = (double)shipsAtThatLocation.Min(s => s.Speed);
            var gameSpeed = (double)decimal.Divide(1, _configurationManager.GameSpeed);

            // How long will the trip take?
            var minutes = (timeItTakesToCrossASquare * threeDDistance) / (gameSpeed * minSpeed);
            var roundedMinutes = (int)Math.Floor(minutes);
            var seconds = (int)(60 * (minutes - roundedMinutes));

            return new TimeSpan(0, roundedMinutes, seconds);
        }