This commit is contained in:
happy44300
2018-08-13 19:10:00 +02:00
2 changed files with 31 additions and 22 deletions

View File

@@ -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<Mission>().HasWon();
}
}
private bool UserHasWon()
{
foreach (KeyValuePair<TreeType, int> pair in GetComponent<Mission>().Objectifs)
{
if (plots.Count(x => x.treePlaced == pair.Key) < pair.Value)
return false;
}
return true;
}
public void StartDraggin(int index)

View File

@@ -9,7 +9,7 @@ public class Mission : MonoBehaviour {
string Missiontext = null;
TreeItem[] items;
public float difficulte;
private Dictionary<string, int> Objectifs = new Dictionary<string, int>();
public Dictionary<TreeType, int> Objectifs = new Dictionary<TreeType, int>();
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<string,int> i in Objectifs)
foreach (KeyValuePair<TreeType,int> 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()
{
}
}