public void TestMethod1() { List <EatingHistoryItem> items = new List <EatingHistoryItem>(); EatingHistoryItem item1 = new EatingHistoryItem() { Calories = 100, Carbohydrates = 100, Fats = 100, Proteins = 100 }; EatingHistoryItem item2 = new EatingHistoryItem() { Calories = 20, Carbohydrates = 10, Fats = 0, Proteins = 30 }; items.Add(item1); items.Add(item2); FoodStatisticsCounter counter = new FoodStatisticsCounter(); FoodStats stats = counter.CountFoodStatistics(items); Assert.AreEqual(120, stats.Calories); Assert.AreEqual(110, stats.Carbohydrates); Assert.AreEqual(100, stats.Fats); Assert.AreEqual(130, stats.Proteins); }
// получение полной информации за конкретный день - список блюд, возможность добавления новых блюд и статистику public void GetDailyInfo(DateTime date) { DailyHistory = new ObservableCollection <EatingHistoryItem>(_repo.GetDailyHistoryData(date)); if (date.Date == DateTime.Now.Date) { IsCurrentDate = true; } else { IsCurrentDate = false; } DailyFoodStatistics = _counter.CountFoodStatistics(DailyHistory.ToList()); }
public static double eatFood(GameObject eatenFood, double eatWish) { FoodStats eatenFoodStats = eatenFood.GetComponent <FoodStats>(); if (eatenFoodStats.foodAmountAvailable > eatWish) { eatenFoodStats.foodAmountAvailable -= (float)eatWish * Time.deltaTime; return(eatWish * Time.deltaTime); } eatenFoodStats.foodAmountAvailable = 0; return(0); }
protected override void OnUpdate() { Entities.ForEach((Bibit bibit, Transform transform) => { Profiler.BeginSample("foods vergleichen"); //resetToDefaults: bibit.distToNearestPoison = float.PositiveInfinity; bibit.distToNearestFood = float.PositiveInfinity; bibit.distToNearestBibit = float.PositiveInfinity; bibit.angleToNearestPoison = null; bibit.angleToNearestFood = null; bibit.angleToNearestBibit = null; bibit.nearestFood = null; bibit.nearestPoison = null; bibit.foodAmountInSightRadius = 0; bibit.nearestBibit = null; neighbours.Clear(); Vector3 transPos = transform.position; int transPosX = Mathf.RoundToInt(transPos.x + offsetX) + 1; int transPosY = Mathf.RoundToInt(offsetY - transPos.y) + 1; //todo: mehrere Iterationen einbauen, for loop, sichtradius vererben if (transPosX <= widthBounds && transPosY <= heightBounds && transPosX >= 0 && transPosY > 0) { FoodStats currentField = fields[transPosX, transPosY]; neighbours.Add(currentField); } if (transPosX <= widthBounds && transPosY + 1 <= heightBounds && transPosX >= 0 && transPosY + 1 > 0) { FoodStats aboveField = fields[transPosX, transPosY + 1]; neighbours.Add(aboveField); } if (transPosX <= widthBounds && transPosY - 1 <= heightBounds && transPosX >= 0 && transPosY - 1 > 0) { FoodStats belowField = fields[transPosX, transPosY - 1]; neighbours.Add(belowField); } if (transPosX - 1 <= widthBounds && transPosY <= heightBounds && transPosX - 1 >= 0 && transPosY > 0) { FoodStats leftField = fields[transPosX - 1, transPosY]; neighbours.Add(leftField); } if (transPosX + 1 <= widthBounds && transPosY <= heightBounds && transPosX + 1 >= 0 && transPosY > 0) { FoodStats rightField = fields[transPosX + 1, transPosY]; neighbours.Add(rightField); } if (transPosX + 1 <= widthBounds && transPosY + 1 <= heightBounds && transPosX + 1 >= 0 && transPosY + 1 > 0) { FoodStats rightAboveField = fields[transPosX + 1, transPosY + 1]; neighbours.Add(rightAboveField); } if (transPosX + 1 <= widthBounds && transPosY - 1 <= heightBounds && transPosX + 1 >= 0 && transPosY - 1 > 0) { FoodStats rightBelowField = fields[transPosX + 1, transPosY - 1]; neighbours.Add(rightBelowField); } if (transPosX - 1 <= widthBounds && transPosY + 1 <= heightBounds && transPosX - 1 >= 0 && transPosY + 1 > 0) { FoodStats leftAboveField = fields[transPosX - 1, transPosY + 1]; neighbours.Add(leftAboveField); } if (transPosX - 1 <= widthBounds && transPosY - 1 <= heightBounds && transPosX - 1 >= 0 && transPosY - 1 > 0) { FoodStats leftBelowField = fields[transPosX - 1, transPosY - 1]; neighbours.Add(leftBelowField); } foreach (FoodStats f in neighbours) { if (f.CompareTag("poison")) { Vector3 neighbourPos = f.transform.position; float newDist = Vector2.Distance(transPos, neighbourPos); if (newDist < bibit.distToNearestPoison) { bibit.distToNearestPoison = newDist; bibit.angleToNearestPoison = Vector3.SignedAngle(transform.up, neighbourPos - transPos, transform.forward); bibit.nearestPoison = f.gameObject; } } } foreach (FoodStats f in neighbours) { if (f.CompareTag("food")) { Vector3 neighbourPos = f.transform.position; bibit.foodAmountInSightRadius += f.foodAmountAvailable; float newDist = Vector2.Distance(transPos, neighbourPos); if (newDist < bibit.distToNearestFood) { bibit.nearestFood = f.gameObject; bibit.distToNearestFood = newDist; bibit.angleToNearestFood = Vector3.SignedAngle(transform.up, neighbourPos - transPos, transform.forward); } } } Profiler.EndSample(); bibit.isOnPoison = bibit.distToNearestPoison < bibit.distToNearestFood; }); }
// удаление элемента из таблицы с историей и обновление статистики public void DeleteItem(EatingHistoryItem item) { _repo.RemoveEatingHistoryItem(item); DailyHistory.Remove(item); DailyFoodStatistics = _counter.CountFoodStatistics(DailyHistory.ToList()); }