public bool Consume(long time) { double realConsumption = time - lastTimeConsumed; double energyGot = energySource.giveElectricity(realConsumption, time); lastTimeConsumed = time; //if (Math.Abs(realConsumption - energyGot)<0.001) //Console.WriteLine(String.Format("Потребитель {0} потребовал {1} энергии, получил {2}", name, realConsumption, energyGot)); return(Math.Abs(realConsumption - energyGot) < 0.001); }
double IElectriticyGiver.giveElectricity(double amount, long time) { if (is_broken) { return(0); } long timePassed = time - lastTimeChecked; double final_break_prob = 1 - Math.Pow(1 - break_prob, timePassed); lastTimeChecked = time; if (RandomGenerator.getRandomBool(final_break_prob)) { is_broken = true; Console.WriteLine(String.Format("Провод {0} сломался", Name)); return(0); } else { var totalLoss = lossPerLenght * Length; //Console.WriteLine(String.Format("Выдано {0} энергии", amount + totalLoss)); return(parent.giveElectricity(amount + totalLoss, time) - totalLoss); } }