I am new to programming and mostly self-taught by following a few MOOCs and doing little projects. I have reached the point where I am trying to develop more complicated programs (numerical models at work and games at home) and I would like to be able to give a structure to my programs to enhance readability.
I am following an Edx course called Systematic Program Design which offers methods on how to design functions, data and world in a consistent manner.
However, I have come to notice that the method seems to work mostly with functional programs rather than the object-oriented(ish) code I tend to write (especially for games). This course made me aware that my code was full of methods with almost exclusively side effects changing attributes. Which makes it hard to follow the method and makes the code look really chunky. I was wondering if anyone knows of a course/book on how to increase readability of OO code. I use Python 2.7.1.
As I said, I am self-taught, so I apologies if the answer seems trivial to some of you who have done CS.
The github link to my game is Far and Away v1
And this is the picture of my . The idea is that every object in the game has a game attribute linked to the Game() object which I use as a waypoint to access all objects in my game whilst keeping them in separate files.
To give you an example of what my code looks like and why I would like to have a method to improve it, here is one method of a game I've made:
#Displays the map of planets and handles user interaction with the map def view_solarsys(self,offset): planets_to_blit =  #checks for discovered planets and draws lines between them #as well as creating a list with them, that will be blitted to the screen for p in self.game.all_planets: if self.game.player.logbook[p.name].is_discovered == True: [pygame.draw.line(self.screen, (0,250,0), p.pos, p2.pos, 5) for p2 in p.planets_in_SOF if self.game.player.logbook[p2.name].is_explored and self.game.player.logbook[p.name].is_explored] planets_to_blit.append(p) #if mouse is over planet, the hoovered attribute is updated to the planet instance if p.rect.collidepoint(pygame.mouse.get_pos()) : self.hoovered = p #Blits discovered planets to screen. If they are not explored blits a red halo around them as well. If the player's location is on the planet blits a green halo around it. for p in planets_to_blit: if self.game.player.logbook[p.name].is_discovered == True: if self.game.player.logbook[p.name].is_explored == False: pygame.draw.circle(self.screen, (255,0,0), p.pos, int(p.rect.w*0.6), 0) if self.game.player.location == p.name: pygame.draw.circle(self.screen, (0,255,0), p.pos, int(p.rect.w*0.75), 0) fn.blitc(self.screen, Data.images_planets[p.img_ref], p.pos) '''Mouse interaction''' if p.rect.collidepoint(pygame.mouse.get_pos()) and self.game.map_active: if pygame.mouse.get_pressed(): if self.game.player.logbook[p.name].is_explored == False: p.explore(self.game.player) else: p.visit(self.game.player) elif pygame.mouse.get_pressed() and self.game.pressed_right_clic == True: p.search_in_SOF(self.game.player,True,30) self.game.pressed_right_clic = False '''blitting planet info of hoovered planet''' self.view_planet()