public MapResource(SimulationWorld world, ConfigurationSection sect) { string type = sect["Type"].ToLowerInvariant(); switch (type) { case "petro": OilField oil = new OilField(world); oil.Parse(sect); Longitude = oil.Longitude; Latitude = oil.Latitude; Type = NaturalResourceType.Petro; Amount = oil.CurrentAmount; break; case "wood": Forest fores = new Forest(world); fores.Parse(sect); Longitude = fores.Longitude; Latitude = fores.Latitude; Type = NaturalResourceType.Wood; Amount = fores.CurrentAmount; Radius = fores.Radius; break; } }
public void CreateData() { DbContextOptions <Context> options = new DbContextOptionsBuilder <Context>() .UseInMemoryDatabase(databaseName: "post") .Options; using (Context context = new Context(options)) { OilFieldController service = new OilFieldController(context); IActionResult result = service.Get(1); NotFoundResult resNo = result as NotFoundResult; Assert.AreEqual(404, resNo.StatusCode); result = service.Post(new OilField { Location = "test1", Name = "test1", NumOfEmployees = 0, NumOfPumpjacks = 1, Production = 5 }); OkObjectResult res = result as OkObjectResult; Assert.AreEqual(200, res.StatusCode); OilField val = (OilField)res.Value; Assert.AreEqual(1, val.ID); } }
public IActionResult Put(int id, [FromBody] OilField value) { IActionResult result = BadRequest(); try { var oilField = _context.OilFields.Update(value); _context.SaveChanges(); result = Ok(true); } catch (Exception e) { Console.WriteLine($"EXCEPTION: {e.Message}"); result = StatusCode(StatusCodes.Status500InternalServerError); } return(result); }
private GameObject CreateNewObject(Grid grid, int x, int y) { if (_selectedGridObjectType.ToString().Equals("Empty")) { return(null); } GameObject go = PrefabUtility.InstantiatePrefab( GridObjectsManager.Instance.GetObjectData().GridTypePrefabs[(int)_selectedGridObjectType]) as GameObject; go.name = _selectedGridObjectType.ToString(); go.transform.position = grid[x, y].transform.position; go.transform.SetParent(grid[x, y].transform); if (_selectedGridObjectType == GridObjectType.OilField) { OilField of = go.AddComponent <OilField>(); of.OilValue = _selectedIntValue; } return(go); }
public IActionResult Get(int id) { IActionResult result = BadRequest(); try { // TODO add pages OilField oilField = _context.OilFields.Find(id); if (oilField != null) { result = Ok(oilField); } else { return(NotFound()); } } catch (Exception e) { Console.WriteLine($"EXCEPTION: {e.Message}"); result = StatusCode(StatusCodes.Status500InternalServerError); } return(result); }
public void UpdateData() { DbContextOptions <Context> options = new DbContextOptionsBuilder <Context>() .UseInMemoryDatabase(databaseName: "put") .Options; using (Context context = new Context(options)) { context.OilFields.Add(new OilField { ID = 1, Location = "test1", Name = "test1", NumOfEmployees = 0, NumOfPumpjacks = 1, Production = 5 }); context.SaveChanges(); } using (Context context = new Context(options)) { OilFieldController service = new OilFieldController(context); IActionResult result = service.Put(1, new OilField { ID = 1, Location = "test2", Name = "test2", NumOfEmployees = 0, NumOfPumpjacks = 1, Production = 5 }); context.SaveChanges(); OkObjectResult res = result as OkObjectResult; Assert.AreEqual(200, res.StatusCode); result = service.Get(1); res = result as OkObjectResult; Assert.AreEqual(200, res.StatusCode); OilField val = (OilField)res.Value; Assert.AreEqual("test2", val.Name); } }
public new void Remove(OilField oilField) => base.Remove(oilField);
public static void Test() { Player player = new Player(""); SimulationRegion region = new SimulationRegion(); City city = new City(region); City city2 = new City(region); IniSection sect = new IniSection(""); sect.Add("Name", "HUST"); sect.Add("Longitude", "0"); sect.Add("Latitude", "0"); sect.Add("Population", "150"); sect.Add("Size", UrbanSize.Large.ToString()); city.Parse(sect); sect = new IniSection(""); sect.Add("Name", "Home"); sect.Add("Longitude", "1"); sect.Add("Latitude", "0"); sect.Add("Population", "1"); sect.Add("Size", UrbanSize.Small.ToString()); city2.Parse(sect); region.Add(city); //region.Add(city2); //city.AddNearbyCity(city2); //city2.AddNearbyCity(city); OilField oilFld = new OilField(region); sect = new IniSection(""); sect.Add("Amount", "100000"); sect.Add("Latitude", "1"); sect.Add("Longitude", "0"); oilFld.Parse(sect); region.Add(oilFld); CityPluginType plgType = new CityPluginType(); sect = new IniSection(""); sect.Add("Cost", "100"); sect.Add("HRCSpeed", "100"); sect.Add("Behaviour", CityPluginBehaviourType.CollectorFactory.ToString()); plgType.Parse(sect); CityPlugin plg = new CityPlugin(plgType, CityPluginTypeId.OilRefinary); city.Add(plg); plgType = new CityPluginType(); sect = new IniSection(""); sect.Add("Cost", "100"); sect.Add("FoodConvRate", "0.50"); sect.Add("FoodCostSpeed", "100"); sect.Add("Behaviour", CityPluginBehaviourType.CollectorFactory.ToString()); plgType.Parse(sect); plg = new CityPlugin(plgType, CityPluginTypeId.BiofuelFactory); city.Add(plg); //OilField oil = new OilField(region); //Forest forest = new Forest(region); float c = 0; while (true) { Console.Clear(); Console.WriteLine("Energy Status:"); Console.Write(" Current Food Storage "); Console.WriteLine(region.EnergyStatus.CurrentFood); Console.Write(" Current HR Storage "); Console.WriteLine(region.EnergyStatus.CurrentHR); Console.Write(" Current LR Storage "); Console.WriteLine(region.EnergyStatus.CurrentLR); Console.Write(" Current Natural HR "); Console.WriteLine(region.EnergyStatus.RemainingHR); Console.Write(" Current Natural LR "); Console.WriteLine(region.EnergyStatus.RemainingLR); Console.WriteLine("City :" + city.Name); Console.WriteLine("City Status:"); Console.Write(" Development "); Console.WriteLine(city.Development); Console.Write(" Population "); Console.WriteLine(city.Population); Console.Write(" Disease "); Console.WriteLine(city.Disease); Console.Write(" Size "); Console.WriteLine(city.Size); Console.WriteLine(" Local H[{0}] L[{1}] F[{2}]", city.LocalHR.Current, city.LocalLR.Current, city.LocalFood.Current); Console.WriteLine(" Drain H[{0}] L[{1}] F[{2}]", city.GetSelfHRCSpeed(), city.GetSelfLRCSpeed(), city.GetSelfFoodCostSpeed()); Console.WriteLine(" Ratio H[{0:P}] L[{1:P}] F[{2:P}]", city.SelfHRCRatio, city.SelfLRCRatio, city.SelfFoodCostRatio); c += city.GetCarbonChange(); //city.LocalFood.Commit(250); //city.LocalHR.Commit(250); city.LocalLR.Commit(100); //Console.WriteLine("City :" + city2.Name); //Console.WriteLine("City Status:"); //Console.Write(" Development "); //Console.WriteLine(city2.Development); //Console.Write(" Population "); //Console.WriteLine(city2.Population); //Console.Write(" Disease "); //Console.WriteLine(city2.Disease); //Console.Write(" Size "); //Console.WriteLine(city2.Size); //Console.WriteLine(" Local H[{0}] L[{1}] F[{2}]", city2.LocalHR.Current, city2.LocalLR.Current, city2.LocalFood.Current); //Console.WriteLine(" Drain H[{0}] L[{1}] F[{2}]", city2.GetSelfHRCSpeed(), city2.GetSelfLRCSpeed(), city2.GetSelfFoodCostSpeed()); //Console.WriteLine(" Ratio H[{0:P}] L[{1:P}] F[{2:P}]", city2.SelfHRCRatio, city2.SelfLRCRatio, city2.SelfFoodCostRatio); //c += city2.GetCarbonChange(); Console.WriteLine("World Carbon {0}", c); GameTime gt = new GameTime(0, 0, TimeSpan.FromHours(1), TimeSpan.FromHours(1)); region.Update(gt); Thread.Sleep(5); } }