using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System;

public class TrackGenerator : MonoBehaviour
{
    System.Random rnd = new System.Random();
    GameControler gameController;
    //public WidgetManager widgetManager;

    void Start()
    {
        gameController = transform.parent.GetComponentInChildren<GameControler>();
    }
    
  
    public Track generateNewTrack(int difficultyRequested, bool typeError)
    {
        // Check which widgets are available
        int tries = 0;
        Track track = null;
		// Track could try to create itself but not find the widgets needed, if that happens
		// valid is set to false. Yeah, it's hacky...

        while ((track == null || track.valid == false) && tries < 100)
        {
            tries++;
            int trackType = rnd.Next(0, Math.Min(difficultyRequested,5));
            
			//trackType = 4;// DeBUG

            switch (trackType)
            {
                case 0: //Do
                case 1:
                    Debug.Log("TrackGenerator.generateNewTrack() Do");
                    track = new Track_Do(gameController, true); //typeError);//widgetManager);                    
                    break;                    
                case 2: 
                case 3:
                //DoThen                    
                    Debug.Log("TrackGenerator.generateNewTrack() DoThen");
                    track = new Track_DoThen(gameController, typeError);//widgetManager);
                    break;
                case 4: //DoWhen
                case 5:
                    Debug.Log("TrackGenerator.generateNewTrack() DoWhen");
                    track = new Track_DoWhen(gameController, typeError);//widgetManager);
                    break;
                default:
                    break;
            }   
            
        }
        return track;
    }
}
