Hardware Reference
In-Depth Information
Writing the.Geo-Fence Program
The final step is to write the program that makes the geo-fencing work and charges
rent whenever the player is standing in the field. This program is similar in structure to
the whereAmI.py program.
You are also going to use constants in this new game to make it easier to move your
field around later. That way you won't have to hunt through your programs to find the
coordinate values you need to change if you move your field.
A constant is a name for a part of the computer's memory (just like a variable)
where you can store values that normally don't change while the program is running.
The Python language does not really have a special way of handing constants,
unlike other programming languages. Python programmers usually use a
programming convention (which simply means a standard way of working)
where constants are always typed in using upper case letters. This makes it
more obvious when you're programming something that it is a constant, and
you should not change it once you have set an initial value. Other programming
languages have their own way of using constants, and in these languages an
error is raised if you try to change their value. Python does not have this feature.
To write the program, follow these steps:
1. Start by opening a new window in IDLE by choosing File New File from the menu.
2. Choose File Save As from the menu, and name the file rent.py .
3. Import the modules needed for this program:
import mcpi.minecraft as minecraft
import time
4. Connect to the Minecraft game:
mc = minecraft.Minecraft.create()
5. Now you need to define some constants for the four coordinates of the geo-
fence. Make sure you use the coordinates that you worked out earlier. I've used
the coordinates that I used in my program, but yours might be different:
X1 = 10
Z1 = 10
X2 = 20
Z2 = 20
 
 
Search WWH ::




Custom Search