Added levels. Dishes can only be made once

This commit is contained in:
2024-04-10 09:45:19 +02:00
parent d984e0dfe3
commit 299d85e236
3 changed files with 104 additions and 41 deletions

View File

@@ -1,5 +1,6 @@
using System.Collections;
using System.Collections.Generic;
using System.Net;
using Microsoft.Unity.VisualStudio.Editor;
using TMPro;
using UnityEngine;
@@ -21,15 +22,8 @@ public class Cooking : MonoBehaviour
public Vector3 FinishedDishPosition;
public GameObject AllIngredients;
public int requiredScore = 5;
public TextMeshProUGUI UserScoreText;
public TextMeshProUGUI RequredScoreText;
private void Start()
{
UserScoreText.text = "0";
RequredScoreText.text = requiredScore.ToString();
}
public GameObject LevelManager;
private List<GameObject> DishesCooked = new List<GameObject>(); // stop user from cooking same dish twice.
public void CreateDish() {
List <GameObject> Ingredients = GetIngredients();
@@ -96,6 +90,16 @@ public class Cooking : MonoBehaviour
}
}
foreach (GameObject cookedDish in DishesCooked)
{
if (BestDish == cookedDish){
return;
}
}
DishesCooked.Add(BestDish);
// Find used ingredients
List <GameObject> IngredientsInDish = BestDish.GetComponent<Dish>().RequiredIngredients;
List <GameObject> UsedIngredients = new();
@@ -133,13 +137,16 @@ public class Cooking : MonoBehaviour
// Show dish ui screen
Sprite DishImage = BestDish.GetComponent<SpriteRenderer>().sprite;
int Stars = 3;
int NutritionalValue = BestDish.GetComponent<Dish>().NutritionalValue;
int Stars = NutritionalValueToStars(NutritionalValue);
string DishName = BestDish.name;
gameObject.GetComponent<DishUI>().ShowUI(DishName, DishImage, Stars);
UpdateUserScore(Stars);
int NV = BestDish.GetComponent<Dish>().NutritionalValue;
LevelManager.GetComponent<LevelManager>().UpdateUserScore(NV);
LevelManager.GetComponent<LevelManager>().CompareScores();
}
// Keep track of ingredients going on and off the cooker.
@@ -161,18 +168,29 @@ public class Cooking : MonoBehaviour
}
return Ingredients;
}
private void UpdateUserScore(int score)
private int NutritionalValueToStars(int NV)
{
UserScoreText.text = score.ToString();
int stars = 1;
if (NV >= 11)
{
stars = 2;
}
if (NV >= 14)
{
stars = 3;
}
if (NV >= 20)
{
stars = 4;
}
if (NV >= 22)
{
stars = 5;
}
return stars;
}
// void Update()
// {
// GetIngredients();
// }
}