Just finished this exercise for Learn Python The Hard Way and thought I'd put it up to see what people think. You can grab the PDF from the site if you want to see what Exercise 35 is like. Basically they make an Adventure game and in this one they make a bigger one on their own.
I'm going to give you some rules now that you know if-statements,
for-loops, and while-loops that will keep you out of trouble. I'm
also going to give you some tips on debugging so that you can figure out
problems with your program. Finally, you're going to design a similar
little game as in the last exercise but with a slight twist.
if-statement must have an else.else should never be run, because it doesn't
make sense, then you must use a die function in the else that
prints out an error message and exits, just like we did in
the last exercise. This will find many errors.if-statements more than 2 deep and always try
to do them 1 deep. This means if you put an if in an if
then you should be looking to move that second if into
another function.if-statements like paragraphs, where each if,elif,else
grouping is like a set of sentences. Put blank lines before and
after them.If you follow these simple rules you will start writing better code than most programmers currently coding. Go back to the last exercise and see if I followed all of these rules. If not, fix it.
while-loop only to loop forever, and that means probably
never. This only applies to Python, other languages are different.for-loop for all other kinds of looping, especially if
there is a fixed or limited number of things to loop over.print to print
out the values of variables at points in the program to see
where they go wrong.You should now write a similar game to the one that I created in the last exercise. It can be any kind of game you want in the same flavor, and you should spend a week on it making it as interesting as you can. For extra credit, you should use lists, functions, and modules (remember those?) as much as possible, and find as many new pieces of Python as you can to make the game work.
There is one catch though, you should write up your idea for the game first. Before you start coding you must write up a map for your game. Create the rooms, the monsters, and the traps that the player must go through on paper before you code.
Once you have your map, then you should try to code it up. If you find problems with the map then adjust it and make the code match.
One final word of advice: Every programmer becomes paralyzed by irrational fear at starting out on a new large project. They then use procrastination to avoid confronting this fear and end up not getting their program working or even started. I do this. Everyone does this. The best way to get rid of this is to make a list of things you should do, and then do them one at a time, bit by bit.
Just start doing it, do a small version, make it bigger, keep a list of things to do, and do them.