18 hours ago · Tech · 0 comments

I’ve had an obvious but seemingly decent idea. Let’s try it. Here’s my cunning plan … Class variable holding current DungeonLayer What we’ll do is provide a class variable on DungeonLayout, current, which we’ll set every time we create a Layout. When we need it in Cell, we’ll fetch it. We’ll work, over time, not to need it, essentially by replacing Cell.whatever by calls to current. That will be the thing we need to let us change out our 112 uses of at one at a time, allowing for incremental refactoring. Of course, in practice, I’ll do them in a few batches, but in Real Life we could take our time. class DungeonLayout: current = None def __init__(self, max_x=10, max_y=10): DungeonLayout.current = self self.cells = dict() for x in range(max_x): for y in range(max_y): self.cells[(x,y)] = Cell(x, y) self.rooms = [] That, of course, continues to pass all the tests. Commit: add and update current class member. Use class variable in Cell It seems to me that we can probably fix cell to use…

No comments yet. Log in to reply on the Fediverse. Comments will appear here.