Cooking function can find the best dish possible

This commit is contained in:
2024-03-12 14:57:25 +01:00
parent 9636ce41d3
commit 35211790a4
2 changed files with 25 additions and 6 deletions

View File

@@ -29,8 +29,9 @@ public class Cooking : MonoBehaviour
}
}
List <GameObject> PossibleDishes = new List <GameObject>();
List <GameObject> PossibleDishes = new List <GameObject>();
// Find the dishes, where all ingredients exist
foreach (GameObject Dish in AllDishes) {
@@ -51,11 +52,29 @@ public class Cooking : MonoBehaviour
}
}
foreach (GameObject Dish in PossibleDishes) {
Debug.Log(Dish);
// No dishes possible
if (PossibleDishes.Count < 1) {
return;
}
GameObject BestDish = null;
foreach (GameObject Dish in PossibleDishes) {
if (BestDish == null) {
BestDish = Dish;
continue;
}
int CurrentNutritionalValue = Dish.GetComponent<Dish>().NutritionalValue;
int BestNutrionnalValue = BestDish.GetComponent<Dish>().NutritionalValue;
if (CurrentNutritionalValue > BestNutrionnalValue) {
BestDish = Dish;
}
}
Debug.Log(BestDish.name);
}