Game Development Reference
In-Depth Information
6 - Dragon Realm
How to Play "Dragon Realm"
In this game, the player is in a land full of dragons. The dragons all live in caves with
their large piles of collected treasure. Some dragons are friendly, and will share their
treasure with you. Other dragons are greedy and hungry, and will eat anyone who enters
their cave. The player is in front of two caves, one with a friendly dragon and the other with
a hungry dragon. The player is given a choice between the two.
Open a new file editor window by clicking on the File menu, then click on New
Window . In the blank window that appears type in the source code and save the source
code as dragon.py . Then run the program by pressing F5.
Sample Run of Dragon Realm
You are in a land full of dragons. In front of you,
you see two caves. In one cave, the dragon is friendly
and will share his treasure with you. The other dragon
is greedy and hungry, and will eat you on sight.
Which cave will you go into? (1 or 2)
1
You approach the cave...
It is dark and spooky...
A large dragon jumps out in front of you! He opens his jaws
and...
Gobbles you down in one bite!
Do you want to play again? (yes or no)
no
Dragon Realm's Source Code
Here is the source code for the Dragon Realm game. Typing in the source code is a great
way to get used to the code. But if you don't want to do all this typing, you can download
the source code from this topic's website at the URL http://inventwithpython.com/chapter6.
There are instructions on the website that will tell you how to download and open the
source code file. You can use the online diff tool on the website to check for any mistakes
in your code.
One thing to know as you read through the code below: The blocks that follow the def
lines define a function, but the code in that block does not run until the function is called.
The code does not execute each line in this program in top down order. This will be
explained in more detail later in this chapter.
Search WWH ::




Custom Search