hello all,
hope this finds you well. monopoly development for the most part is going very smoothly i've learned a lot about a lot of things throughout the whole process. but i came across some interesting behavior and wanted to get it out here and see if anyone had anything to say about it. i've developed what is called a state programming pattern or a state machine in my game. for those of you that don't know what that is: everything in the game is a screen and the game cycles through the screens as needed. i'm holding the screens in the game stack. only the top screen (list[-1]) gets the focus at one point. i don't really see any need for keyboard import to trickle down the stack to other screens at the moment but i'm using this because its a good model for games and i can easily add to my understanding of this if i create something more complex in the future. all that beeing said, my function for switching screens is buggy. adding screens is working amazingly well. the issue comes in when i need to remove more than one screen off the stack at a time. this isn't copied code for code below, but i hope you get the general gist and can help me flush out some better practices out of this. the underlying engine for how the game runs needs to be super solid and its not at the moment.
each screen returns a string which the engine uses to look up the next screen in a dictionary.
def screen-switcher(self):
self.next_screen = self.screen_dict[self.next_screen]
#looks up screen in dict
if self.next_screen in self.stack:
#seeing if screen obj is already in the stack
for screen in reversed(self.stack):
if self.stack.index(self.next_screen) != -1:
try:
app.remove_from_stack(screen)
#i want it to remove screens until the specified screen is on top
except ValueError:
app.add_to_stack(screen)
else:
app.add_to_stack(self.next_screen)
#if screen isn't in the stack already, it just gets added
this seems to be mostly doing what i want it to do. but it doesn't seem to be catching the value error that the screen was removed. any help making this more solid would be appreciated.