/// <summary> /// Uses vector math to update the ship's location. /// </summary> /// <param name="shippyUpdate">Ship to be updated.</param> /// <param name="starry">star for gravity</param> private void updateShipLocation(ship shippyUpdate, star starry) { Vector2D gravity = starry.loc - shippyUpdate.loc; // Find the vector from the ship to the star. gravity.Normalize(); // Turn the vector into a unit-length direction by normalizing. gravity *= starry.mass; // Adjust strentth of vector by multiplying star's mass. Vector2D thrust; //We need to only do this thrus if the ship is thrusting, otherwise the star will only have the impact on the ship if (shippyUpdate.getThrust() == true) { thrust = shippyUpdate.GetDirections(); // So long as rotate is only ever applied, should always be normalized. thrust = thrust * (engineStrength); // Adjust the length of the vector by multiplying by the engine strength. shippyUpdate.setThrust(false); } else { thrust = new Vector2D(0, 0); // no thrust for you. } Vector2D acceleration = gravity + thrust; // combine all forces. shippyUpdate.velocity += acceleration; // Add acceleration to velocity. shippyUpdate.loc = shippyUpdate.loc + shippyUpdate.velocity; // Apply new velocity to position. checkIfOffScreen(shippyUpdate); // Wraparound if offscreen. }
public bool TaskBind(string loginName, string newtaskName, string routeName, string shipName) { waterdataEntities entity = new waterdataEntities(); users objuser = entity.users.SingleOrDefault(s => s.login_name == loginName); task mytask = entity.task.SingleOrDefault(s => s.task_name == newtaskName && s.user_id == objuser.user_id); ship ship = entity.ship.FirstOrDefault(s => s.ship_name == s.ship_name && s.company_id == objuser.company_id); if (mytask == null) { route myroute = entity.route.SingleOrDefault(s => s.route_name == routeName && s.user_id == objuser.user_id); if (myroute != null) { task newtask = new task() { ship_id = ship.ship_id, user_id = objuser.user_id, route_id = myroute.route_id, task_name = newtaskName, create_time = DateTime.Now }; entity.task.Add(newtask); entity.SaveChanges(); return(true); } } else { return(false); } return(false); }
public bool SendParameter(int shipId, string str) { string[] strs = str.Split('|'); foreach (var item in strs) { waterdataEntities entity = new waterdataEntities(); task lasttask = entity.task.Where(s => s.ship_id == shipId && s.route_id != null).OrderByDescending(s => s.create_time).First(); ship ship = entity.ship.SingleOrDefault(s => s.ship_id == shipId); WaterData waterdata = DataParse.dealSensorData(item); parameter parameter = entity.parameter.SingleOrDefault(s => s.parameter_name == waterdata.ParameterName && s.company_id == ship.company_id); waterdata.ParameterId = parameter.parameter_id.ToString(); waterdata.TaskId = lasttask.task_id.ToString(); water_data newdata = new water_data() { task_id = Convert.ToInt32(waterdata.TaskId), parameter_id = Convert.ToInt32(waterdata.ParameterId), parameter_value = Convert.ToDouble(waterdata.ParameterValue), longitude = Convert.ToDouble(waterdata.Longitude), latitude = Convert.ToDouble(waterdata.Latitude), create_time = DateTime.Now }; entity.water_data.Add(newdata); entity.SaveChanges(); } return(true); }
public bool AddNewTask(string newtaskName, string newrouteName, string shipName, string loginName, string points) { waterdataEntities entity = new waterdataEntities(); RouteService routeservice = new RouteService(); users user = entity.users.FirstOrDefault(s => s.login_name == loginName); task task = entity.task.FirstOrDefault(s => s.task_name == newtaskName && s.user_id == user.user_id); route route = entity.route.FirstOrDefault(s => s.route_name == newrouteName); ship ship = entity.ship.FirstOrDefault(s => s.ship_name == s.ship_name && s.company_id == user.company_id); if (task != null || route != null) { return(false); } if (routeservice.AddRoute(loginName, newrouteName, points)) { route newroute = entity.route.SingleOrDefault(s => s.route_name == newrouteName && s.user_id == user.user_id); task newTask = new task() { ship_id = ship.ship_id, task_name = newtaskName, route_id = newroute.route_id, user_id = user.user_id, create_time = DateTime.Now }; entity.task.Add(newTask); entity.SaveChanges(); } else { return(false); } return(true); }
/// <summary> /// 修改船体信息 /// </summary> /// <param name="shipName"></param> /// <param name="companyName"></param> /// <param name="devicesrial"></param> /// <param name="newshipName"></param> /// <param name="newcompanyName"></param> /// <param name="newdevicesrial"></param> /// <returns></returns> public bool UpdateShip(string shipName, string companyName, string devicesrial, string newshipName, string newcompanyName, string newdevicesrial, string newReminder) { waterdataEntities entity = new waterdataEntities(); entity.Configuration.ValidateOnSaveEnabled = false; bool result = false; ship objship = entity.ship.FirstOrDefault(s => s.ship_name == shipName && s.company.company_name == companyName && s.device_serial == devicesrial); if (objship != null) { if (newshipName != null) { objship.ship_name = newshipName; result = true; } if (newcompanyName != null) { company objcompany = entity.company.SingleOrDefault(s => s.company_name == newcompanyName);//如果公司存在 objship.company_id = objcompany.company_id; result = true; } if (newdevicesrial != null) { objship.device_serial = newdevicesrial; result = true; } if (newReminder != null) { objship.reminder = newReminder; result = true; } entity.SaveChanges(); } return(result); }
public ActionResult Index(string post) { if (Request.Params["SerialKey"] != null && Request.Params["ActivationKey"] != null) { string regKey = Request.Params["ActivationKey"].ToString(); if (Registration.ValidateRegistration(regKey)) { Key actKey = new Key(); actKey.SerialKey = Request.Params["SerialKey"].ToString(); actKey.ActivationKey = Request.Params["ActivationKey"].ToString(); db.Keys.AddObject(actKey); db.SaveChanges(); ship serShip = new ship(); serShip.serial_number = Request.Params["SerialKey"].ToString(); db.ships.AddObject(serShip); db.SaveChanges(); user adm = new user(); adm.firstname = "Admin"; adm.lastname = "Admin"; adm.user_name = "admin"; adm.password = "******"; adm.ship_id = serShip.ship_id; adm.rank_id = 1; db.users.AddObject(adm); db.SaveChanges(); return(RedirectToAction("Login", "Account")); } ViewBag.Error = "Invalid Activation Key. Please contact the administartor"; } CheckRegistration(); return(View()); }
public List <Task> GetTaskBySTN(string shipName, string taskName, string loginName, int page, int limit) { waterdataEntities entity = new waterdataEntities(); users objuser = entity.users.SingleOrDefault(s => s.login_name == loginName); ship objship = entity.ship.SingleOrDefault(s => s.ship_name == shipName); IQueryable <task> query = entity.task.Where(s => s.user_id == objuser.user_id && s.ship_id == objship.ship_id && s.task_name == taskName).OrderByDescending(s => s.create_time); List <Task> tasks = new List <Task>(); foreach (var item in query) { tasks.Add(new Task() { ShipName = item.ship.ship_name, TaskName = item.task_name, RouteName = item.route.route_name, CreateTime = item.create_time.ToString() }); } int strat = (page - 1) * limit; int end = strat + limit; List <Task> newtasks = new List <Task>(); for (int i = strat; i < end && i < tasks.Count; i++) { newtasks.Add(tasks[i]); } return(newtasks); }
/// <summary> /// Creates a projectile from passed in ship. /// </summary> /// <param name="ship_"></param> public void createProjectile(ship ship_) { Vector2D dur = new Vector2D(ship_.dir.GetX(), ship_.dir.GetY()); projectile project = new projectile(countOfProjectil, ship_.ID, ship_.loc, dur); projectilesInWorld.TryAdd(countOfProjectil, project); countOfProjectil++; }
public ActionResult DeleteConfirmed(int id) { ship ship = db.ships.Single(s => s.ship_id == id); db.ships.DeleteObject(ship); db.SaveChanges(); return(RedirectToAction("Index")); }
public void Update() { Name.text = Card.name; desc.text = Card.desc; part = Card.part; part = Card.part; ship = GameObject.FindObjectOfType <ship>(); }
// // GET: /Ship/Delete/5 public ActionResult Delete(int id = 0) { ship ship = db.ships.Single(s => s.ship_id == id); if (ship == null) { return(HttpNotFound()); } return(View(ship)); }
public IHttpActionResult Post([FromBody] ship t) { try { return(Ok(context.InsertAndGetItem(t))); } catch (Exception ex) { return(Content(HttpStatusCode.NotAcceptable, ex.Message)); } }
public ActionResult Create(ship ship) { if (ModelState.IsValid) { db.ships.AddObject(ship); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(ship)); }
public ActionResult Edit(ship ship) { if (ModelState.IsValid) { db.ships.Attach(ship); db.ObjectStateManager.ChangeObjectState(ship, EntityState.Modified); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(ship)); }
public IHttpActionResult Put(int id, [FromBody] ship value) { try { return(Ok(context.UpdateAndGetItem(value))); } catch (Exception ex) { return(Content(HttpStatusCode.NotModified, ex.Message)); } }
public async Task <ship> Add(ship item) { var result = await client.PostAsync <ship>("Post", item); if (result != default(ship)) { Source.Add(result); SourceView.Refresh(); } return(result); }
public void ShipThrustingTrue() { World world = new World(); Socket socket; IPAddress ip; networking.MakeSocket("localhost", out socket, out ip); SocketState ss = new SocketState(socket); ship sh = new ship(1, ss, 5, new Vector2D(8, 8), "JoCee", 0, new Vector2D(9, 9), 7); sh.Thrust(); }
public void GetLocationY() { World world = new World(); Socket socket; IPAddress ip; networking.MakeSocket("localhost", out socket, out ip); SocketState ss = new SocketState(socket); ship sh = new ship(1, ss, 5, new Vector2D(8, 8), "JoCee", 0, new Vector2D(9, 9), 7); Assert.AreEqual(sh.GetLocation().GetY(), 8); }
public static void createJson() { ship customShipCreation = new ship(); customShipCreation.ShipName = ShipName; customShipCreation.Manufacturer = manufacturer; customShipCreation.Dimensions = new double[] { Convert.ToDouble(L), Convert.ToDouble(W), Convert.ToDouble(H) }; customShipCreation.LandingPadSize = landingPadSize; customShipCreation.Type = type_of_ship; customShipCreation.Cost = Int32.Parse(cost); customShipCreation.Insurance = Int32.Parse(Insurance); customShipCreation.TopSpeed = Int32.Parse(TopSpeed); customShipCreation.MaxSpeed = Int32.Parse(MaxSpeed); customShipCreation.BoostSpeed = Int32.Parse(BoostSpeed); customShipCreation.MaxBoostSpeed = Int32.Parse(MaxBoostSpeed); customShipCreation.Manoeuvrability = Int32.Parse(manoeuvrability_); customShipCreation.Shields = Int32.Parse(Shields); customShipCreation.Armor = Int32.Parse(armor_); customShipCreation.HullMass = Int32.Parse(hullMass); customShipCreation.Seats = Int32.Parse(seats_); customShipCreation.FighterBay = bool.Parse(fighterBay); customShipCreation.MaxFighterBayTier = Int32.Parse(maxFighterBayTier); customShipCreation.CargoCapacity = Int32.Parse(cargoCapacity); customShipCreation.MaxCargo = Int32.Parse(maxCargo); customShipCreation.FuelCapacity = Int32.Parse(fuelCapacity); customShipCreation.UnladenJump = Double.Parse(unladenJump); customShipCreation.MaxJump = Double.Parse(maxJump); customShipCreation.MassLockFactor = Int32.Parse(massLockFactor); customShipCreation.Utility = Int32.Parse(utility_); customShipCreation.Small = Int32.Parse(small_); customShipCreation.Medium = Int32.Parse(medium_); customShipCreation.Large = Int32.Parse(large_); customShipCreation.Huge = Int32.Parse(huge_); customShipCreation.Size1 = Int32.Parse(size1_); customShipCreation.Size2 = Int32.Parse(size2_); customShipCreation.Size3 = Int32.Parse(size3_); customShipCreation.Size4 = Int32.Parse(size4_); customShipCreation.Size5 = Int32.Parse(size5_); customShipCreation.Size6 = Int32.Parse(size6_); customShipCreation.Size7 = Int32.Parse(size7_); customShipCreation.Size8 = Int32.Parse(size8_); customShipCreation.Military_Slot1 = Int32.Parse(military_slot1); customShipCreation.Military_Slot2 = Int32.Parse(military_slot2); string json = JsonConvert.SerializeObject(customShipCreation, Formatting.Indented); try { File.WriteAllText(DataFolder + ShipName + ".json", json); } catch (DirectoryNotFoundException) { Directory.CreateDirectory(DataFolder); File.WriteAllText(DataFolder + ShipName + ".json", json); } }
public void decreaseHp() { World world = new World(); Socket socket; IPAddress ip; networking.MakeSocket("localhost", out socket, out ip); SocketState ss = new SocketState(socket); ship sh = new ship(1, ss, 5, new Vector2D(8, 8), "JoCee", 0, new Vector2D(8, 9), 7); sh.decreaseHP(6); Assert.AreEqual(4, sh.hp); }
public void CreateWorld() { World world = new World(); Socket socket; IPAddress ip; networking.MakeSocket("localhost", out socket, out ip); SocketState ss = new SocketState(socket); ship sh = new ship(1, ss, 5, new Vector2D(8, 8), "JoCee", 0, new Vector2D(8, 9), 7); world.AddShip(ss, sh); Assert.AreEqual(1, world.shipsInWorld.Count); }
public bool RouteChange(string taskName, string routeName, string loginName, string shipName) { waterdataEntities entity = new waterdataEntities(); users objuser = entity.users.SingleOrDefault(s => s.login_name == loginName); task mytask = entity.task.SingleOrDefault(s => s.task_name == taskName && s.user_id == objuser.user_id); route route = entity.route.SingleOrDefault(s => s.route_name == routeName && s.user_id == objuser.user_id); ship ship = entity.ship.SingleOrDefault(s => s.ship_name == shipName && s.company_id == objuser.company_id); mytask.ship_id = ship.ship_id; mytask.route_id = route.route_id; entity.SaveChanges(); return(true); }
public void kill() { World world = new World(); Socket socket; IPAddress ip; networking.MakeSocket("localhost", out socket, out ip); SocketState ss = new SocketState(socket); ship sh = new ship(1, ss, 5, new Vector2D(8, 8), "JoCee", 0, new Vector2D(8, 9), 7); sh.kill(30); Assert.AreEqual(true, sh.dead); }
public void collisionStarTesting() { World world = new World(); Socket socket; IPAddress ip; networking.MakeSocket("localhost", out socket, out ip); SocketState ss = new SocketState(socket); ship sh = new ship(1, ss, 5, new Vector2D(8, 8), "JoCee", 0, new Vector2D(8, 9), 7); world.addStar(30, 7, 7); world.detectCollisions(30, 30, 30); Assert.AreEqual(false, sh.dead == true); }
/// <summary> /// 删除船体信息 /// </summary> /// <param name="shipName"></param> /// <param name="companyName"></param> /// <returns></returns> public bool DeleteShip(string shipName, string companyName) { waterdataEntities entity = new waterdataEntities(); bool result = false; ship objship = entity.ship.FirstOrDefault(s => s.ship_name == shipName && s.company.company_name == companyName); if (objship != null) { entity.ship.Remove(objship); entity.SaveChanges(); result = true; } return(result); }
public void ResetProjectileDelay() { World world = new World(); Socket socket; IPAddress ip; networking.MakeSocket("localhost", out socket, out ip); SocketState ss = new SocketState(socket); ship sh = new ship(1, ss, 5, new Vector2D(8, 8), "JoCee", 0, new Vector2D(9, 9), 7); sh.resetProjectileDelay(8); sh.decreaseProjectileDelay(); Assert.AreEqual(7, sh.projectileFiringDelayTimer); }
public ship UpdateAndGetItem(ship t) { using (var db = new OcphDbContext()) { if (db.Ships.Update(O => new { O.Description, O.Name }, t, O => O.Id == t.Id)) { return(t); } else { throw new SystemException(MessageCollection.Message(MessageType.UpdateFaild)); } } }
public static void createExampleJson() { ship Sidewinder = new ship(); Sidewinder.ShipName = "Sidewinder"; Sidewinder.Manufacturer = "Faulcon DeLacy"; Sidewinder.Dimensions = new double[] { 14.9, 21.3, 5.4 }; Sidewinder.LandingPadSize = "Small"; Sidewinder.Type = "Light Multipurpose"; Sidewinder.Cost = 48000; Sidewinder.Insurance = 1600; Sidewinder.TopSpeed = 220; Sidewinder.MaxSpeed = 255; Sidewinder.BoostSpeed = 320; Sidewinder.MaxBoostSpeed = 371; Sidewinder.Manoeuvrability = 5; Sidewinder.Shields = 40; Sidewinder.Armor = 108; Sidewinder.HullMass = 25; Sidewinder.Seats = 1; Sidewinder.FighterBay = false; Sidewinder.MaxFighterBayTier = 0; Sidewinder.CargoCapacity = 4; Sidewinder.MaxCargo = 12; Sidewinder.FuelCapacity = 2; Sidewinder.UnladenJump = 7.56; Sidewinder.MaxJump = 24.43; Sidewinder.MassLockFactor = 6; Sidewinder.Utility = 2; Sidewinder.Small = 2; Sidewinder.Medium = 0; Sidewinder.Large = 0; Sidewinder.Huge = 0; Sidewinder.Size1 = 2; Sidewinder.Size2 = 2; Sidewinder.Size3 = 0; Sidewinder.Size4 = 0; Sidewinder.Size5 = 0; Sidewinder.Size6 = 0; Sidewinder.Size7 = 0; Sidewinder.Size8 = 0; Sidewinder.Military_Slot1 = 0; Sidewinder.Military_Slot2 = 0; Sidewinder.Military_Slot3 = 0; string json = JsonConvert.SerializeObject(Sidewinder, Formatting.Indented); File.WriteAllText(DataFolder + "Sidewinder.json", json); }
public ActionResult Index(ship postback, string sell_id) { if (this.ModelState.IsValid) { //取得目前購物車 var currentcart = Carts.Models.Cart.Operation.GetCurrentCart(); //取得目前登入使用者Id var userId = User.Identity.GetUserName(); using (farmarEntities1 db = new farmarEntities1()) { //建立Order物件 order order = new order() { buy_id = userId, buy_Name = postback.buy_Name, buy_Phone = postback.buy_phone, buy_Address = postback.buy_Address, order_category = "非預購", build_time = DateTime.Now, sell_id = sell_id, status = "未付款", }; //加其入Orders資料表後,儲存變更 db.orders.Add(order); try { db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { throw ex; } //取得購物車中OrderDetai物件 var orderDetails = currentcart.ToOrderDetailList(order.order_id); var orders = from c in orderDetails where c.sell_id == sell_id select c; //將其加入OrderDetails資料表後,儲存變更 db.order_detail.AddRange(orders); db.SaveChanges(); var currentCart = Operation.GetCurrentCart(); currentCart.Removesell_id(sell_id); } return(RedirectToAction("Orders")); } return(View()); }
public ship InsertAndGetItem(ship t) { using (var db = new OcphDbContext()) { t.Id = db.Ships.InsertAndGetLastID(t); if (t.Id > 0) { return(t); } else { throw new SystemException(MessageCollection.Message(MessageType.SaveFail)); } } }
public bool Check(ship target, beam weapon) { Matrix mat = Matrix.CreateTranslation(new Vector3(weapon.position,0)) * Matrix.CreateRotationZ(weapon.Angle); tt = target.position - weapon.position; templeng = tt.Length(); if(length + weapon.beamsize >= templeng) { tt = Location(templeng, Angle(tt)); if (Math.Abs(tt.X) < target.boundingSphereRadius) { rAngle = weapon.Angle - target.Angle; //Get exact location to start and stop checking } } w = weapon.position; t = target.position; angle = weapon.Angle; radius = target.boundingSphereRadius; m1 = -(float)Math.Tan(Math.PI / 2 - (double)angle); m2 = -1 / m1; location.X = (t.Y - w.Y + (m1 * w.X) - (m2 * t.X)) / (m1 - m2); location.Y = m2 * location.X + t.Y - m2 * t.X; length = (t - location).Length(); if (length <= radius) { length = (w - location).Length() - new Vector2(radius, length).Length(); hit.X = length * (float)Math.Cos(Math.PI + angle); hit.Y = length * (float)Math.Sin(Math.PI + angle); return true; } else { return false; } }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { // TODO: Add your initialization logic here strName = "nicktest"; ship ship1 = new ship(); ship1.shipx = 0; ship1.shipy = 0; ship1.shipObj = Content.Load<Texture2D>("test"); shipList.Add(ship1); ship ship2 = new ship(); ship2.shipx = 300; ship2.shipy = 300; ship2.shipObj = Content.Load<Texture2D>("test"); shipList.Add(ship2); //Using UDP sockets clientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); IPHostEntry ipHostInfo = Dns.Resolve(Dns.GetHostName()); IPAddress ipAddress = ipHostInfo.AddressList[0]; Console.WriteLine(ipAddress); //Server is listening on port 1000 IPEndPoint ipEndPoint = new IPEndPoint(ipAddress, 11000); epServer = (EndPoint)ipEndPoint; Data msgToSend = new Data(); msgToSend.cmdCommand = Command.Login; msgToSend.strMessage = null; msgToSend.strName = strName; byte[] byteData = msgToSend.ToByte(); //Login to the server clientSocket.BeginSendTo(byteData, 0, byteData.Length, SocketFlags.None, epServer, new AsyncCallback(OnSend), null); byteData = new byte[1024]; //Start listening to the data asynchronously clientSocket.BeginReceiveFrom(byteData, 0, byteData.Length, SocketFlags.None, ref epServer, new AsyncCallback(OnReceive),null); base.Initialize(); }