Hardware Reference
In-Depth Information
1. Save your buildStreet.py with File Save As from the menu, and call it
buildStreet2.py .
2. Add this import statement at the top of the program to gain access to the ran-
dom number generator:
import random
3. Change your house() function so that it generates a random carpet colour each
time it is used. As WOOL can have an extra data value ranging between 0 and 15,
that is the range of random numbers you need to generate. Store the random
number in a variable called c so that the carpet-building line doesn't become too
long and hard to read, and make sure that both of these lines are indented cor-
rectly, as they are both part of the house() function:
c = random.randint(0, 15)
mc.setBlocks(x+1, y+1, z+1, x+SIZE-1, y+1, z+SIZE-1,
block.WOOL.id, c)
4. Save your program.
Now you need to find somewhere in your Minecraft world that has plenty of space to
build more houses! Move around the world and find somewhere to build, then run
your new program. It should generate another street of houses but this time, when
your player explores inside the houses, the carpet in each house should be a different,
random colour. See Figure 3-8 to see what these new houses look like, but your player
will need to actually go into each house and look at the carpets so that you can check
they are indeed all different!
FIGURE.3-8 Each house has a random carpet colour.
Search WWH ::




Custom Search