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

public class RepeatDrums : MonoBehaviour {
    public int difficulty = 1;
    int stackHeight;
	public GameObject go;
    // Use this for initialization
    void Start()
    {
       //InvokeRepeating("DrumMakeBeat", 1f, 1f);
    }

    // Update is called once per frame
    void Update()
    {

    }

    public void DrumMakeBeat()
    {
        List<GameObject> segments = new List<GameObject>();
        int[] occlude = new int[8];
        int side = -1;
        
        float distanceFromCenter = 0f;
        Instantiate(go, gameObject.transform);
        switch (difficulty) {
            case 1:
                stackHeight = Random.Range(1, 5);
                break;
            case 2:
                stackHeight = Random.Range(1, 10);
                break;
            case 3:
                stackHeight = Random.Range(1, 15);
                break;
            default:
                Debug.Log("All Drum Sticks are Broken");
                break;
        }
        
        
        for (int k = 0; k < stackHeight; k++)
        {
            GameObject addOne = Instantiate(go, gameObject.transform) as GameObject;
            addOne.transform.position += Vector3.up * k * .625f;
        }
        for (int j = 0; j < 4; j++)
        {
            occlude[j] = Random.Range(2, 22);
            occlude[j + 4] = occlude[j] + 1;
        }
        for (int i = 0; i < 24; i++)
        {
            if (side == -1)
            {
                distanceFromCenter += 1.125f;
            }
            GameObject thisSeg = Instantiate(go, gameObject.transform) as GameObject;
            segments.Add(thisSeg);
            segments[i].transform.position += Vector3.right * distanceFromCenter * side;
            if (i != occlude[0] && i != occlude[1] && i != occlude[2] && i != occlude[3] && i != occlude[4] && i != occlude[5] && i != occlude[6] && i != occlude[7])
            {
                switch (difficulty)
                {
                    case 1:
                        stackHeight = Random.Range(1, 5);
                        break;
                    case 2:
                        stackHeight = Random.Range(1, 10);
                        break;
                    case 3:
                        stackHeight = Random.Range(1, 15);
                        break;
                    default:
                        Debug.Log("All Drum Sticks are Broken");
                        break;
                }
                for (int k = 0; k < stackHeight; k++)
                {
                    GameObject addOne = Instantiate(go, gameObject.transform) as GameObject;
                    addOne.transform.position += segments[i].transform.position + (Vector3.up * k * .625f);
                }
            }
            side *= -1;
        }
        

        /*foreach (GameObject one in segments) {
            int stackHieght = Random.Range(1, 16);
            for (int k = 0; k < stackHieght; k++) {
                GameObject addOne = Instantiate(go, gameObject.transform) as GameObject;
                addOne.transform.position += Vector3.up * k * .625f;
            }
        }*/
    }
}
