Hardware Reference
In-Depth Information
continued
This means that if you have a list with anything in it, you can loop through all the
items in the list in the same way. Try this at the Python Shell:
for name in ["David", "Gail", "Janet", "Peter"]:
print("hello " + name)
You can also loop through the characters of a text string like this:
name = "David"
for ch in name:
print(ch)
Writing a Treasure Hunt Game
For most of this adventure, you have been learning skills and building snippets of
program code to test out and experiment with various sensing features in Minecraft.
It's now time for you to knit all of that code together into a complete game. The game
you are going to write is called “Sky Hunt”, a treasure hunt in which you have to find
diamond blocks hanging randomly in the sky using a homing beacon, and hit them to
get points.
There is a twist to this game though: every time you move forward you leave a trail of
gold, and this costs you one point off your score per gold block. If you run around
aimlessly looking for the treasure, your score will rapidly decrease and even become
negative! You will have to use your Minecraft navigation skills to look for the dia-
mond blocks quickly, and try to get to them in as few moves as possible.
When you find each piece of treasure you score points, and the trail of gold magically
melts away (possibly leaving holes in the ground for you to trip over, so watch out!).
This program is mostly made up of reusable parts from all the other little experimental
programs you have already written in this adventure. You can cut and paste bits of
your other programs and modify them to save typing time if you wish. But I have
included the full program here to make sure you know what is needed.
Professional software engineers often start with a simple framework program built
with just print statements and test this first to make sure the structure is correct, and
then add and test new features to it gradually. In this section, you are also going to be
a real software engineer, and write and test this program in steps. First, let's get the
framework of the game loop in, and some dummy functions that you can flesh out as
you go along.
 
Search WWH ::




Custom Search