+ 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

15th Feb 2020, 8:46 AM
Neil Walker
Neil Walker - avatar
7 Antworten
0
Oh I see. Look forward to playing your game.
15th Feb 2020, 9:33 AM
Gordon
Gordon - avatar
+ 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.
15th Feb 2020, 9:08 AM
Gordon
Gordon - avatar
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.
15th Feb 2020, 8:58 AM
Gordon
Gordon - avatar
0
thanks Gordon . I had assumed only one map hence i hadnt bothered instantiating it, but you make a good point about multiple maps
15th Feb 2020, 9:05 AM
Neil Walker
Neil Walker - avatar
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) }
15th Feb 2020, 9:15 AM
Gordon
Gordon - avatar
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.
15th Feb 2020, 9:24 AM
Neil Walker
Neil Walker - avatar
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
15th Feb 2020, 3:53 PM
Neil Walker
Neil Walker - avatar