Here's the class tile list that contains the head pointer, that links all of the nodes.
class TileList
{
public:
TileList(Tile* newHead = nullptr);
~TileList();
Tile* getHead();
void setHead(Tile* newHead);
void insertAtFront();
void AssignTilePos();
private:
Tile* pHead;
};
TileList::TileList(Tile* newHead)
{
this->pHead = newHead;
}
TileList::~TileList()
{
//Add deconstrcutor here
}
Tile* TileList::getHead()
{
return this->pHead;
}
void TileList::setHead(Tile* newHead)
{
this->pHead = newHead;
}
void TileList::insertAtFront()
{
Tile* pMem = new Tile;
if (pMem != nullptr)
{
if (this->pHead != nullptr)
{
pMem->setNext(this->pHead);
this->pHead->setPrev(pMem);
}
this->pHead = pMem;
}
}
void TileList::AssignTilePos()
{
// assigning the top
if (this->pHead->getY() != 0) // if it doesn't equal zero then there is a tile above it
{
}
}
Here's the Minefield that calls upon it.
class Minefield
{
public:
Minefield();
~Minefield();
void displayBoard(sf::RenderWindow& window);
private:
TileList boardList;
};
Minefield::Minefield()
{
float rowSlot = 0, colSlot = 0;
for (int index1 = 0; index1 < 10; ++index1)
{
for (int index2 = 0; index2 < 10; ++index2)
{
this->boardList.insertAtFront();
this->boardList.getHead()->setX(colSlot);
this->boardList.getHead()->setY(rowSlot);
this->boardList.getHead()->setSpritePos(colSlot, rowSlot);
cout << "(" << colSlot << "," << rowSlot << ")" << endl;
colSlot = colSlot + 16;
}
colSlot = 0;
rowSlot = rowSlot + 16;
}
}
Minefield::~Minefield()
{
}
void Minefield::displayBoard(sf::RenderWindow& window)
{
Tile* tileCur = this->boardList.getHead();
while (tileCur != nullptr)
{
window.draw(tileCur->getSprite());
tileCur = tileCur->getNext();
}
}
It's now working sometimes, it sometimes crashes and sometimes doesn't...