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

@@ -900,7 +900,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
RequiredIngredients: RequiredIngredients:
- {fileID: 885031692} - {fileID: 885031692}
NutritionalValue: 10 NutritionalValue: 8
--- !u!61 &449563474 --- !u!61 &449563474
BoxCollider2D: BoxCollider2D:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -1014,7 +1014,7 @@ MonoBehaviour:
- {fileID: 1274549341} - {fileID: 1274549341}
- {fileID: 1420342329} - {fileID: 1420342329}
- {fileID: 885031692} - {fileID: 885031692}
NutritionalValue: 200 NutritionalValue: 20
--- !u!212 &460072663 --- !u!212 &460072663
SpriteRenderer: SpriteRenderer:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -1557,7 +1557,7 @@ MonoBehaviour:
- {fileID: 1001436608} - {fileID: 1001436608}
- {fileID: 1274549341} - {fileID: 1274549341}
- {fileID: 1659394507} - {fileID: 1659394507}
NutritionalValue: 150 NutritionalValue: 23
--- !u!212 &578240411 --- !u!212 &578240411
SpriteRenderer: SpriteRenderer:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -1669,6 +1669,11 @@ MonoBehaviour:
m_Script: {fileID: 11500000, guid: bbc9dba12af11ea408751c79d0373658, type: 3} m_Script: {fileID: 11500000, guid: bbc9dba12af11ea408751c79d0373658, type: 3}
m_Name: m_Name:
m_EditorClassIdentifier: m_EditorClassIdentifier:
level: 1
levelRequirements: 0b0000000e000000130000001500000017000000
UserScoreText: {fileID: 1335248046}
RequiredScoreText: {fileID: 1979510732}
LevelText: {fileID: 1587131887}
--- !u!1 &680543386 --- !u!1 &680543386
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -2200,7 +2205,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
RequiredIngredients: RequiredIngredients:
- {fileID: 537514707} - {fileID: 537514707}
NutritionalValue: 50 NutritionalValue: 12
--- !u!1 &878970302 --- !u!1 &878970302
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -3227,7 +3232,7 @@ MonoBehaviour:
RequiredIngredients: RequiredIngredients:
- {fileID: 1575942281} - {fileID: 1575942281}
- {fileID: 885031692} - {fileID: 885031692}
NutritionalValue: 20 NutritionalValue: 10
--- !u!212 &1325467682 --- !u!212 &1325467682
SpriteRenderer: SpriteRenderer:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -4019,9 +4024,7 @@ MonoBehaviour:
m_EditorClassIdentifier: m_EditorClassIdentifier:
FinishedDishPosition: {x: -4.66, y: 2.89, z: 0} FinishedDishPosition: {x: -4.66, y: 2.89, z: 0}
AllIngredients: {fileID: 24980075} AllIngredients: {fileID: 24980075}
requiredScore: 5 LevelManager: {fileID: 637472079}
UserScoreText: {fileID: 1335248046}
RequredScoreText: {fileID: 1979510732}
--- !u!50 &1517788317 --- !u!50 &1517788317
Rigidbody2D: Rigidbody2D:
serializedVersion: 4 serializedVersion: 4
@@ -4180,7 +4183,7 @@ MonoBehaviour:
- {fileID: 1659394507} - {fileID: 1659394507}
- {fileID: 1274549341} - {fileID: 1274549341}
- {fileID: 885031692} - {fileID: 885031692}
NutritionalValue: 0 NutritionalValue: 19
--- !u!212 &1525651429 --- !u!212 &1525651429
SpriteRenderer: SpriteRenderer:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -4375,7 +4378,7 @@ GameObject:
- component: {fileID: 1587131888} - component: {fileID: 1587131888}
- component: {fileID: 1587131887} - component: {fileID: 1587131887}
m_Layer: 5 m_Layer: 5
m_Name: text m_Name: LevelText
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
@@ -4421,7 +4424,9 @@ MonoBehaviour:
m_OnCullStateChanged: m_OnCullStateChanged:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
m_text: 'Required score:' m_text: 'Level: [Level]
Required score:'
m_isRightToLeft: 0 m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
@@ -4808,7 +4813,7 @@ MonoBehaviour:
- {fileID: 1420342329} - {fileID: 1420342329}
- {fileID: 1575942281} - {fileID: 1575942281}
- {fileID: 885031692} - {fileID: 885031692}
NutritionalValue: 40 NutritionalValue: 21
--- !u!212 &1680633069 --- !u!212 &1680633069
SpriteRenderer: SpriteRenderer:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -5045,7 +5050,7 @@ MonoBehaviour:
- {fileID: 143107362} - {fileID: 143107362}
- {fileID: 537514707} - {fileID: 537514707}
- {fileID: 1001436608} - {fileID: 1001436608}
NutritionalValue: 180 NutritionalValue: 14
--- !u!212 &1714471224 --- !u!212 &1714471224
SpriteRenderer: SpriteRenderer:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -5162,7 +5167,7 @@ MonoBehaviour:
- {fileID: 143107362} - {fileID: 143107362}
- {fileID: 1274549341} - {fileID: 1274549341}
- {fileID: 1001436608} - {fileID: 1001436608}
NutritionalValue: 300 NutritionalValue: 21
--- !u!212 &1790468150 --- !u!212 &1790468150
SpriteRenderer: SpriteRenderer:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@@ -5349,7 +5354,9 @@ MonoBehaviour:
m_OnCullStateChanged: m_OnCullStateChanged:
m_PersistentCalls: m_PersistentCalls:
m_Calls: [] m_Calls: []
m_text: '[insert score]' m_text: '
[insert score]'
m_isRightToLeft: 0 m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}
m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2}

View File

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

View File

@@ -1,23 +1,61 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using TMPro;
using UnityEngine; using UnityEngine;
public class LevelManager : MonoBehaviour public class LevelManager : MonoBehaviour
{ {
public int level; public int level;
public List<int> levelRequirements;
public TextMeshProUGUI UserScoreText;
public TextMeshProUGUI RequiredScoreText;
public TextMeshProUGUI LevelText;
// Start is called before the first frame update // Start is called before the first frame update
void Start() private void Start()
{ {
level = 1; 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);
}
}
} }