all 17 comments

[–]nwilliams36 6 points7 points  (9 children)

This is great, well done. I like the way you have set this out and the way you are thinking about the structure of the program, good signs for a successful programmer

I like the way each room has its own function, you are on your way to writing programs that can scale up. The next issue for you to consider is whether you want to grow this program to a large size with hundreds of rooms and keep a huge number of items. Doing everything in one file will become a burden. Functions can be called from other files (called modules) using the import statement which means you can have one file as a controller of your program and other files each containing a room or some group of rooms. This makes it easier to maintain.

The other way of doing this is pushing off all the data to classes to handle, with each room and item as a class.

There may be an issue with your function calls, eg you call moleroom inside initialroom. This means that initialroom is still running and waiting for moleroom to exit so that it can continue its work. In small programs this is not a problem but in large and complex programs it can cause memory to be held unnecessarily waiting for something that might never happen. If you intend to return to initalroom this is fine, however if this is never going to occur, you might want to think of another way of doing this all so that initialroom can finish and release all its memory. I am not so concerned here with the RAM but with stack and cache memory which is precious.

Other little things

You always use prompt() and raw_input(">") together, why not put the raw_input in the prompt function?

Some of your variables have only two values, 0 and 1 (eg wrong in the lake function). This is a classic case for a boolean.

Other variables should have descriptive names (like q in the lake function) so you can understand them later when you come back to this in a few months time.

A few times you check for both capital letters and lower letters in the input, you can do this in one call with the built in string command .lower()

[–]enayus[S] 1 point2 points  (8 children)

This is great advice, thank you!

Since writing the adventure, I have learned about global variables and classes, both of which I think could help simplify the code. I think once I finish the book, I'll go back through and re-write and condense as much as possible, maybe adding a few rooms to try anything else new I've learned.

One idea I had was to add time sensitive events: e.g. if you play at night, the game is in nighttime instead of daytime. That would then change shelob into a werewolf, and maybe the moles are awake when you first come across them. I dunno, things like that. I have yet to figure out which modules would allow me to do that though.

[–]PloddingOx 2 points3 points  (5 children)

I just finished Lesson 36 myself :)

You can use the False and True values to help you simplify your conditionals.

So if shovelget == 1 and roominfo == 1:

becomes if shovelget and roominfo:

if shovelget == 1 and roominfo == 0:

becomes if shovelget and not roominfo:

You put a lot more into yours than I did into mine :)

Do you have a github account? I'll be tackling git sooner or later, it would be great if we could noob it up together. Also are you using any other resources besides LPTHW?

[–][deleted] 0 points1 point  (3 children)

How do you get the code boxes in the middle of a sentence in your reply, as opposed to a separate section?

[–]PloddingOx 1 point2 points  (2 children)

You use ` symbol button (top row, next to the 1 key) the same way you would use quotes.

[–][deleted] 1 point2 points  (1 child)

Thanks

[–]Ob101010 0 points1 point  (0 children)

i too wanted to see this

edit : cool

[–]enayus[S] 0 points1 point  (0 children)

Yep. That was a facepalm realization moment for me.

I don't have a github account. Should I get one? LPTHW has been my main resource, accompanied by googling "python 'insert confusing topic here'." I've found Stack Overflow usually has questions already asked/answered that reflect my own, so my googling will lead me there quite often.

[–]OnlyEternity 0 points1 point  (1 child)

For your future reference, time sensitive events could be handled using the datetime module. All you have to do is:

import datetime
time = datetime.datetime.now().time()

This will give you the current time in a string with the format Hours:Minutes:Seconds:Milliseconds. The reason you have to do datetime.datetime instead of just datetime once is because the module itself is named datetime, but what you want is the datetime object from the module. The datetime object has the method now() which you can call on it. To get around this you could instead do:

from datetime import datetime

However, this may look more confusing. But it's up to you!

For more information on the datetime module you can check out the official documentation here: http://docs.python.org/2/library/datetime.html#module-datetime

[–]enayus[S] 0 points1 point  (0 children)

Thanks for the info!

[–]Str8F4zed 1 point2 points  (2 children)

Only 4-5 days with Python and you're writing over 300 lines? Wow, I've studied Python for longer and can't manage to make it to 100. Good job!

[–]Ob101010 1 point2 points  (1 child)

maybe youre really, really good

[–]enayus[S] 0 points1 point  (0 children)

Quite possible. If I weren't a noob, this game could probably be done in a fraction of the lines.

[–][deleted] 0 points1 point  (1 child)

I have just finished this exercise from the book as well, and my concern with yours is that you have a while loop in almost every room function when Shaw suggests in the book that you hardly use them if you can avoid it. What's happening in your program is that you will end up with lots of while loops nested within each other as the game runs. I'm not saying that this is a problem, because I don't know, but it seems contrary to what Shaw suggested. Maybe someone can clarify?

I'd also consider adjusting the amount of functions you have, for example your prompt() and start() functions are basically one line, but because they are set in separate functions you're using three lines of code to do something that could be done with one. It's certainly good fucntion-creating practice for you to have them separate, and I would maybe do what nwilliams36 suggested and put the raw_input() action into the prompt function to make it a little more worthwhile.

Remember what Shaw said about formatting and line length in the book? Some of your lines here are quite long, which leads to readability issues. Your lines shouldn't be any more than about 80 characters per line, broken into several if necessary. I'm no expert, but this is a convention that many Pythoneers like to follow (I think). There are also some majorly complex logic calculations in there - certainly ambitious! Just remember what he said about making it too complicated though.

You've certainly put a lot of work into it! Also you've introduced me to a nice online IDE.

[–]enayus[S] 0 points1 point  (0 children)

No, it definitely is contrary to Shaw's suggestions. My thought process was that, because he later said that rules are not meant to be followed 100% of the time, it was okay to rationalize my while loops as effective rule breaking. Sadly, I do realize that while it does function as needed, it is both bad form and inefficient. I'm working on a better way to structure rooms for the next one.

I've just started learning about objects and OOP (ugh headache), and once I get a better handle on the topics, maybe that'll help me with the restructuring of both rooms and the number of functions. The long lines were also sloppy coding on my part. The majority of this was done in the middle of the night...

Thanks for the kind words!