Trying a Thing
Hello, loves!
I’d like to make the KeyPress code simpler. Here’s something that works. Do we like it? Yes, but we don’t love it. Tout le monde déteste l’IA.
Here’s the KeyPress code for D:
class KeyPress:
elif symbol == arcade.key.D:
more = self.stepper.step()
maker = DungeonViewMaker(self.dungeon)
maker.update(self.view)
if not more:
self.dungeon.run()
Here’s what I want: Wishful Thinking:
elif symbol == arcade.key.D:
more = self.stepper.step(self.view)
if not more:
self.dungeon.run()
Here’s how I changed the stepper:
class BuildStepper:
def __init__(self, table, layout, dungeon ):
self.table = table
self.index = 0
self.layout = layout
self.dungeon = dungeon
def step(self, view=None):
if self._more_to_do():
self._do_one_step(view)
return self._more_to_do()
def _more_to_do(self):
return self.index < len(self.table)
def _do_one_step(self, view):
self.table[self.index](self.dungeon, self.layout)
if view:
maker = DungeonViewMaker(self.dungeon)
maker.update(view)
self.index += 1
The game works as intended. Three tests are failing. They just needed a bit of rewiring. Let’s commit this.
Reflection
To make this work, I moved creation of the KeyPress object into DungeonView.run(), passing in the stepper. I’m not entirely comfortable with that, but the real issue might be that we create the view in the DUngeonView’s __init__ method.
I like this in that now the KeyPress doesn’t really know what’s going on. I do not like it in that the BuildStepper knows about the DungeonViewMaker, but maybe that’s OK because it’s not a generic object for executing things in order, it’s a specialized one. If we wanted a generalized one we might extract it and provide it with an inner bit, or we might make the DungeonViewMaker be the outer bit.
One other option comes to mind: Maybe THe DungeonViewMaker isn’t really a view maker at all but instead is a maker of the KeyedSpriteList, which is all we use to update the old view from the new.
Tentative conclusion as of now: these objects aren’t quite dividing up the responsibilities correctly. We’ll think about that and see what is to be done next time. For now, we have stepping quite nicely encapsulated.
See you next time!