using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using HumanLikeBattleRobots.Graphic;

namespace HumanLikeBattleRobots.Logic
{
    class Box : ICollidable, IOtherObjects
    {
        private Vec2f position;
        private float size;
        private float health;
        private BoxSprite sprite = new BoxSprite(1);

        public Box(Vec2f position)
        {
            this.position = position;
            size = 32;
            health = 1;
            sprite.Position = this.position;
            sprite.Angle = GameManager.MainRandom.Next(0, 361);
            GameManager.otherObjects.Add(this);
            GameManager.collidable.Add(this);
        }

        public void Draw()
        {
            sprite.Draw();
        }

        Vec2f ICollidable.Position
        {
            get { return position; }
        }

        float ICollidable.Radius
        {
            get { return size; }
        }

        float ICollidable.HitRadius
        {
            get { return size; }
        }

        void ICollidable.GetDamage(float damage)
        {
            health -= damage;
            if (health <= 0)
            {
                GameManager.otherObjects.Remove(this);
                GameManager.collidable.Remove(this);
                new Explosion(this.position);
                int bonusProbability = GameManager.MainRandom.Next(0, 8);
                switch (bonusProbability)
                {
                    case 1:
                    case 2:
                    case 3:
                        new HealthBonus(this.position);
                        break;
                    case 4:
                    case 5:
                        new SpeedBonus(this.position);
                        break;
                    default:
                        new DamageBonus(this.position);
                        break;
                }
            }
        }

        public void  Proceed()
        {
            if (position.Distance(GameManager.myRobot.Position) > 2500)
            {
                GameManager.otherObjects.Remove(this);
                GameManager.collidable.Remove(this);
            }
        }

        public int Stage()
        {
            return 1;
        }
    }
}
