For just a score variable, it's probably not a big deal to
have an = 0 in there twice as duplicate code, but games are
complicated and so I'm sure you've got lots of other fields as
well, and that's where the duplication becomes problematic,
especially if it's just there to appease the linter. I'm
assuming the Game object is sort of an application context
that survives the entire duration of the program's runtime,
and that aside from score, you have a variety of other fields
as well that need to be reset. For things like this, I would
split game into a 2-tiered object, where each object has the
desired lifespan. Something like this...
class ApplicationContext:
def __init__(self):
self.session =
GameSession()
def reset(self):
self.session =
GameSession()
def __init__(self):
self.score = 0
self.player_location
= (0, 0)
self.zombies =
self.build_zombie_list()
self.im_just_making_up_examples = etc
Nope, this doesn't solve your fundamental problem of
getting rid of a duplicate assignment, but it does group
things with identical lifecycles so that the duplication is
always limited to just the single 'session' field no matter
how complicated your game becomes.