Ex. 36 - maybe needs rework?

Hello forumers!
Never tried programming, but recently tried to learn python the hard way.

Spent some days doing homework for ex.36

On the one hand project works and I can finish the game, on the other hand I have a couple of points that are not obvious to me:

  1. First I’ve tried to make cycles for room using while, but realized that in some conditions that might render the scene unpassable. Is it ok that I pushed variable to global in order to be able to change it from inside def?
  2. Is there a better way of doing the check for (in)correct input besides using def moebius as I did?

Code might be too long, so I zipped files and put them here:
[7z link removed]

Looking forward for your comments.

Regards.

Although it’s probably innocent, you might find some reluctance to opened a zipped file off a public forum. Is the code available in a repo like GitHub?

Although it’s probably innocent, you might find some reluctance to opened a zipped file off a public forum. Is the code available in a repo like GitHub?

Hope I did it right:

Hey @Batrachotomus thanks for putting this in github instead of a 7z. You’ll understand if we avoid clicking on links to files like that.

I took a quick look at your code and it’s looking nice. I like how you use the global invader_fed to keep track of state.

I’d definitely try using a global for other state. In fact you could just make a single STATE dict and keep all the information you need for the game in there. Try that.

The only way to get rid of that moebius function is to create a separate “runner”. Something like this (pseudo code, won’t work):

next_room = rooms.start()
while next:
    next_room = next_room()

Then in your room you do this:

return moebius  # <--- don't () to call it, just return it

You can pass function names around like variables and then call them later, so you just have to not call them and let your little runner do it.

Try it. Otherwise if you want that content printed out then you’ll have to do it somewhere, but this should give you a clue about where.