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

public class Cylinder : MonoBehaviour
{
    public List<GameObject> discs;

    public float baseX;
    public float baseY;
    public float baseZ;

    private float diffY = 1.5f;
    private float startY = -6.5f;

    public bool selected = false;
    public GameObject control;

    void UpdateLight()
    {
        if (this.selected)
        {
            this.control.transform.position = new Vector3(this.baseX, 10, this.baseZ);
        }
    }

    public bool CanPutDisc(GameObject disc)
    {
        if (this.discs.Count == 0)
        {
            return true;
        }

        return this.discs[this.discs.Count - 1].GetComponent<Disc>().size > disc.GetComponent<Disc>().size;
    }

    public GameObject GetTopDisc()
    {
        GameObject topDisc = this.discs[this.discs.Count - 1];
        this.discs.RemoveAt(this.discs.Count - 1);
        return topDisc;
    }

    // Update is called once per frame
    void FixedUpdate()
    {
        float y = this.startY;
        foreach (GameObject disc in this.discs)
        {
            disc.transform.position = new Vector3(this.baseX, y, this.baseZ);
            y += this.diffY;
        }
        this.UpdateLight();
    }
}
