public GameObject CreateLarva(Vector2 position) { GameObject newLarva = (GameObject)Instantiate(larva, position, Quaternion.identity); Larvae.Add(newLarva); newLarva.transform.SetParent(worldCanvas.transform); newLarva.transform.SetAsFirstSibling(); return(newLarva); }
private void Hatch() { File.Delete(this.FullPathProperty); Larvae newForm = new Larvae(this.IDProperty, this.ColonyIDProperty,this.LocationProperty); }
public void DestroyLarva(GameObject deadLarva) { Larvae.Remove(deadLarva); Destroy(deadLarva); }
//passed the enviroment root private void LoadScenario(string saveFilePath) { //take root folder as selected by user //init ant hill //store anthill stats. //store pointer in dictionary //init ant //store stats //store pointer in dictionary if (new FileInfo(saveFilePath).Length != 0) { using (StreamReader sr = new StreamReader(saveFilePath)) { string line = ""; int counter = 0; //A temp value for parsing ints int temp; bool tempBool; //temp objects AntHill tempAnthill; Chamber tempChamber = new Chamber(); Pheromone tempPhe = new Pheromone(0, "", PheromoneEnum.Danger, true); Worker tempWorker = new Worker(0, 0, "", true); Queen tempQueen = new Queen(0, 0, "", true); Egg tempEgg = new Egg(0, 0, "", true); Larvae tempLarvae = new Larvae(0, 0, "", true); Pupae tempPupae = new Pupae(0, 0, "", true); Ant antPointer = tempWorker; while ((line = sr.ReadLine()) != "[Enviroment Stats End]") { counter++; if (counter == 1) { this.enviromentFullPath = line; } } tempAnthill = new AntHill(0, "", false); counter = 0; while ((line = sr.ReadLine()) != "[Anthill Stats End]") { counter++; /* 1 sw.WriteLine(antHills[0].LocationProperty); 2 sw.WriteLine(antHills[0].IDProperty); 3 sw.WriteLine(antHills[0].AntsDiggingProperty); 4 sw.WriteLine(antHills[0].AntsMoveingEggsProperty); 5 sw.WriteLine(antHills[0].AntsScoutingProperty); 6 sw.WriteLine(antHills[0].AntsTendingToBroodProperty); 7 sw.WriteLine(antHills[0].AntsTendingToQueenProperty); 8 sw.WriteLine(antHills[0].AntsTotalProperty); */ if (counter == 1) { tempAnthill.LocationProperty = line; } else if (counter == 2) { int.TryParse(line, out temp); tempAnthill.IDProperty = temp; } else if (counter == 3) { int.TryParse(line, out temp); tempAnthill.AntsDiggingProperty = temp; } else if (counter == 4) { int.TryParse(line, out temp); tempAnthill.AntsMoveingEggsProperty = temp; } else if (counter == 5) { int.TryParse(line, out temp); tempAnthill.AntsScoutingProperty = temp; } else if (counter == 6) { int.TryParse(line, out temp); tempAnthill.AntsTendingToBroodProperty = temp; } else if (counter == 7) { int.TryParse(line, out temp); tempAnthill.AntsTendingToQueenProperty = temp; antHills[0] = tempAnthill; txtOutput.Text += Environment.NewLine + "Anthill" + tempAnthill.IDProperty + " Loaded"; } } counter = 0; txtOutput.Text += Environment.NewLine + "Chambers Start: "; //For the rest of the categories, I will have to set up a couple of loops. //One for the category as a whole, and one for each record in that category. while ((line = sr.ReadLine()) != "[Anthill Chamber Stats End]") { if (line == "[Anthill Chamber End]") { tempChamber = new Chamber(); counter = 0; } else { counter++; } /* 1 sw.WriteLine(antHills[0].chambers[i].IDProperty); 2 sw.WriteLine(antHills[0].chambers[i].TypeProperty); 3 sw.WriteLine(antHills[0].chambers[i].LocationProperty); 4 sw.WriteLine(antHills[0].chambers[i].AmountOfFoodProperty); 5 sw.WriteLine(antHills[0].chambers[i].AmountOfOffspringProperty); 6 sw.WriteLine(antHills[0].chambers[i].CapacityReachedProperty); */ if (counter == 1) { int.TryParse(line, out temp); tempChamber.IDProperty = temp; } else if (counter == 2) { tempChamber.TypeProperty = (ChamberType)Enum.Parse(typeof(ChamberType), line); } else if (counter == 3) { tempChamber.LocationProperty = line; } else if (counter == 4) { int.TryParse(line, out temp); tempChamber.AmountOfFoodProperty = temp; } else if (counter == 5) { int.TryParse(line, out temp); tempChamber.AmountOfOffspringProperty = temp; } else if (counter == 6) { bool.TryParse(line, out tempBool); tempChamber.CapacityReachedProperty = tempBool; txtOutput.Text += Environment.NewLine + "Anthill Chamber" + tempChamber.IDProperty + " Loaded"; } //Add to list } while ((line = sr.ReadLine()) != "[Pheremone Stats End]") { if (line == "[Anthill Chamber End]") { tempPhe = new Pheromone(0, "", PheromoneEnum.Danger, true); counter = 0; } else { counter++; } /* 1 sw.WriteLine(antHills[0].pheromonesPlaced[i].ColonyIDProperty); 2 sw.WriteLine(antHills[0].pheromonesPlaced[i].FullPathProperty); 3 sw.WriteLine(antHills[0].pheromonesPlaced[i].LocationProperty); 4 sw.WriteLine(antHills[0].pheromonesPlaced[i].StrengthProperty); 5 sw.WriteLine(antHills[0].pheromonesPlaced[i].TypeProperty); */ if (counter == 1) { int.TryParse(line, out temp); tempPhe.ColonyIDProperty = temp; } else if (counter == 2) { tempPhe.FullPathProperty = line; } else if (counter == 3) { tempPhe.LocationProperty = line; } else if (counter == 4) { int.TryParse(line, out temp); tempPhe.StrengthProperty = temp; } else if (counter == 5) { tempPhe.TypeProperty = (PheromoneEnum)Enum.Parse(typeof(PheromoneEnum), line); txtOutput.Text += Environment.NewLine + "Pheremone" + tempPhe.TypeProperty.ToString() + " Loaded"; } } while ((line = sr.ReadLine()) != "[Ant Stats End]") { if (line == "[Ant End]") { counter = 0; } else { counter++; } /* 1 sw.WriteLine(antHills[0].ants[i].TypeProperty); 2 sw.WriteLine(antHills[0].ants[i].IDProperty); 3 sw.WriteLine(antHills[0].ants[i].FullPathProperty); 4 sw.WriteLine(antHills[0].ants[i].LocationProperty); 5 sw.WriteLine(antHills[0].ants[i].HungerProperty); 6 sw.WriteLine(antHills[0].ants[i].HealthProperty); 7 sw.WriteLine(antHills[0].ants[i].AgeProperty); 8 sw.WriteLine(antHills[0].ants[i].BeingCarriedProperty); 9 sw.WriteLine(antHills[0].ants[i].CarriedAntProperty.IDProperty); 10 sw.WriteLine(antHills[0].ants[i].CarriedObjectFullPathProperty); 11 sw.WriteLine(antHills[0].ants[i].CarriedObjectLocationProperty); 12 sw.WriteLine(antHills[0].ants[i].CarryAmountProperty); 13 sw.WriteLine(antHills[0].ants[i].CarryingProperty); 14 sw.WriteLine(antHills[0].ants[i].ColonyIDProperty); 15 sw.WriteLine(antHills[0].ants[i].DestinationProperty); 16 sw.WriteLine(antHills[0].ants[i].InNestProperty); 17 sw.WriteLine(antHills[0].ants[i].NewThroneRoomProperty); 18 sw.WriteLine(antHills[0].ants[i].PheromoneProperty); 19 sw.WriteLine(antHills[0].ants[i].PreviousLocationProperty); 20 sw.WriteLine(antHills[0].ants[i].StateProperty); 21 sw.WriteLine(antHills[0].ants[i].StepCountProperty); */ if (counter == 1) { if (line == "Queen") { tempQueen = new Queen(0, 0, "", true); antPointer = tempQueen; } else if (line == "Egg") { tempEgg = new Egg(0, 0, "", true); antPointer = tempEgg; } else if (line == "Larvae") { tempLarvae = new Larvae(0, 0, "", true); antPointer = tempLarvae; } else if (line == "Pupae") { tempPupae = new Pupae(0, 0, "", true); antPointer = tempPupae; } else if (line == "Worker") { tempWorker = new Worker(0, 0, "", true); antPointer = tempWorker; } } else if (counter == 2) { int.TryParse(line, out temp); antPointer.IDProperty = temp; } else if (counter == 3) { antPointer.FullPathProperty = line; } else if (counter == 4) { antPointer.LocationProperty = line; } else if (counter == 5) { int.TryParse(line, out temp); antPointer.HungerProperty = temp; } else if (counter == 6) { int.TryParse(line, out temp); antPointer.HealthProperty = temp; } else if (counter == 7) { int.TryParse(line, out temp); antPointer.AgeProperty = temp; } else if (counter == 8) { bool.TryParse(line, out tempBool); antPointer.BeingCarriedProperty = tempBool; } else if (counter == 9) { //This is an object, so i will have to perhaps store the id of the ant instead, then get that ant. //Or ignore this all together, but thats not good. //I might have to change this property to store the ID anyway, then have the ant look for the //cooresponding ant by ID. //antPointer.CarriedAntProperty //what i can do is use the ant dictionary and just point to the ID regardless of if it's a null value. //that ant will get placed in the dictionary anyway at the end of the load. if (line == "nullValue") { antPointer.CarriedAntProperty = null; } else { int.TryParse(line, out temp); antPointer.CarriedAntProperty = antHills[0].ants[temp]; } } else if (counter == 10) { //10 sw.WriteLine(antHills[0].ants[i].CarriedObjectFullPathProperty); if (line != "nullValue") { antPointer.CarriedObjectFullPathProperty = line; } } else if (counter == 11) { //11 sw.WriteLine(antHills[0].ants[i].CarriedObjectLocationProperty); if (line != "nullValue") { antPointer.CarriedObjectLocationProperty = line; } } else if (counter == 12) { //12 sw.WriteLine(antHills[0].ants[i].CarryAmountProperty); int.TryParse(line, out temp); antPointer.CarryAmountProperty = temp; } else if (counter == 13) { //13 sw.WriteLine(antHills[0].ants[i].CarryingProperty); antPointer.CarryingProperty = (Carrying)Enum.Parse(typeof(Carrying), line); } else if (counter == 14) { //14 sw.WriteLine(antHills[0].ants[i].ColonyIDProperty); int.TryParse(line, out temp); antPointer.ColonyIDProperty = temp; } else if (counter == 15) { //15 sw.WriteLine(antHills[0].ants[i].DestinationProperty); antPointer.DestinationProperty = line; } else if (counter == 16) { //16 sw.WriteLine(antHills[0].ants[i].InNestProperty); bool.TryParse(line, out tempBool); antPointer.InNestProperty = tempBool; } else if (counter == 17) { // 17 sw.WriteLine(antHills[0].ants[i].NewThroneRoomProperty); bool.TryParse(line, out tempBool); antPointer.NewThroneRoomProperty = tempBool; } else if (counter == 18) { //18 sw.WriteLine(antHills[0].ants[i].PheromoneProperty); antPointer.PheromoneProperty = (PheromoneEnum)Enum.Parse(typeof(PheromoneEnum), line); } else if (counter == 19) { //19 sw.WriteLine(antHills[0].ants[i].PreviousLocationProperty); antPointer.PreviousLocationProperty = line; } else if (counter == 20) { //20 sw.WriteLine(antHills[0].ants[i].StateProperty); antPointer.StateProperty = (State)Enum.Parse(typeof(State), line); } else if (counter == 21) { //21 sw.WriteLine(antHills[0].ants[i].StepCountProperty); int.TryParse(line, out temp); antPointer.StepCountProperty = temp; antPointer.MyAnthillProperty = antHills[0]; antHills[0].ants[antPointer.IDProperty] = antPointer; txtOutput.Text += Environment.NewLine + "Ant" + antPointer.ColonyIDProperty.ToString("D2") + "_" + antPointer.IDProperty.ToString("D4") + " Loaded"; } //add ant to dictionary. //set anthill pointer to anthill[0] // } txtOutput.Text += Environment.NewLine + "LOAD COMPLETE"; sr.Close(); } } }
public IActionResult DownStats() { //var newFeed = new Feed { }; int intId = 0; string country = string.Empty; string province = string.Empty; string cases = string.Empty; string deaths = string.Empty; string recovered = string.Empty; // https://corona.lmao.ninja/countries?sort=country // https://corona.lmao.ninja/v2/historical // delete any entries for the downloadDate; only one dataset per day //var latest = _larvae.GetLatestDownloadDate(); //_larvae.DeleteByDay(latest); HttpClient client = new HttpClient(); client.BaseAddress = new Uri(Url); client.DefaultRequestHeaders.Accept.Add( new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); HttpResponseMessage response = client.GetAsync(Url).Result; if (response.IsSuccessStatusCode) { // load content in db //Url2: THIS DOES NOT WORK!!! Cannot be deserialized .. see error below //var results = response.Content.ReadAsAsync<IEnumerable<LarvaeListingModel>>().Result; // Url1 or Url2 var results = response.Content.ReadAsStringAsync().Result; // START >> THIS WORKS FOR BOTH URL APIs ... however only writes (entire) result to table // April 15, 2020 var newLarvae = new Larvae { Result = results }; _larvae.Add(newLarvae); // END // START >> This was just for shits&giggles ... did not amount to anything ... //JToken token = JToken.Parse(results); //JArray countryStr = (JArray)token.SelectToken("country"); //JArray provinceStr = (JArray)token.SelectToken("province"); //JArray casesArr = (JArray)token.SelectToken("timeline[0].cases"); //JArray deathsArr = (JArray)token.SelectToken("timeline[0].deaths"); //JArray recoveredArr = (JArray)token.SelectToken("timeline[0].recovered"); // END // Error received when attempting to process Url #2: /* * Cannot deserialize the current JSON object (e.g. {"name":"value"}) into type 'System.Collections.Generic.IEnumerable`1[Googster.ViewModels.LarvaeListingModel]' because the type requires a JSON array (e.g. [1,2,3]) to deserialize correctly. * To fix this error either change the JSON to a JSON array (e.g. [1,2,3]) or change the deserialized type so that it is a normal .NET type (e.g. not a primitive type like integer, not a collection type like an array or List<T>) that can be deserialized from a JSON object. JsonObjectAttribute can also be added to the type to force it to deserialize from a JSON object. * Path 'Afghanistan', line 2, position 16.) */ // So I DO NOT KNOW how to work with that F**K'N data (in .NET, Ng, or Python) //foreach (var x in results) //{ // var newLarvae = new Larvae // { // IntId = "0", // Not in Url2 // Country = "Country", // Province = "Province", //Not in Url2 // Date1 = x.Date1, // Cases = x.Cases, // Deaths = x.Deaths, // Recovered = x.Recovered // }; // _larvae.Add(newLarvae); //} } return(RedirectToAction("Index")); }
public void Update(Larvae newLarvae) { throw new NotImplementedException(); }
public void Add(Larvae newLarvae) { _context.Add(newLarvae); _context.SaveChanges(); }