diff --git a/Assets/Script/InventoryManager.cs b/Assets/Script/InventoryManager.cs index 7262f58..ab5385a 100644 --- a/Assets/Script/InventoryManager.cs +++ b/Assets/Script/InventoryManager.cs @@ -4,6 +4,7 @@ using UnityEngine; using UnityEngine.Tilemaps; using TMPro; using UnityEngine.UI; +using System.Linq; public class InventoryManager : MonoBehaviour { @@ -279,6 +280,21 @@ public class InventoryManager : MonoBehaviour } } } + + if (UserHasWon()) + { + GetComponent().HasWon(); + } + } + + private bool UserHasWon() + { + foreach (KeyValuePair pair in GetComponent().Objectifs) + { + if (plots.Count(x => x.treePlaced == pair.Key) < pair.Value) + return false; + } + return true; } public void StartDraggin(int index) diff --git a/Assets/Script/Mission.cs b/Assets/Script/Mission.cs index d0ab323..76affee 100644 --- a/Assets/Script/Mission.cs +++ b/Assets/Script/Mission.cs @@ -9,7 +9,7 @@ public class Mission : MonoBehaviour { string Missiontext = null; TreeItem[] items; public float difficulte; - private Dictionary Objectifs = new Dictionary(); + public Dictionary Objectifs = new Dictionary(); public int MinArbre = 1; public int MaxArbre = 10; private void Start() @@ -19,8 +19,8 @@ public class Mission : MonoBehaviour { { Debug.Log("eroor"); } - //Debug.Log(items[0].type); - if(difficulte> items.Length) + + if (difficulte> items.Length) { Debug.LogError("difficulté trop grande"); } @@ -37,32 +37,25 @@ public class Mission : MonoBehaviour { { Objectifs.Add(ChoisirUnTypeDarbre(), Random.Range(MinArbre, MaxArbre)); } - foreach (KeyValuePair i in Objectifs) + foreach (KeyValuePair i in Objectifs) { - Missiontext = Missiontext + "Place: " + i.Value+ " " + i.Key +"\n"; + Missiontext = Missiontext + "Place: " + i.Value + " " + i.Key.ToString() +"\n"; } - - - //ChoisirUnTypeDarbre() - //Random.Range(MinArbre, MaxArbre) - - } + public string GetMissionText() { return Missiontext; } - public string ChoisirUnTypeDarbre() - { - string arbre = items.Where(x => !Objectifs.ContainsKey(x.type.ToString()) && x.type != TreeType.Nothing).ToArray()[Random.Range(0, items.Where(x => !Objectifs.ContainsKey(x.type.ToString()) && x.type != TreeType.Nothing).ToArray().Length)].type.ToString(); - //if (Objectifs.ContainsKey(arbre)) - //{ - // return ChoisirUnTypeDarbre(); - //} - //else - //{ - return arbre; - //} + public TreeType ChoisirUnTypeDarbre() + { + TreeType arbre = items.Where(x => !Objectifs.ContainsKey(x.type) && x.type != TreeType.Nothing).ToArray()[Random.Range(0, items.Where(x => !Objectifs.ContainsKey(x.type) && x.type != TreeType.Nothing).ToArray().Length)].type; + return arbre; + } + + public void HasWon() + { + } }