using System;

namespace PlantDemo
{
    public abstract class Plant : LivingEntity
    {
        public double FireX { get; set; }
        public double FireY { get; set; }
        public int FireFrequency { get; set; }
        public int Price { get; set; }
        public int Star { get; set; }

        public EventHandler OnFire { get; set; }

        public Plant()
        {
            Width = Height = 72;
        }

        public abstract Bullet Fire();

        public abstract PlantShower CreateShower();
    }

    public class FiringBulletEventArgs : EventArgs
    {
        public Bullet Bullet { get; set; }
    }

    public class PlWDSS : Plant
    {
        public PlWDSS()
        {
            FireFrequency = 1;
            FireX = 60;
            FireY = 10;
            Price = 100;
        }

        public override Bullet Fire()
        {
            BulWD bullet = new BulWD() { X = this.X + this.FireX, Y = this.Y + this.FireY };
            if (OnFire != null)
                OnFire(this, new FiringBulletEventArgs() { Bullet = bullet });
            return bullet;
        }

        public override PlantShower CreateShower()
        {
            return new PlWDSSShower(this);
        }
    }

    public class PlWDSS2 : Plant
    {
        public PlWDSS2()
        {
            FireFrequency = 2;
            FireX = 60;
            FireY = 20;
            Price = 200;
        }

        public override Bullet Fire()
        {
            BulWD bullet = new BulWD() { X = this.X + this.FireX, Y = this.Y + this.FireY };
            if (OnFire != null)
                OnFire(this, new FiringBulletEventArgs() { Bullet = bullet });
            return bullet;
        }

        public override PlantShower CreateShower()
        {
            return new PlWDSS2Shower(this);
        }
    }

    public class PlWDSS3 : Plant
    {
        int kTime = 0;

        public PlWDSS3()
        {
            FireFrequency = 4;
            FireX = 30;
            FireY = 25;
            Price = 325;
        }

        public override Bullet Fire()
        {
            int k = (kTime++) % 3;
            BulWD bullet = new BulWD() { X = this.X + this.FireX, Y = this.Y + this.FireY };
            if (k == 1)
                bullet.VY = 5;
            else if (k == 2)
                bullet.VY = -5;
            if (OnFire != null)
                OnFire(this, new FiringBulletEventArgs() { Bullet = bullet });
            return bullet;
        }

        public override PlantShower CreateShower()
        {
            return new PlWDSS3Shower(this);
        }
    }


    public class PlHBSS : Plant
    {
        public PlHBSS()
        {
            FireFrequency = 1;
            FireX = 60;
            FireY = 10;
            Price = 175;
        }

        public override Bullet Fire()
        {
            BulBWD bullet = new BulBWD() { X = this.X + this.FireX, Y = this.Y + this.FireY };
            if (OnFire != null)
                OnFire(this, new FiringBulletEventArgs() { Bullet = bullet });
            return bullet;
        }

        public override PlantShower CreateShower()
        {
            return new PlHBSSShower(this);
        }
    }

    public class PlXMG : Plant
    {
        public PlXMG()
        {
            FireFrequency = 1;
            Width = 50;
            Height = 49;
            FireX = 35;
            FireY = 30;
            Price = 45;
        }

        public override Bullet Fire()
        {
            BulXQP bullet = new BulXQP() { X = this.X + this.FireX, Y = this.Y + this.FireY };
            if (OnFire != null)
                OnFire(this, new FiringBulletEventArgs() { Bullet = bullet });
            return bullet;
        }

        public override PlantShower CreateShower()
        {
            return new PlXMGShower(this);
        }
    }

    public class PlPMG : Plant
    {
        int kTime = 0;

        public PlPMG()
        {
            FireFrequency = 4;
            FireX = 30;
            FireY = 30;
            Price = 225;
        }

        public override Bullet Fire()
        {
            BulQP bullet = new BulQP() { X = this.X + this.FireX, Y = this.Y + this.FireY };
            int k = (kTime++) % 5;
            if (k == 1)
                bullet.VY = 8;
            else if (k == 2)
            {
                bullet.VX = 0;
                bullet.VY = 8;
            }
            else if (k == 3)
                bullet.VY = -8;
            else if (k == 4)
            {
                bullet.VX = 0;
                bullet.VY = -8;
            }
            if (OnFire != null)
                OnFire(this, new FiringBulletEventArgs() { Bullet = bullet });
            return bullet;
        }

        public override PlantShower CreateShower()
        {
            return new PlPMGShower(this);
        }
    }
}
