Currently, it's basically those examples I mentioned, because I know how to make the hero move and how to generate a dungeon (classical terminal output). It's how to make him interact within the dungeon and its objects.
Moreover I don't want to simply implement something, but also understand why and how it is working.
Alright, well the best way to handle that depends on what you want to do. If your game is pretty simple and tiles don't do anything too wacky, you could make a two dimensional array for each floor, with the array's dimensions being the maximum width and the maximum height of a floor in your game. Something like this:
int tile[MAX_SIZE_X][MAX_SIZE_Y];
or if you wanted persistent floors, maybe this instead:
int tile[MAX_FLOORS][MAX_SIZE_X][MAX_SIZE_Y];
Then elsewhere you'd have constant values for each type of tile in your dungeon. Maybe EMPTY_FLOOR is 0, WALL is 1, OPEN_DOOR is 2, CLOSED_DOOR is 3, etc.
So let's say that the player/a monster/whatever uses the open command on coordinate 12,16, which is a closed door. Your function might look something like this:
bool openDoor(int targetX,int targetY) {
// If the action is unsuccessful, this should not consume the actor's turn. If it's a monster, their AI needs to select a different action.
// If it's the player, we can display a message about how they tried to open a wall or whatever.
bool actionSuccessful;
// If the tile is a closed door, we allow the actor to open it
if(tile[targetX][targetY] == CLOSED_DOOR) {
tile[targetX][targetY] = OPEN_DOOR;
actionSuccessful = true;
} else {
actionSuccessful = false;
}
return actionSuccessful;
}
So the game will see that the value stored in tile[12][16] is 3, because that is the value we have associated with closed doors. It will check whether that value matches the value for closed doors, and since it does, the game will change the value of tile[12][16] to 2, because that is the value we have associated with open doors. Then it will set actionSuccessful to true and return the value of true so that the function that called this one will know that the door-opening attempt succeeded.
Maybe you'd want to add additional bits to check whether the actor in question is capable of opening doors at all, but you get the idea.
If you want your tiles to be more complex or more varied, making each tile an object would be a better idea. That way each tile can have an "openable" variable, and your open door function will check for that instead. Then you can have the function work for multiple door types without having to resort to this:
if(tileType == CLOSED_STONE_DOOR || tileType == CLOSED_WOODEN_DOOR || tileType == CLOSED_METAL_DOOR) {
// Do whatever
}
instead you'd do
if(tile[targetX][targetY].openable == true) {
// Do whatever
}
And then it'd be easy to give every tile the properties you want. The burnable variable for wooden doors is set to true, but for metal doors it's false. You could make the wooden door a member of the wooden tiles class, which is a subclass of tiles where burnable is always set to true. Or you could have a variable for a tile's material and set it to equal a WOOD constant, which would mean the tile is burnable, and breakable if your character has enough attack power, and so forth.
If every wooden door is identical to every other wooden door (like, you can't carve anything into them and you can't partially damage them without breaking them or whatever), then another possibility is to combine the two implementations I've suggested above. Make one object in the tiles class for each type of tile in the game. So one object for empty floors, one object for stone walls, etc. Then assign a constant number to each tile type.
That will allow you to make an array of integers for each tile in the game, and the value stored in the array is the number associated with the appropriate tile type. So if the constant value for EMPTY_FLOOR is 0 and the tile at 25,19 is an empty floor, you'd set tile[25][19] to 0 and then whenever anything in the game needs to interact with 25,19, it'd look up its value in the array, see that its value is 0, and thus it is an empty floor, and from that point on the game would read whatever information it needs from the empty floor object's variables.
Does that make sense? Is it the sort of thing you're looking for help with?
I'm sure there are people here who are much better at programming than I am. If someone posts that I'm the worst coder of all time and my example code makes them want to gouge their eyes out, they're probably right and you should use their suggestions instead.