Hardware Reference
In-Depth Information
Writing the.Functions and
the.Main.Game Loop
1. Start a new file with File New File from the menu. Save it with File Save As
and call it skyHunt.py .
2. Import the necessary modules:
import mcpi.minecraft as minecraft
import mcpi.block as block
import time
import random
3. Connect to the Minecraft game:
mc = minecraft.Minecraft.create()
4. Set a score variable that will keep track of your score as the game plays. You will
also use a RANGE constant to set how difficult the game is, by setting how far
away from the player the random treasure is placed. Set this to a small number
to start with, while you are testing, and make the number bigger later on when
your program is completed:
score = 0
RANGE = 5
5. As you are going to develop and test this program in steps, first write some
dummy functions for each of the features of the program. Python functions
need at least one statement in them, so you can use the Python print state-
ment here to print a message. This just acts as a placeholder for code you will
write later:
treasure_x = None # the x-coordinate of the treasure
def placeTreasure():
print("placeTreasure")
def checkHit():
print("checkHit")
def homingBeacon():
print("homingBeacon")
bridge = []
def buildBridge():
print("buildBridge")
 
 
Search WWH ::




Custom Search