public bool ContainsSubstance(Substance substance) { return(this.Substances.Keys.Contains(substance)); }
public void ReleaseSubstance(Substance substance, double amount, double distance) { if (substance == null) { throw new ArgumentNullException("Substance cannot be null."); } if (!this.Resources.ContainsKey(substance)) { return; } if (amount > this.Resources[substance].Amount) { amount = this.Resources[substance].Amount; } Func <double, double, double> f = (double x, double y) => { var t = x * x + y * y; return((1 / ((2 * Math.PI) * 3)) * Math.Exp(-t / (18))); }; List <long> xList = new List <long>(); List <long> yList = new List <long>(); List <double> rList = new List <double>(); double sum = 0; for (long y = (long)(this.Y - distance); y < (long)(this.Y + distance); y++) { for (long x = (long)(this.X - distance); x < (long)(this.X + distance); x++) { if (x * x + y * y > distance * distance) { continue; } if (x < 0) { x = -x; } if (x > World.Width) { x = World.Width - (x - World.Width); } if (y < 0) { y = -y; } if (y > World.Height) { y = World.Height - (y - World.Height); } var r = f(x, y); sum += r; xList.Add(x); yList.Add(y); rList.Add(r); } } for (var i = 0; i < yList.Count; i++) { var x = xList[i]; var y = yList[i]; var r = rList[i]; var amt = amount * r / sum; World[x, y].Add(substance, amt); } this.Resources[substance].SetAmount(this.Resources[substance].Amount - amount); }
public string RegisterSubstance(Substance substance) { Substances.Add(substance); globalCount++; return(Substances.Count.ToString()); }