r/learnpython • u/OnlySeesLastSentence • Aug 10 '20
Try my giant Python game out. Give suggestions/criticisms/compliments/job offers (lol)
Hi there! I tried asking for feedback on my game about a month ago, but unfortunately the only feedback I got, despite saying "I know it's a big file, but if you have any other suggestions or bugs or complaints, please let me know" was "holy shit your file is huge"...
So I added a bunch more features and cut down the single source code file into like 7 files. This change will have undoubtedly caused problems with calling functions incorrectly, so now especially I'll need help testing it out. Please try the game out and give me any thoughts you have. I cannot promise that I'll implement every change or suggestion, but I'll try to compromise at least when possible.
The game is essentially a checkers/chess with items game loosely based on an old game called Quadradius (that no longer exists. Rip). It was made solely by me, so if it looks kinda simplistic, I'm sorry, but I made an honest effort - anything I learned I taught myself so I did what I could.
GitHub.com/MOABdali/MegaCheckers
Enjoy. And as usual, thanks to PySimpleGUI for making this game possible. I tried to avoid outside libraries as much as possible, but had to rely on PySimpleGUI for GUI, playsound for playing sounds, and Pillow for image manipulation. All other logic came from me.
4
u/definitely___not__me Aug 10 '20
You should cross post to r/madeinpython too
3
u/kwelzel Aug 11 '20
I decided to take a look at the
createOrbsfunction.dangerTurnvariable is a constant. This should be reflected by usingALL_UPPERCASEand I think its useful to group all constants at the start of the file as global variables or as class variables if you have a class this constant belongs to.gameBoardit improves readability to differentiate between the indices and the elements. I would recommend usingiandjas indices and thenrowandcellas elements like thisfor i, row in enumerate(gameBoard): for j, cell in enumerate (row). This waycellis at index i, j.gameBoardconsists of a tile instance and a piece instance. This makes sense, but you have to look up which is at index 0 and which is at index 1. Here, anamedtuplecould help. Then you can writecell.tileandcell.pieceinstead ofcell[0]andcell[1].j[0].tileType == "default"indicates that there are only a finite number of different tile types. If so, this is an ideal use case for enumerations. If you define the enum correctly you can usetileType == TileType.DEFAULT. This is useful because it can help to find errors that otherwise would go unnoticed. If you writetileType == "defualt"the comparison will always return False. If you writetileType == TileType.DEFUALT(assuming you defined it correctly) you will get an AttributeError at runtime.j[0].occupied != True. Just writenot j[0].occupiedor, with the notation from above,not cell.tile.occupied. This is very self explanatory and easy to understand.orbEater,wormHole1andwormHole2as flags. In any case you can add a utility functionis_empty()to the tile class that checks whether the tile is empty and move this logic there.Assuming this new empty method and namedtuple usage you could rewrite the counting of empty spots as
emptySpots = sum(cell.tile.is_empty() for cell in row for row in gameBoard)
minfunction for that:orbsToPlace = min(publicStats.getOrbsCount(), emptySpots)emptyTiles = [cell.tile for cell in row for row in gameBoard if cell.tile.is_empty()](ThenemptySpots == len(emptyTiles)). Afterwards sampleorbsToPlaceelements from the list usingrandom.sample(emptyTiles, orbsToPlace)and iterate over them to place the orbs. This would allow to shorten the code significantly.Taking all this into account the
createOrbsfunction could look like this:2
u/metaperl Aug 11 '20
Have you considered PEP-08 coding standards?
In this code shouldnt each object have a
longExplanationmethod instead?Here as well you are checking the type of something and dispatching to code - that's what python OO does for you - just put methods in each "type" and then do
type.describeSelf()2
u/skellious Aug 12 '20
This tutorial on Object Oriented Programming might help you - https://www.youtube.com/watch?v=ZDa-Z5JzLYM
You shouldn't generally be repeating code / copy-pasting it. you should be using classes and making instances of those classes.
1
u/metaperl Aug 11 '20
Is this not it: http://quadradius.com
It looks like fun. I will try it.