using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using Blindfold.Objects;


namespace Blindfold.Managers
{
    /// <summary>
    /// This is a game component that implements IUpdateable.
    /// </summary>
    public class ObjManager : Microsoft.Xna.Framework.GameComponent
    {
        public static Main GAME;

        List<Obj> lib;
        private bool isCleared;

        #region PROPERTIES
        public List<Obj> LIB
        {
            get
            {
                return lib;
            }
        }
        #endregion

        public ObjManager(Main game)
            : base(game)
        {
            // TODO: Construct any child components here
             GAME = game;
             lib = new List<Obj>();
        }

        /// <summary>
        /// Allows the game component to perform any initialization it needs to before starting
        /// to run.  This is where it can query for any required services and load content.
        /// </summary>
        public override void Initialize()
        {
            // TODO: Add your initialization code here

            base.Initialize();
        }

        public void add(Obj o)
        {
            lib.Add(o);
        }

        /// <summary>
        /// Allows the game component to update itself.
        /// </summary>
        /// <param name="gameTime">Provides a snapshot of timing values.</param>
        public override void Update(GameTime gameTime)
        {
            // TODO: Add your update code here
            if (lib.Count > 0)
            {
                foreach (Obj o in lib)
                {
                    o.Update(gameTime);
                    if (isCleared)
                    {
                        isCleared = false;
                        break;
                    }
                }
            }
            base.Update(gameTime);
        }

        public List<Obj> objectsOfType(Type t)
        {
            List<Obj> list = new List<Obj>();
            foreach (Obj o in lib)
            {
                if (o.GetType().Equals(t))
                {
                    list.Add(o);
                }
            }
            return list;
        }

        public void Clear()
        {
            lib.Clear();
            isCleared = true;
        }

        public void drawAll(SpriteBatch sb)
        {
            foreach (Obj o in lib)
            {
                o.Draw(sb);
            }
        }
    }
}
