using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;

namespace SpaceWinnie
{
	public class ObjectCollection
	{
		List<GameObject> objects = new List<GameObject> ();
		Random rand = new Random ( Environment.TickCount );
		Game game;

		public ObjectCollection ( Main game )
		{
			this.game = game;
		}

		public void Add ()
		{
			int t = rand.Next ( -1, 2 );
			float z = 0;
			if ( objects.Count > 0 )
				z = objects [ objects.Count - 1 ].z;
			for ( int i = -1; i <= 1; i++ )
			{
				if ( i == t ) 
				{
					if ( rand.Next ( 0, 5 ) == 3 )
						objects.Add ( new Item ( game as Main, ( ItemType ) rand.Next ( 0, 5 ), i * 1.5f, z - 15 ) );
					continue; 
				}
				objects.Add ( new Stone ( game as Main, i * 1.5f, z - 15 ) );
			}
		}

		public void Update ( GameTime gameTime )
		{
			if ( GameObject.accel < 1f )
				GameObject.accel += GameObject.accel * 0.005f;

			if ( objects.Count / 2 < 10 )
				Add ();

			foreach ( GameObject stone in objects )
			{
				stone.Update ( gameTime );
			}

			int len = objects.Count;
			for ( int i = 0; i < len; i++ )
			{
				if ( objects [ 0 ].z > 2 )
					objects.Remove ( objects [ 0 ] );
			}
		}

		public void Draw ( GameTime gameTime )
		{
			foreach ( GameObject stone in objects )
			{
				stone.Draw ( gameTime );
			}
		}
	}
}
