Added levels. Dishes can only be made once
This commit is contained in:
@@ -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();
|
||||
// }
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,23 +1,61 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
public class LevelManager : MonoBehaviour
|
||||
{
|
||||
public int level;
|
||||
public List<int> levelRequirements;
|
||||
public TextMeshProUGUI UserScoreText;
|
||||
public TextMeshProUGUI RequiredScoreText;
|
||||
public TextMeshProUGUI LevelText;
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
private void Start()
|
||||
{
|
||||
level = 1;
|
||||
UpdateUserScore(0);
|
||||
UpdateRequiredScore(levelRequirements[0]);
|
||||
UpdateLevel(level);
|
||||
}
|
||||
|
||||
// Update is called once per frame
|
||||
public void UpdateLevel(int levelNumber)
|
||||
{
|
||||
|
||||
private void Update() {
|
||||
|
||||
if (levelNumber > levelRequirements.Count)
|
||||
{
|
||||
LevelText.text = "You win";
|
||||
RequiredScoreText.text = "";
|
||||
return;
|
||||
}
|
||||
|
||||
int score = levelRequirements[levelNumber - 1];
|
||||
|
||||
RequiredScoreText.text = score.ToString();
|
||||
LevelText.text = "Level: " + levelNumber.ToString();
|
||||
UpdateUserScore(0);
|
||||
}
|
||||
|
||||
|
||||
public void UpdateUserScore(int score)
|
||||
{
|
||||
UserScoreText.text = score.ToString();
|
||||
}
|
||||
|
||||
public void UpdateRequiredScore(int score)
|
||||
{
|
||||
RequiredScoreText.text = score.ToString();
|
||||
}
|
||||
|
||||
public void CompareScores()
|
||||
{
|
||||
int userScore = int.Parse(UserScoreText.text);
|
||||
int requredScore = int.Parse(RequiredScoreText.text);
|
||||
|
||||
if (userScore >= requredScore)
|
||||
{
|
||||
level += 1;
|
||||
UpdateLevel(level);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user