using System;
using System.Windows;

namespace PlantDemo
{
    public abstract class Entity
    {
        bool bDestroyed;
        public bool IsDestroyed { get { return bDestroyed; } }

        int steps;
        public int Steps { get { return steps; } }

        public double X { get; set; }
        public double Y { get; set; }
        public double Width { get; set; }
        public double Height { get; set; }
        public double VX { get; set; }
        public double VY { get; set; }

        public virtual void Move()
        {
            steps++;
            X += VX;
            Y += VY;
            if (OnMove != null)
                OnMove(this, null);
        }

        public event EventHandler OnMove;

        public Rect Region
        {
            get { return new Rect(X, Y, Width, Height); }
        }

        public virtual bool Overlap(Entity other)
        {
            return this.Region.IntersectsWith(other.Region);
        }

        public void Destroy()
        {
            bDestroyed = true;
            if (OnDestroyed != null)
                OnDestroyed(this, null);
        }

        public event EventHandler OnDestroyed;
    }

    public abstract class LivingEntity : Entity
    {
        protected double heathPoint;
        public double HeathPoint
        {
            get { return heathPoint; }
            set
            {
                heathPoint = value;
                if (heathPoint <= 0)
                    this.Destroy();
            }
        }
    }
}
