using Microsoft.Xna.Framework;
using System;
using System.Linq;

namespace Igdc.Drawables
{
    public class MapEnemy : DrawableBase
    {
        public byte X;
        public byte Y;
        public int Texture;
        public int Difficulty;

        public bool DeleteMark;

        public override Point Size => new Point(16);

        private static readonly Random Random = new Random();

        public bool IsNear(MapPlayer p)
        {
            if (Math.Abs(X - p.X) > 1) return false;
            if (Math.Abs(Y - p.Y) > 1) return false;
            return true;
        }

        public BattleEnemy[] CreateBattleEnemies()
        {
            var enemies = new BattleEnemy[Difficulty];
            for (var i = 0; i < Difficulty; i++)
            {
                while (true)
                {
                    var x = (byte)Random.Next(0, 3);
                    var y = (byte)Random.Next(0, 2);
                    if (enemies.Where(a => a != null).Any(a => x == a.X && y == a.Y)) continue;
                    var enemy = new BattleEnemy { X = x, Y = y, Health = Random.Next(2 + Difficulty, 4 + Difficulty), Texture = Texture, ShootingChance = Random.Next(2 + Difficulty, 4 + Difficulty * Difficulty) };
                    enemies[i] = enemy;
                    break;
                }
            }
            return enemies;
        }
    }
}