Unfortunately I'm not familiar with SFML, but I'm very familiar with the SDL, and I'm assuming it's similar. The first thing to keep in mind: you may not want your internal representation of the inventory to be the same as the graphical representation.
Here's what I mean. A linked list is just a data structure (the other most common one being a vector/dynamic array). It holds a list of elements; that's it. Maybe that's a good choice for representing the objects the player has in their inventory. However, when you're displaying the inventory you need to keep track of (e.g.) row and column positions and convert those into pixels and then actually display the objects' images. There's no reason the position-information has to be stored in the actual "inventory" list. You could auto-generate it. Pseudo-code:
Code:
row = 0, col = 0
for each inventory item i:
col ++
if(col >= NUMBER_OF_COLUMNS) row ++, col = 0
x = 100 + col*10 // or whatever. Convert to pixels
y = 200 + row*10
drawImage(image for object i, x, y)
As for data structures themselves. Well, you could make your own linked list or vector if you wanted to, but you should be aware that the standard C++ library already has std::list (a linked list) and std::vector (a dynamic array)! Of the two, I suggest std::vector because it's easier to index elements in it -- and the efficiency differences don't matter if you have small data structures.
Code:
#include <vector>
std::list<vector> data;
data.push_back(1);
data.push_back(2);
data.push_back(3);
for(int x = 0; x < int(data.size()); x ++) {
std::cout << data[x] << std::endl;
}
If you have using namespace std you can drop my std:: prefixes. Notice that I casted data.size() to type int; its return value is actually of type std::vector<int>::size_type, which is unsigned, so you'll get signed/unsigned warnings if you have warnings enabled. (You do have warnings enabled, right? For g++: add -Wall -Wextra to your compiler options.) Basically if you care about the warning, you can cast the return value or use
Code:
for(std::vector<int>::size_type x = 0; x < data.size(); x ++)
Quite a mouthful. Looks better with typedefs.
If you really really wanted to, you could implement your own linked list. But seriously, there's no reason for it unless you specifically want to learn how linked lists work. That's useful in itself but if you just want the data structure for use somewhere else, it's *way* easier to use the builtin ones. There's always some bug you miss if you implement it yourself.
I've talked about the data structure but haven't said anything about inventory items themselves. Obviously you probably won't want to use an int. The simplest possible solution is probably this:
Code:
enum ItemType {
ITEM_SWORD,
ITEM_MAGIC_KEY,
// ...
};
struct InventoryItem {
ItemType type;
std::string imagePath;
};
std::vector<InventoryItem> inventory;
InventoryItem sword;
sword.type = ITEM_SWORD;
sword.path = "sword.png";
An enum is basically names for 0, 1, 2, etc. You can use a string if you prefer. If you want to make that more complicated you could use a class.
Also, you may have noticed that the image-name to use is also display-information, which can be separated from the actual inventory objects themselves. So you could just have inventory objects contain a certain type, and then e.g. an array to map types to images...
Code:
std::string files[] = {
"sword.png",
"magickey.png",
// ...
};
paint(files[ITEM_SWORD]);
But I digress. In fact, I think I began digressing about ten percent of the way through this post. Anyway, hope some of it is useful.