forked from jaildesigner-jailgames/jaildoctors_dilemma
Añadida la clase item_tracker
This commit is contained in:
67
source/item_tracker.cpp
Normal file
67
source/item_tracker.cpp
Normal file
@@ -0,0 +1,67 @@
|
||||
#include "item_tracker.h"
|
||||
|
||||
// Constructor
|
||||
Item_tracker::Item_tracker()
|
||||
{
|
||||
}
|
||||
|
||||
// Destructor
|
||||
Item_tracker::~Item_tracker()
|
||||
{
|
||||
}
|
||||
|
||||
// Comprueba si el objeto ya ha sido cogido
|
||||
bool Item_tracker::hasBeenPicked(std::string name, SDL_Point pos)
|
||||
{
|
||||
}
|
||||
|
||||
// Añade el objeto a la lista de objetos cogidos
|
||||
void Item_tracker::addItem(std::string name, SDL_Point pos)
|
||||
{
|
||||
// Primero busca si ya hay una entrada con ese nombre
|
||||
const int index = findByName(name);
|
||||
if (index != -1)
|
||||
{
|
||||
}
|
||||
|
||||
// En caso contrario crea la entrada
|
||||
else
|
||||
{
|
||||
item_tracker_t item;
|
||||
item.name = name;
|
||||
item.pos.push_back(pos);
|
||||
list.push_back(item);
|
||||
}
|
||||
}
|
||||
|
||||
// Busca una entrada en la lista por nombre
|
||||
int Item_tracker::findByName(std::string name)
|
||||
{
|
||||
const int c = -1;
|
||||
|
||||
for (int i = 0; i < list.size(); i++)
|
||||
{
|
||||
if (list[i].name == name)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
|
||||
// Busca una entrada en la lista por posición
|
||||
int Item_tracker::findByPos(int index, SDL_Point pos)
|
||||
{
|
||||
const int c = -1;
|
||||
|
||||
for (int i = 0; i < list[index].pos.size(); i++)
|
||||
{
|
||||
if ((list[index].pos[i].x == pos.x) && (list[index].pos[i].y == pos.y))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
Reference in New Issue
Block a user