The easiest way to start is to copy the template.py file to your new game file -- call it something like MyGame.py (or whatever suits you). The template imports the modules which define verbs and objects and so forth; then there's a big gap where you define your own objects and classes (if any); then it prints the title screen and runs the game.
You can actually run the game at this point, though nothing much interesting happens. A sample transcript shows that you'll find yourself in "The Universe", and a perfectly ordinary one at that. Pretty dull so far.
Now let's create the two rooms of a house. We'll call them "upstairs" and "downstairs", and give them descriptions. This code goes in the "Create Some Objects" section of the game file:
downstairs = pubobjs.Room("Downstairs Room") downstairs.desc = "You're on the ground floor of a tiny house. The walls \ are featureless, and you can find no doors or windows. However, there is \ a ladder that leads up through a little hole in the ceiling." upstairs = pubobjs.Room("Upstairs Room") upstairs.desc = "You're in the upper room of this tiny house. There are no \ windows, and no doors either except for a hole in the floor, through which \ a ladder leads down."This creates the two rooms, but they are not really linked together. We need to create an exit from each room to the other. When creating any type of object except rooms, the object goes into the last room created. So things we want to appear in the downstairs room should be created right after that room. After the "downstairs.desc" line and before the "upstairs" code, insert an exit and a decorative plant:
downstairs_u = Exit("up,ladder,exit,u,hole,upstairs") downstairs_u.desc = "Looking up, you get a glimpse of a tiny room much like \ the one you're in." plant = Thing("potted plant,plant,potted") plant.desc = "It's a nice green ivy, growing merrily despite the lack of \ direct sunlight."Then after the "upstairs" code, insert some things there:
upstairs_d = Exit("down,d,ladder,exit,out,hole,downstairs") upstairs_d.desc = "It's just a ladder leading down." Monty = NPC("Monty,Mon,Mr. Python") Monty.desc = "Monty's a tall man with a large mustache and a very silly walk." Monty.replies['walk'] = [ "It's not very silly, but I think with some funding I could develop it.", "You think it's silly? You've got a pretty ordinary walk yourself." ] Monty.replies['silly'] = Monty.replies['walk']So we have exits in each room, as well as a plant downstairs and a character named Monty upstairs. Monty has two canned responses to the word 'walk', and the same replies for the work 'silly'.
At this point, your script should look like this. When you run the game, you get this surprising result: you're still in the Universe, looking down on the two rooms! We forgot to move the player to one of the rooms we've created. Just add this line after you create the downstairs room:
player.MoveTo(downstairs)That makes things a little better; you start out in the downstairs room and you can look at the plant, the ladder, etc. But when we try to go up, we get the error:
>up Up leads nowhere.What's going on? We created the exits in both rooms, but we forgot to set the dest property on each one. This property tells the game where each exit leads. Note that we can't reference "upstairs" before it's been created, so we'll put both of these lines after both downstairs and upstairs have been declared:
downstairs_u.dest = upstairs upstairs_d.dest = downstairsNow the complete script should look like this, and a trial run shows that everything appears to be in working order. (I didn't test the downstairs link in this trial; you should do so, in addition to looking at the plant, the ladder, etc.)