#include "GameObject.h"
#include "GameObjectList.h"
#include "GameObjectListIterator.h"
#include "LogManager.h"

GameObjectList::GameObjectList(){
	for(int i=0;i<MAX_GAME_OBJECTS;i++){
		this->list[i]=NULL;
		this->count=0;
	}
}
GameObjectList::~GameObjectList(){}


GameObjectListIterator GameObjectList::createIterator() const{
	return GameObjectListIterator(&GameObjectList());
}

int GameObjectList::insert(GameObject *p_go){
	for(int i=0;i<MAX_GAME_OBJECTS;i++){
		if(this->list[i]==NULL){
			p_go->setId(i);
			this->list[i]=p_go;
			this->count++;
			return i;
		}
	}
	return -1;
}
int GameObjectList::remove(GameObject *p_go){
	for(int i=0;i<MAX_GAME_OBJECTS;i++){
		if(list[i]==p_go){
			list[i]=NULL;
			//this->count--;
			return i;
		}
	}
	return -1;
}
void GameObjectList::clear(){
	for(int i=0;i<MAX_GAME_OBJECTS;i++){
		this->list[i]=NULL;
		this->count=0;
	}
}
GameObject* GameObjectList::find(int id){
	for(int i=0;i<MAX_GAME_OBJECTS;i++){
		if(this->list[i]->getId()==id){
			return list[i];
		}
	}
	return NULL;
}

GameObject* GameObjectList::getAt(int index){
	return this->list[index];
}

void GameObjectList::setAt(GameObject* go,int index){
	this->list[index]=go;
}

void GameObjectList::printObjects(){
	for(int i=0;i<MAX_GAME_OBJECTS;i++){
		if(list[i]!=NULL){
			LogManager::getInstance().writeLog("The type of object %d is: %s\n",i,list[i]->getType().c_str());
		}
	}
	//LogManager::getInstance().writeLog("The type of object %d is: %s\n",0,list[0]->getType().c_str());
}