Hello everyone, I just started with the book 'Learning Python the hard way' by Zed A. Shaw,and I have to say that it is really fun to learn code. I thought that it would be a problem because I'm 15,but I'm understanding it pretty well so far.

Anyway,enough of the chitchat. I have a question with my first test-game,I'll put the code in here for it too.

It's still pretty short and I'm writing it with rooms,like room1,room2 etc.
Now my question is,if there is any kind of inventory or such.
I want to make the player find a rope(seil) and then use it on an abyss in the jungle(jungel),the problem is,the rope/seil is in another room.
I wrote,that the seil is false,until it is picked up by the player. After picking it up,the rope becomes True and can't be picked up anymore.

I'm also trying to make the same room twice,in this case the jungle,so you have diffrent dialoques when walking from A to B and B to A.

I'm trying to get the player find a radio with no batteries,then he has to find a rope,to get through the jungle to the other side,to find the batteries.If he has the batteries and the radio,he combines them,calls a rescue team and gets rescued in a new version of the room 'wrack'.
I hope it's not to complicated.

  1. When I go back to the room,will the rope be there again,even after picking it up?
  2. Can I use the picked up rope in another room?
  3. If yes,how?

Sorry for my bad english,and that the code is written in german. But you should probaply understand most of it.

If you have questions about it,please ask me. I'd love to get answers,criticism or tips.

Thanks.

from sys import exit

def wrack_rettung():
    print "Du entdeckst das Rettungsteam und deren Hubschrauber."
    print "Als du angelatscht kommst,wirst du mit Kaffee und einer Decke versorgt."
    print "Du steigst in den Helikopter und fliegst wieder nach Hause. Du hast gewonnen!"


def wrack():
    print "Als du naeher zum Wrack kommst, riechst du das verbrannte Kerosin."
    print "Was tust du als naechstes?"
    print "1. Untersuche das Wrack"
    print "2. Gehe wieder zum Strand"
    print "3. Ruf nach Hilfe"
    funk = False

    while False:

        next = raw_input("> ")

        if next == "2":
            start()
        elif next == "1" and funk:
            print "Du findest ein Funkgeraet ohne Batterien,und steckst es ein."
            print "Was tust du nun?"
            funk = True
        elif next == "1" and not funk:
            print "Es gibt nichts mehr zu untersuchen."
        elif next == "3":
            print "Du rufst verzweifelt nach Hilfe, doch du scheinst alleine zu sein."
            print "Was tust du?"
        else:
            print "Bitte antworte mit 1, 2 oder 3"

def bucht():
    print "Du siehst dich um und siehst ein Seil in der Ferne liegen."
    print "Wie sieht dein Plan aus?"
    print "1. Nimm das Seil"
    print "2. Geh wieder zum Strand"
    seil = False

    while False:
        next = raw_input("> ")

        if next == "1" and seil:
            print "Du steckst das Seil ein."
            seil = True
        elif next == "1" and not seil:
            print "Du hast das Seil bereits eingesteckt."
            print "Was tust du?"
        elif next == "2":
            start()


def strand_nach_jungel():
    print "Du betretest den tiefen Jungel und hoerst diverse Tier-Geraeusche."
    print "1. Geh tiefer in den Jungel hinein"
    print "2. Ruf nach Hilfe"
    print "3. Geh wieder zum Strand"

    next = raw_input(" >")

    if "1":
        print "Du gehst tiefer in den Jungel hinein und stehst aufeinmal vor einem Abgrund."

Recommended Answers

All 3 Replies

class Hero:
  rope = false
  batteries = false
  radio = false
  room = "start"

  def move(self, dest):
    # define room change
  def get(self, item):
    # get item by symbol (flag true)
  # if batteries && radio then (OK to call for backup)
commented: Could you please explain that a bit more? I don't reakky get it. +0

The easiest way to make a text adventure is to use classes. Have a look at this topic: http://www.daniweb.com/software-development/python/threads/57599/text-adventure-classes Basically you create a class called "Room" which has several methods i.e. the room's description, the items inside the room (like a rope) and characters in the room. This way the player can move from room to room and you can print the room's description or add/remove from the room's inventory. i.e. taking the rope from room1's list of items.

Sorry if that's not very well explained, here's a simplified version of the template above:

import sys #importing sys means you can use sys.exit() to quit the program

# Room class
class Room(object):
    """ Room """
    def __init__(self,description):
        self.description = description


#A few sample rooms
room1 = Room("Bedroom1. You are in a bedroom in The Prancing Pony Inn. \neast: Hallway")
room2 = Room("You are in the hallway. \neast: Bedroom \nwest: Bedroom \nnorth: Hallway")
room3 = Room("You are at the northern end of the hallway. \nsouth: Hallway")
room4 = Room("Bedroom2. You are in a bedroom in The Prancing Pony Inn. \nwest: Hallway")

# Room coordinates
room1.coordinates = [0,room2,0,0]
room2.coordinates = [room3,room4,0,room1]
room3.coordinates = [0,0,0,room2]
room4.coordinates = [0,0,0,room2]

# Character class
class Character(object):
    def __init__(self,name,gender,hair,age,Health,location = room1):
        self.name = name
        self.gender = gender
        self.hair = hair
        self.age = age
        self.Health = Health
        self.location = location
        self.inv = []

    def look(self):
        place = self.location
        print(place.description)

#Creating main character
characters = []
Wallace = Character("Wallace","m","black",20,100)
characters.append(Wallace)
currentchar = Wallace

#Introduction
print ("Welcome to Wallace's text adventure.")
print ("What is your name?")
currentchar.name = raw_input()
print ("Hello",currentchar.name)
print ('Type "commands" to see the command list')

#This prints the room description
currentchar.look()


#The game loop, once it has gone through the loop it will ask for the player to type in input again
while True:
    command = raw_input().lower()
    if command == "n" or command == "north":
        if currentchar.location.coordinates[0] == 0:   #0 means there is no exit in that direction
            print("You cannot go that way.")
        else:
            currentchar.location = currentchar.location.coordinates[0] #changes location to the north one for the current room
            currentchar.look()
    elif command == "e" or command == "east":
        if currentchar.location.coordinates[1] == 0:
            print("You cannot go that way.")
        else:
            currentchar.location = currentchar.location.coordinates[1]
            currentchar.look()
    elif command == "s" or command == "south":
        if currentchar.location.coordinates[2] == 0:
            print("You cannot go that way.")
        else:
            currentchar.location = currentchar.location.coordinates[2]
            currentchar.look()
    elif command == "w" or command == "west":
        if currentchar.location.coordinates[3] == 0:
            print("You cannot go that way.")
        else:
            currentchar.location = currentchar.location.coordinates[3]
            currentchar.look()
    elif command == "commands":
        print '"n","e","s", and "w" make your character go north, east, south, and west respectively'
        print '"end" to quit'
        print '"look" to look around the room'
        print '"players" to see the player list'
    elif command == "players":
        print(characters)
    elif command == "end" or command == "quit":
        sys.exit() # This quits the game

I do not understand your while False blocks, as that means the statements are never executed.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.