private BalancingStation balanceStn = new BalancingStation(); // Balancing station object. Used to complete reactions. // Start is called before the first frame update void Start() { // Create chemicals used in the level. Chemical c = new Chemical("C", 1, 0, false, molecules[6], "C"); Chemical o2 = new Chemical("O" + sub_2, 2, 0, false, molecules[4], "O"); Chemical n2 = new Chemical("N" + sub_2, 2, 0, false, molecules[5], "N"); // Load possible reactions into dictionary. results[Tuple.Create(n2, o2)] = new Chemical("N" + sub_2 + "O", 2, 1, true, molecules[7], "NO"); results[Tuple.Create(o2, n2)] = new Chemical("N" + sub_2 + "O", 1, 2, true, molecules[7], "NO"); results[Tuple.Create(c, o2)] = new Chemical("CO", 1, 1, true, molecules[7], "CO"); results[Tuple.Create(o2, c)] = new Chemical("CO", 1, 1, true, molecules[7], "CO"); // Add chemicals to list. chemicals.Add(c); chemicals.Add(o2); chemicals.Add(n2); // Load orders for the level. orders.Add("CO"); orders.Add("N" + sub_2 + "O"); orders.Add("CO"); // Fix subscripts. fix1.text = "C"; fix2.text = "O" + sub_2; fix3.text = "N" + sub_2; InHand = n2; // Load customers for the level and have new ones appear as player completes orders. GenerateCustomers(); InvokeRepeating("GenerateCustomers", 2.0f, 2.0f); section1.Add(sec1_row0); section1.Add(sec1_row1); section1.Add(sec1_row2); section1.Add(sec1_row3); section2.Add(sec2_row0); section2.Add(sec2_row1); section2.Add(sec2_row2); section2.Add(sec2_row3); section3.Add(sec3_row0); section3.Add(sec3_row1); section3.Add(sec3_row2); section3.Add(sec3_row3); section4.Add(sec4_row0); section4.Add(sec4_row1); section4.Add(sec4_row2); section4.Add(sec4_row3); }
public void RadonTest() { WaterPacket w = new WaterPacket(12); Chemical C = ChemicalFactory.Instance.GetChemical(ChemicalNames.Radon); Chemical cl = ChemicalFactory.Instance.GetChemical(ChemicalNames.Cl); //Checks old evaporation C.IsFirstOrderDegradable = false; w.AddChemical(C, 5); w.AddChemical(cl, 5); Assert.AreEqual(0.4167, w.GetConcentration(C), 0.001); w.MoveInTime(TimeSpan.FromDays(1), 6); Assert.AreEqual(0.3846, w.GetConcentration(C), 0.001); w.MoveInTime(TimeSpan.FromDays(1), 6); Assert.AreEqual(0.355, w.GetConcentration(C), 0.001); //Checks new Reactions double d = w.GetConcentration(C); w.MoveInTime(TimeSpan.FromDays(3.8), ChemicalFactory.Instance.LakeReactions, 0); Assert.AreEqual(d / 2, w.GetConcentration(C), 0.01); Assert.AreEqual(5.0 / 12, w.GetConcentration(cl), 0.01); }
public void Chemical_Parse_works(int qty, string nam, string text) { var expected = new Chemical(qty, nam); var parsed = Chemical.Parse(text); Assert.Equal(expected, parsed); }
private bool ExecuteReactionsForMaximumChemical(Chemical chemical) { if (chemical.Name == "ORE") { return(true); } var available = GetAvailable(chemical.Name); if (available.Quantity >= chemical.Quantity) { return(true); } var reaction = chemical.ProducedBy; foreach (var input in reaction.Inputs) { if (!ExecuteReactionsForMaximumChemical(input)) { return(false); } var availableInput = GetAvailable(input.Name); if (availableInput.Quantity < input.Quantity) { return(false); } availableInput.Subtract(input.Quantity); } available.Add(reaction.Output.Quantity); return(ExecuteReactionsForMaximumChemical(chemical)); }
public void UpdateBalanced() { int num1 = (int)Math.Ceiling(balanceStn.QuantityR1 * balanceStn.Reactant1.Subscript1 / (float)balanceStn.Product.Subscript1); int num2 = (int)Math.Ceiling(balanceStn.QuantityR2 * balanceStn.Reactant2.Subscript1 / (float)balanceStn.Product.Subscript2); int goal = Math.Max(num1, num2); result.text = goal.ToString() + " " + balanceStn.Product.Name; int missing1 = balanceStn.Product.Subscript1 * goal - balanceStn.QuantityR1 * balanceStn.Reactant1.Subscript1; int missing2 = balanceStn.Product.Subscript2 * goal - balanceStn.QuantityR2 * balanceStn.Reactant2.Subscript1; if (missing1 == 0 && missing2 == 0) { // Balanced resultTotal.text = "Balanced! You have finished the reaction for creating " + balanceStn.Product.Name + "!"; Hand.SetActive(true); InHand = balanceStn.Product; SpriteRenderer sr = Hand.GetComponent <SpriteRenderer>(); sr.sprite = InHand.Colour; FindObjectOfType <AudioManager>().Play("successBalance"); deliveryLightsOn = true; } else { // Not balanced string text1 = "Needed: " + (balanceStn.Product.Subscript1 * goal).ToString() + " " + balanceStn.Reactant1.SingleName; string text2 = " " + (balanceStn.Product.Subscript2 * goal).ToString() + " " + balanceStn.Reactant2.SingleName; resultTotal.text = text1 + text2 + " Missing " + missing1.ToString() + " " + balanceStn.Reactant1.SingleName + " and " + missing2.ToString() + " " + balanceStn.Reactant2.SingleName; } }
public override object Part2() { var reactions = Parse(Input); const long oreStock = 1_000_000_000_000; long fuelMin = 0, fuelMax = 1; while (GetRequiredOre(reactions, Chemical.Fuel(fuelMax)) < oreStock) { fuelMin = fuelMax; fuelMax *= 2; } while (fuelMin + 1 < fuelMax) { long fuelMid = (fuelMin + fuelMax) / 2; long requiredOre = GetRequiredOre(reactions, Chemical.Fuel(fuelMid)); if (requiredOre > oreStock) { fuelMax = fuelMid; } else if (requiredOre < oreStock) { fuelMin = fuelMid; } } return(fuelMin); }
private long GetRequiredOre(Dictionary <string, Reaction> reactions, Chemical requiredChem, Dictionary <string, long> extra = null) { if (requiredChem.Name == "ORE") { return(requiredChem.Quantity); } extra ??= new Dictionary <string, long>(); extra.TryGetValue(requiredChem.Name, out long extraQuantity); long usedExtraQuantity = Math.Min(requiredChem.Quantity, extraQuantity); if (usedExtraQuantity > 0) { requiredChem = new Chemical(requiredChem.Name, requiredChem.Quantity - usedExtraQuantity); extra[requiredChem.Name] -= usedExtraQuantity; } var reaction = reactions[requiredChem.Name]; var numReactions = (long)Math.Ceiling((decimal)requiredChem.Quantity / reaction.Output.Quantity); long ore = reaction.Inputs .Select(inChem => GetRequiredOre(reactions, new Chemical(inChem.Name, inChem.Quantity * numReactions), extra)) .Sum(); extra.TryGetValue(requiredChem.Name, out extraQuantity); extra[requiredChem.Name] = extraQuantity + numReactions * reaction.Output.Quantity - requiredChem.Quantity; return(ore); }
string GetGHSImageAsBase64(Chemical chem) { string result = ""; List <string> imgs = new List <string>(); foreach (var v in Chemical.GetAvailableGHS()) { if (chem.GHS.HasFlag(v)) { string imgFile = Path.Combine(_env.WebRootPath, "images\\" + v.ToString() + ".png"); imgs.Add(imgFile); } } using (Image <Rgba32> outputImage = new Image <Rgba32>(imgs.Count * 256, 256)) { for (int i = 0; i < imgs.Count; i++) { string imgFile = imgs[i]; using (Image <Rgba32> img1 = Image.Load <Rgba32>(imgFile)) { outputImage.Mutate(o => o.DrawImage(img1, new Point(i * 256, 0), 1f)); } } //outputImage.SaveAsPng(Path.Combine(_env.WebRootPath, "plep.png")); result = outputImage.ToBase64String(PngFormat.Instance); } return(result.Substring(result.IndexOf(',') + 1));; }
private void addNewRadiopharmaceutical() { Chemical rp = new Chemical(); Radiopharmaceuticals.Add(rp); DesktopApplication.MakeModalDocument(new DataStoreItemViewModel(rp)); }
// The databank 'legacy API' public float GetCriticalPoint(Chemical compound, State point) { // Melting Point if (point == State.Melting) { switch (compound) { case Chemical.Water: return 0.0f; case Chemical.Benzene: return 5.5f; case Chemical.Ethanol: return -114.1f; default: return 0f; } } // Boiling Point else { switch (compound) { case Chemical.Water: return 100.0f; case Chemical.Benzene: return 80.1f; case Chemical.Ethanol: return 78.3f; default: return 0f; } } }
//show chemical: public ActionResult Show(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); //what's this? } string main_query = "SELECT* FROM Chemicals WHERE ChemicalID = @id"; var pk_parameter = new SqlParameter("@id", id); Chemical Chemical = db.Chemicals.SqlQuery(main_query, pk_parameter).FirstOrDefault(); if (Chemical == null) { return(HttpNotFound()); } string cate_query = "SELECT * FROM Categories INNER JOIN Chemicals ON Categories.CategoryID = Chemicals.CategoryID WHERE Chemicals.CategoryID = @id"; var capk_parameter = new SqlParameter("@id", id); Category Category = db.Categories.SqlQuery(cate_query, capk_parameter).FirstOrDefault(); string ord_query = "SELECT * FROM Orders INNER JOIN OrderChemicals ON Orders.OrderID = OrderChemicals.Order_OrderID WHERE OrderChemicals.Chemical_ChemicalID = @id"; var fk_parameter = new SqlParameter("@id", id); List <Order> OrderChemicals = db.Orders.SqlQuery(ord_query, fk_parameter).ToList(); ShowChemical viewmodel = new ShowChemical(); viewmodel.chemical = Chemical; viewmodel.category = Category; viewmodel.orders = OrderChemicals; return(View(viewmodel)); }
public void TestCountDependencies() { List <Chemical> inA = new List <Chemical>() { new Chemical(1, "C") }; Chemical outA = new Chemical(1, "A"); Reaction a = new Reaction(inA, outA); List <Chemical> inB = new List <Chemical>() { new Chemical(1, "C") }; Chemical outB = new Chemical(1, "B"); Reaction b = new Reaction(inB, outB); List <Chemical> inC = new List <Chemical>() { new Chemical(1, "ORE") }; Chemical outC = new Chemical(1, "C"); Reaction c = new Reaction(inC, outC); List <Reaction> reactions = new List <Reaction>(); reactions.Add(a); reactions.Add(b); reactions.Add(c); Nanofactory n = new Nanofactory(); Assert.That(n.CountDependencies(a, reactions), Is.EqualTo(0)); Assert.That(n.CountDependencies(b, reactions), Is.EqualTo(0)); Assert.That(n.CountDependencies(c, reactions), Is.EqualTo(2)); }
// The databank 'legacy API' public float GetCriticalPoint(Chemical compound, State point) { // Melting Point if (point == State.Melting) { switch (compound) { case Chemical.Water: return(0.0f); case Chemical.Benzene: return(5.5f); case Chemical.Ethanol: return(-114.1f); default: return(0f); } } // Boiling Point else { switch (compound) { case Chemical.Water: return(100.0f); case Chemical.Benzene: return(80.1f); case Chemical.Ethanol: return(78.3f); default: return(0f); } } }
private void ExecuteReactions(Chemical chemical) { if (chemical.Name == "ORE") { _oreUsed += chemical.Quantity; return; } var available = GetAvailable(chemical.Name); if (available.Quantity >= chemical.Quantity) { return; } var reaction = chemical.ProducedBy; foreach (var input in reaction.Inputs) { ExecuteReactions(input); var availableInput = GetAvailable(input.Name); availableInput.Subtract(input.Quantity); } available.Add(reaction.Output.Quantity); ExecuteReactions(chemical); }
public void Inject() { if (chemSlot.item != null) { Chemical chem = chemSlot.item.GetComponent <Chemical>(); chemSlot.clearSlot(); Hunger += chem.hunger; PH += chem.PH; Temperature += chem.Temperature; Temperature *= 0.5f; Source.clip = Clip; Source.Play(); for (int i = 0; i < chem.Effects.Count; i++) { effects.Add(chem.Effects[i]); intensities.Add(chem.EffectIntensities[i]); } } }
public void Update() { if (pickupable) { if (Input.GetMouseButtonDown(0)) { RaycastHit2D hit = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if (hit.collider != null) { Debug.Log(Vector2.Distance(transform.position, hit.collider.transform.position)); if (Vector2.Distance(transform.position, hit.collider.transform.position) <= 2) { if (hit.collider.tag == "item") { GameObject itempickedup = hit.collider.gameObject; Item itemobject = itempickedup.GetComponent <Item>(); Chemical itemchem = itempickedup.GetComponent <Chemical>(); //audio here AudioSauce.clip = Pickup; AudioSauce.Play(); AddItem(itempickedup, itemobject.Name, itemobject.Description, itemobject.Icon, itemobject.Stackable, itempickedup, itemchem.Color, itemchem.Solid, itemchem.liquidSPRITE); } } } } } }
public override bool AddToMixture(Chemical Chemical) //Returns false if failed { //Test if solid if (Chemical.Solid == true) { if (PH < -2 || PH > 2) { //Can dissolve solid RecalculateValues(Chemical); return(true); } else { //cannot dissolve solid, not acidic enough return(false); } } else { //Add the chemical to mixture RecalculateValues(Chemical); return(true); } }
private DAL.Class CheckingClass(Chemical ch, Organoleptic or) { if ((or.Scent20 <= 2 && or.Scent60 <= 2 && or.Flavor <= 2 && or.Chromaticity <= 20 && or.Turbidity <= 1.5 && or.Temperature >= 8 && or.Temperature <= 12) && (ch.Residue <= 1000 && ch.Ph <= 9 && ch.Ph >= 6 && ch.Rigidity <= 7 && ch.Chlorides <= 350 && ch.Sulphates <= 500 && ch.Iron <= 0.3 && ch.Marhan <= 0.1 && ch.Fluorine <= 1.5 && ch.Nitrates <= 45)) { return(DAL.Class.first); } else if ((or.Scent20 <= 2 && or.Scent60 <= 2 && or.Flavor <= 2 && or.Chromaticity <= 20 && or.Turbidity <= 3.5 && or.Temperature >= 8 && or.Temperature <= 12) && (ch.Residue <= 1500 && ch.Ph <= 9 && ch.Ph >= 6 && ch.Rigidity <= 10 && ch.Chlorides <= 350 && ch.Sulphates <= 500 && ch.Iron <= 10 && ch.Marhan <= 1.0 && ch.Fluorine <= 1.5 && ch.Nitrates <= 45)) { return(DAL.Class.second); } else if ((or.Scent20 <= 2 && or.Scent60 <= 2 && or.Flavor <= 2 && or.Chromaticity <= 50 && or.Turbidity <= 3.5 && or.Temperature >= 8 && or.Temperature <= 12) && (ch.Residue <= 1500 && ch.Ph <= 9 && ch.Ph >= 6 && ch.Rigidity <= 10 && ch.Chlorides <= 350 && ch.Sulphates <= 500 && ch.Iron <= 20 && ch.Marhan <= 2.0 && ch.Fluorine <= 5 && ch.Nitrates <= 45)) { return(DAL.Class.third); } else { return(DAL.Class.undrinkable); } }
public ActionResult Create([Bind(Include = "Chem_ID,Name")] Chemical chemical) { var query = db.Chemicals.Count() + 1; string temp = "Chem-" + query; bool exist = false; try { var search = db.Controls.Where(c => c.C_ID == temp).Single(); exist = true; } catch { exist = false; } if (exist) { var all = db.Controls.ToList(); var cont = all.Last(); chemical.Chem_ID = "Chem-" + DataModel.Constants.NextNumber(cont.C_ID); } else { chemical.Chem_ID = temp; } if (ModelState.IsValid) { db.Chemicals.Add(chemical); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(chemical)); }
// Constructor public RichCompound(Chemical chemical) { Chemical = chemical; // The Adaptee bank = new ChemicalDatabank(); }
public bool ProductChemical(ref Strain parentStrain, ref Block currentBlock, ref CodingGene gene) { if (string.IsNullOrEmpty(gene.ProductionChemicalName)) { return(true); } var ProductionChemicalName = gene.ProductionChemicalName; var productionChemical = Local.FindChemicalByName(ProductionChemicalName); // ----- 对化学物质产生影响 ----- // 查找是否存在这个物质 var productChem = currentBlock.PublicChemicals.Find(che => { return(che.Name == ProductionChemicalName); }); if (productChem == null) { productChem = new Chemical { Name = ProductionChemicalName, Count = 0, SpreadRate = productionChemical.SpreadRate }; // 向block物质集中添加改变的chemical currentBlock.PublicChemicals.Add(productChem); } productChem.Count += ( int )GetProductionChemicalDelta(ref parentStrain, ref gene); // ----- 对化学 物质产生影响 ----- return(true); }
public long OreRequiredForChemical(string name, long quantity) { var requiredChemical = new Chemical(name, quantity); SetProducedBy(requiredChemical); ExecuteReactions(requiredChemical); return(_oreUsed); }
public override string GetSolution() { Chemical chemical = availableChemicals["FUEL"]; chemical.Produce(1); return(availableChemicals["ORE"].AvailableAmount.ToString()); }
public ActionResult DeleteConfirmed(string id) { Chemical chemical = db.Chemicals.Find(id); db.Chemicals.Remove(chemical); db.SaveChanges(); return(RedirectToAction("Index")); }
ChemReaction MakeChemReaction(string chemInfo) { var parts = chemInfo.Split(" ", 2); var chem = new Chemical(parts[1].Trim(), Convert.ToInt32(parts[0].Trim())); var item = new ChemReaction(chem); return(item); }
public void TrashClick() { // Allow player to throwout whatever chemical they are currently holding. Hand.SetActive(false); InHand = chemicals[0]; FindObjectOfType <AudioManager>().Play("trashUse"); trashClickEvent = true; }
public IActionResult Create([Bind] Chemical chemical) { if (ModelState.IsValid) { objchemical.ChemicalAddOrEdit(chemical); return(RedirectToAction("Index")); } return(View(chemical)); }
public void GetChemicalTest() { Chemical actual = ChemicalFactory.Instance.GetChemical(ChemicalNames.Cl); Assert.AreEqual("Cl", actual.Name); actual = ChemicalFactory.Instance.GetChemical(ChemicalNames.Na); Assert.AreEqual("Na", actual.Name); Assert.AreEqual("Na", ChemicalFactory.Instance.Chemicals[0].Name); }
public void Test_DayFourteen_PartOne() { var fact = new NanoFactory(Path.Combine(TestHelper.TestDir, "Day14.Input.txt")); var fuel = new Chemical("FUEL", 1); fact.ProduceChemical(fuel); Assert.IsTrue(fact.OreRequired == 899155); }
public void ImporterTests_SoilImports() { string oldXml = ReflectionUtilities.GetResourceAsString("UnitTests.ImporterTestsSoilImports.xml"); APSIMImporter importer = new APSIMImporter(); Simulations sims = importer.CreateSimulationsFromXml(oldXml); Soil s = sims.Children[0].Children[0] as Soil; Assert.AreEqual(s.Name, "Soil"); InitialWater initWater = s.Children[0] as InitialWater; Assert.AreEqual(initWater.FractionFull, 0.5); Assert.AreEqual(initWater.PercentMethod, InitialWater.PercentMethodEnum.FilledFromTop); Physical w = s.Children[1] as Physical; Assert.AreEqual(w.Thickness, new double[] { 150, 150, 300, 300 }); Assert.AreEqual(w.BD, new double[] { 1.02, 1.03, 1.02, 1.02 }); Assert.AreEqual(w.LL15, new double[] { 0.29, 0.29, 0.29, 0.29 }); SoilWater sw = s.Children[2] as SoilWater; Assert.AreEqual(sw.Thickness, new double[] { 150, 150, 300, 300 }); Assert.AreEqual(sw.SWCON, new double[] { 0.3, 0.3, 0.3, 0.3 }); Assert.AreEqual(sw.SummerCona, 3.5); Assert.AreEqual(sw.SummerU, 6); Assert.AreEqual(sw.WinterCona, 2); Assert.AreEqual(sw.WinterU, 2); Assert.IsTrue(s.Children[3] is SoilNitrogen); Organic som = s.Children[4] as Organic; Assert.AreEqual(som.Thickness, new double[] { 150, 150, 300, 300 }); Assert.AreEqual(som.Carbon, new double[] { 1.04, 0.89, 0.89, 0.89 }); Assert.AreEqual(som.FBiom, new double[] { 0.025, 0.02, 0.015, 0.01 }); Chemical a = s.Children[5] as Chemical; Assert.AreEqual(a.Thickness, new double[] { 150, 150, 300, 300 }); Assert.AreEqual(a.NO3N, new double[] { 6.5, 2.1, 2.1, 1.0 }); Assert.AreEqual(a.NH4N, new double[] { 0.5, 0.1, 0.1, 0.2 }); Assert.AreEqual(a.EC, new double[] { 0.2, 0.25, 0.31, 0.40 }); Assert.AreEqual(a.PH, new double[] { 8.4, 8.8, 9.0, 9.2 }); Sample sam = s.Children[6] as Sample; Assert.AreEqual(sam.Thickness, new double[] { 150, 150, 300 }); SoilCrop crop = s.Children[1].Children[0] as SoilCrop; Assert.AreEqual(crop.LL, new double[] { 0.29, 0.29, 0.32, 0.38 }); Assert.AreEqual(crop.KL, new double[] { 0.1, 0.1, 0.08, 0.06 }); Assert.AreEqual(crop.XF, new double[] { 1, 1, 1, 1 }); }
/// <summary> /// Recursively calculate amount of ore required to make an amount of a chemical /// </summary> /// <param name="inputChemical"></param> /// <returns></returns> public long OreRequired(Chemical inputChemical) { if (inputChemical.Name.Equals("ORE")) { return(inputChemical.Amount); } // check if in storage if (storage.Count(c => c.Name.Equals(inputChemical.Name)) > 0) { long minimumStored = Math.Min(storage.First(c => c.Name.Equals(inputChemical.Name)).Amount, inputChemical.Amount); inputChemical.Amount -= minimumStored; storage.First(c => c.Name.Equals(inputChemical.Name)).Amount -= minimumStored; } // forgot about this if (inputChemical.Amount == 0) { return(0); } // find required reaction and the amount needed for it Reaction reaction = Reactions.First(r => r.Output.Name.Equals(inputChemical.Name)); long multiple = (long)Math.Ceiling((decimal)inputChemical.Amount / reaction.Output.Amount); // calculate ore cost long total = 0; foreach (Chemical chem in reaction.Input) { total += OreRequired(new Chemical() { Name = chem.Name, Amount = chem.Amount * multiple }); } // add extra to storage long surplus = reaction.Output.Amount * multiple - inputChemical.Amount; if (storage.Count(r => r.Name.Equals(inputChemical.Name)) > 0) { storage.First(r => r.Name.Equals(inputChemical.Name)).Amount += surplus; } else { storage.Add(new Chemical() { Name = inputChemical.Name, Amount = surplus }); } return(total); }
public GameObject prepareChemical(Vector3 location, float concentration, float width, Chemical.BacteriaReaction ecoliReaction) { GameObject chemical = Instantiate(chemicalPrefab) as GameObject; chemical.GetComponent<Chemical>().setOrigin(agar, location); chemical.GetComponent<Chemical>().setConcentration(concentration); chemical.GetComponent<Chemical>().setWidth(width); chemical.GetComponent<Chemical>().setEcoliReaction(ecoliReaction); chemical.GetComponent<Chemical>().setSource(Chemical.Source.External); return chemical; }
public string GetMolecularStructure(Chemical compound) { switch (compound) { case Chemical.Water: return "H20"; case Chemical.Benzene: return "C6H6"; case Chemical.Ethanol: return "C2H5OH"; default: return ""; } }
public double GetMolecularWeight(Chemical compound) { switch (compound) { case Chemical.Water: return 18.015; case Chemical.Benzene: return 78.1134; case Chemical.Ethanol: return 46.0688; } return 0d; }
public void Randomize(ref Random rand) { // Get 60 - 80% var pct = rand.Next(600, 800) / 1000.0f; composition.Add( new Chemical(ChemicalNames.RandomOf(ChemicalNames.HighEnd,ref rand),pct) ); RemainingPercent -= pct; var numMed = rand.Next(1, 2); // Get 10 - 20% pct = rand.Next(100, 200)/1000.0f; var loop = true; var i = 0; Chemical ch; while (loop) { ch = new Chemical(ChemicalNames.RandomOf(ChemicalNames.HighEnd, ref rand), pct); if (i < numMed && composition.Any(x => x.name != ch.name)) { composition.Add(ch); pct = rand.Next(100, 200)/1000.0f; i++; } if (i >= numMed) { loop = false; } } RemainingPercent -= pct; pct = rand.Next(5, 50)/1000.0f; var ano = rand.Next(5, 50)/1000.0f; loop = true; while (loop) { ch = new Chemical(ChemicalNames.RandomOf(ChemicalNames.HighEnd, ref rand), pct); if (RemainingPercent > ano && composition.Any(x => x.name != ch.name)) { composition.Add(ch); RemainingPercent -= pct; pct = rand.Next(5, 20) / 1000.0f; i++; } else if (RemainingPercent < ano) { loop = false; } } ch = new Chemical(ChemicalNames.RandomOf(ChemicalNames.HighEnd, ref rand), RemainingPercent); composition.Add(ch); }
public Menu() : base(UITableViewStyle.Grouped, null) { if(seedVC == null){ seedVC = new Seed (1); } if(chemicalVC == null ){ chemicalVC = new Chemical (1); } Root = new RootElement ("Menu") { new Section(){ new StyledStringElement("Seed",()=>this.NavigationController.PushViewController(seedVC,true)){ Accessory = UITableViewCellAccessory.DisclosureIndicator, }, new StyledStringElement("Chemical",()=>this.NavigationController.PushViewController(chemicalVC,true)){ Accessory = UITableViewCellAccessory.DisclosureIndicator, }, } }; }
private string getColouredChemName(Chemical chem) { return "<color=\"#" +chem.colour.ToHexStringRGB() + "\">" + chem.gameObject.name + "</color>"; }
//adds chemical to the contents, as much as there's room. returns how much was added. public float addChemical(Chemical chem, float inputQuantity) { float capacityRemaining = capacity - getQuantity(); if(capacityRemaining < inputQuantity) { inputQuantity = capacityRemaining; } if(_contents.ContainsKey(chem)) { _contents[chem] += inputQuantity; } else { _contents.Add(chem, inputQuantity); } return inputQuantity; }
private string getColouredChemSymbol(Chemical chem) { return "<color=\"#" +chem.colour.ToHexStringRGB() + "\">" + chem.symbol + "</color>"; }
/*adds chemical to the destination vessel, modified by pipe's flow rate. returns the amount of chem that was added. CALLER'S RESPONSIBILITY TO FACTOR IN DELTATIME!*/ public float pushChemical(Chemical chem, float quantity) { //TODO: opening/closing pipes, only pushing the chemical while the pipe is open. return _outputVessel.addChemical(chem, quantity * _flowRate); }
// Constructor public RichCompound(Chemical chemical) : base(chemical) { }
// Constructor public Compound(Chemical chemical) { this.Chemical = chemical; }