+ 2
Game Map for Goblin Game - Python
I’m only 2 weeks into Python and loving it. I was looking to extend the Goblin Game and wanted to create a map that held the contents of a given tile eg at (1,1) store two goblins and a chest. I think I have achieved what I intended with nested dictionaries (the code attached) but wondered how other, more experienced, coders would go about it https://code.sololearn.com/c07iXRMNu4a4/?ref=app
7 ответов
0
Oh I see.
Look forward to playing your game.
+ 2
You are welcome.
You can make your GameMap class accepts some parameter at construction, such as width and height. Store them with the self keyword to make them property of the created instance.
0
Why not creating an instance of GameMap class to use it?
Because when you enter a town from world map, you need a different map instance.
For GUI, I think you can use PyGame. But of course, you can also use Tkinter or sfml
https://www.pygame.org/wiki/GettingStarted
https://www.sfml-dev.org/tutorials/2.5/
https://docs.python.org/3/library/tkinter.html
Good luck with your Game Development.
0
thanks Gordon . I had assumed only one map hence i hadnt bothered instantiating it, but you make a good point about multiple maps
0
I just perused the script, please don't mind if I make a few points :
Currently, your usage :
GameMap.set_tile(1,1,"Goblin","Gobbly")
GameMap.set_tile(1,1,"Elf","Elfie")
storing
tile[1][1] = {
"Goblin" : "Gobbly",
"Elf" : "Elfie",
}
is a bit counterintuitive. Do you intend to have two character in one tile?
In my understanding (Sorry my imagination is limited, if you do the above intentionally, ignore what I say below), a tile should store information like this:
{
"landscape" : "plain", #compared to "forest", "dessert", "swampland"
"occupied" : True, #a boolean, to avoid funny thing when type coercion occurs
"character" : "Goblin", #compared to "Elf", "Knight", "Mage", if no character None (not string, the type None)
}
0
Gordon i never mind people making points! in this case I would allow multiple characters on a single tile (a tile is just a map location really). i would also store the actual goblin object in reality i think, rather then text. ps i like the bit about the landscape descriptior.
0
Have updated the map code based on a couple of things you said.
https://code.sololearn.com/c07iXRMNu4a4
The full (work in progress) "game" is here. I just keep extending it to test the limits of what I've learnt rather that to achieve completion! ;o)
https://code.sololearn.com/ccfk34KcwU55