Hardware Reference
In-Depth Information
then the f.readlines() will return a list that looks like this:
['line one', 'line two', 'line three']
There is a second point in your program where you used another Python list but
might not have realised it. It was in this line:
data = line.split(",")
The line variable holds a string of text that is the complete line read from the
CSV file. All string variables have a built-in function called split() that will
take that string and split it into a list. The "," inside the brackets tells the split
function which character to split on.
Imagine you have a line variable with three words separated by commas like
this:
line = "one,two,three"
data = line.split(",")
The result of this will be that the data variable will contain a list with three
items in it, like this:
['one','two','three']
CHALLENGE
Design your own maze files in other CSV data files with lots of winding pas-
sages, dead ends and loops to make the mazes hard to solve. Challenge your
friends to find their way through the maze. You might want to plant some ran-
dom treasure (e.g. DIAMOND_BLOCK ) throughout the maze and at the exit so
that your friends can prove they have walked through the whole maze, or even
build a huge maze that takes up most of the Minecraft world! How could you
store the positions of the treasure in the maze file?
When I was designing the programs for this chapter, I had to modify the maze
program slightly as sometimes it was very hard to solve. For example, what
happens if you remove the line from the program that builds the floor? Try building
the walls with some other block types, such as CACTUS or WATER_FLOWING
and see what happens. I went through many versions of this program before
finding block types that I was happy with for the walls and the floor!
 
Search WWH ::




Custom Search