﻿using UnityEngine;

namespace Gamelogic.Grids.Examples
{
	public class HoneyCombBlock : GLMonoBehaviour
	{
		public enum State
		{
			Up,
			GoingUp,
			Down,
			GoingDown
		}

		public bool IsCrusher { get; set; }

		private State state = State.Down;
		private const float animationSpeed = 80f;

		public void SetColor(Color color)
		{
			renderer.material.color = color;
		}


		public float Height
		{
			set { transform.SetScaleZ(value); }
			get { return transform.localScale.z; }
		}

		public void Update()
		{
			if (!IsCrusher) return;

			switch (state)
			{
				case State.Up:
					if (Random.value < 0.005f)
					{
						state = State.GoingDown;
					}
					break;
				case State.GoingUp:
					Height += animationSpeed*Time.deltaTime;
					if (Height > 40)
					{
						Height = 40;
						state = State.Up;
					}
					break;
				case State.Down:
					if (Random.value < 0.005f)
					{
						state = State.GoingUp;
					}
					break;
				case State.GoingDown:
					Height -= animationSpeed*Time.deltaTime;
					if (Height < 3)
					{
						Height = 3;
						state = State.Down;
					}
					break;
			}
		}
	}
}