Dark theme

Hopefully you can see that this code is ultimately much easier to keep sensible than that using a whole load of if-else statements. We have a very short loop in start() which keeps looping round moving the player and checking to see what's at the current location.

Hopefully you're also starting to see how you could adapt the code to make it your own. You can add additional meaning to other numbers, so:

friend_number = 5

and...

if (map_data[current_y][current_x] == friend_number):
   friend()

With a new "friend()" function to go with it.

You can edit the map in a text editor (open it up and have a look at it). I created it in Excel by putting a number in a square of cells and saving it as a ".csv" (Comma Separated Variables) file, which is on the drop down list of filetypes when you save an Excel file.

Give it a go adding some new numbers, walls (zeros), and functions; for example, you might like your player to find and collect some treasure, or lose lives in traps!

And with that, you should have made a great start on writing Python. We've covered:

variables
if-else
while loops
functions
lists

There's a bit more to the core language, but not a lot. You've already learned more coding than they needed to land people on the moon! Most of learning to code is then learning the different built in functions and functions supplied by other people. You're now at a very good stage for finding a good set of tutorials on the detail. A good starting point is the W3Schools tutorials. Have fun!

[Home]