Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 文本冒险室运动_Python_Text_Adventure - Fatal编程技术网

Python 文本冒险室运动

Python 文本冒险室运动,python,text,adventure,Python,Text,Adventure,所以我一直在努力解决这个代码问题有一段时间了,但我似乎无法得到它。无论何时你试图向任何方向移动,它仍然会显示你被困在厨房里。我添加了“打印当前房间”行,这表明程序正在将其移动到其他房间,但没有打印正确的描述 任何帮助都会很好 提前谢谢 class Room(): room = [] def __init__ ( self, desc, north , east , west , south, northwest, southwest, northeast, sou

所以我一直在努力解决这个代码问题有一段时间了,但我似乎无法得到它。无论何时你试图向任何方向移动,它仍然会显示你被困在厨房里。我添加了“打印当前房间”行,这表明程序正在将其移动到其他房间,但没有打印正确的描述

任何帮助都会很好

提前谢谢

class Room():
        room = []
        def __init__ ( self, desc, north , east , west , south, northwest, southwest, northeast, southeast):
            self.room.append(desc)
            self.room.append(north)
            self.room.append(east)
            self.room.append(west)
            self.room.append(south)
            self.room.append(northwest)
            self.room.append(southwest)
            self.room.append(northeast)
            self.room.append(southeast)
        def get_Desc(self):
            return self.room[0]
        def get_North(self):
            return self.room[1]
        def get_East(self):
            return self.room[2]
        def get_West(self):
            return self.room[3]
        def get_South(self):
            return self.room[4]
        def get_Northwest(self):
            return self.room[5]
        def get_Southwest(self):
            return self.room[6]
        def get_Northeast(self):
            return self.room[7]
        def get_Southeast(self):
            return self.room[8]



#Object Class
class Object():
    name = ""
    description = ""
    room = None
    def __init__ (self, newname, desc, newroom):
        self.name = newname
        self.description = desc
        self.room = newroom
    def get_Name():
        return name
    def set_Name(self , name):
        self.name = name
    def get_Desc(self):
        return description
    def set_Desc(self , description):
        self.description = description
    def get_Room(self):
        return self.description
    def set_Room(self, room):
        self.room = room




#This is a list of Objects in game
p_items = []
puppy = Object("Puppy", "OMG ROFL, LMAO, ITS CUTE AS ALL BALLS, GRAB IT AND SQUEEZE IT!!!", 2)
p_items.append(puppy)
Inventory = []
#This is a list of Rooms
room_list = []
room_1 = Room("This is the kitchen - 1. There is a passage to the North, East, and North East.", 3, 2, None, None , None, None, 7, None)
room_list.append (room_1)
room_2 = Room("This is the dining room - 2. There is a passage to the North, North East, and North West", 7, None, 1, None, 3, None, 6, None)
room_list.append(room_2)
room_3 = Room("This is the West hallway -3. There is a passage to the North, East, West, North East, North West, South East, and South West.", 4, 7, 1, None, 4, 1, 5, 2)
room_list.append(room_3)
room_4 = Room("This is the bedroom - 4. There is a passage to the East, West, and Southeast.", None, 5, 3, None, None, None, None, 7)
room_list.append(room_4)
room_5 = Room("This is the office -5. There is a passage to the South, West, Southwest, Northwest, and Northeast .", None, None, 7, 4 , 3, None, None, 6)
room_list.append(room_5)
room_6 = Room("This is the balcony. There is a passage to the West, North West, and South West.", None, None, None, 7, 5, 2, None, None )
room_list.append(room_6)
room_7 = Room("This is the East hallway. There is a passage to the North, South, and West, North East, North West, South East, and South West.", 5, None, 2, 3, 4, 1, 5, 2)
room_list.append(room_7)

current_room = 3
done = False
while not done:
    print (current_room)
    print ((room_list[current_room]).get_Desc()) 
    for object in p_items:
        if object.get_Room() == current_room:
            print("There is an Object in this room : " + object.get_Name() + " - " + object.get_Desc())
    answer = input("Which direction would you like to go? \n N, E, S, W, NE, SE, NW, SW, O to open Inventory, P to pick up an item, or Q to quit ").lower()
    if answer == ("q"):
        done = True
    elif answer == ("n") and room_list[current_room].get_North() != None:
        current_room = room_list [current_room].get_North() 
    elif answer == ("e") and room_list[current_room].get_East() != None:
        current_room = room_list[current_room].get_East() 
    elif answer == ("w") and room_list[current_room].get_West() !=None:
        current_room = room_list[current_room].get_West() 
    elif answer == ("s") and room_list[current_room].get_South() !=None:
        curent_room = room_list[current_room].get_South() 
    elif answer == ("nw") and room_list[current_room].get_Northwest() !=None:
        current_room = room_list[current_room].get_Northwest() 
    elif answer == ("sw") and room_list[current_room].get_Southwest() !=None:
        curent_room = room_list[current_room].get_Southwest() 
    elif answer == ("ne") and room_list[current_room].get_Northeast() !=None:
        current_room = room_list[current_room].get_Northeast() 
    elif answer == ("se") and room_list[current_room].get_Southeast() !=None:
        curent_room = room_list[current_room].get_Souteasth() 
    elif answer == ("o"):
        print ("\nYou have the following objects in your Inventory:")
        for object in inventory:
            print ( "-" + object.get_Name() + " ; " + object.get_Desc());
    elif answer == ("p"):
        print ("\nThere are these items in this room:")
        for object in inventory:
            if object.get_Room() == current_room:
                print ( "-" + object.get_Name() + " ; " + object.get_Desc());                
                pu = input("Would you like to pick it up? (y/n): ").lower()
                if  pu == "y":
                    object.set_Room(666)
                    inventory.append(object)
                elif pu == "n":
                    print ( "Dont be dumb, pick it up!")
                else:
                    print ("That is not a valid option")  

                    print ("That is not a valid option")

    else:
        print ("\nThat is not a valid option!\n") 
    print (answer)
    print (current_room)


 #No quiting allowed everrrrr

导致你的问题的是你的房间等级

这一行使room成为一个类级列表(一个静态变量)。因此,每当您创建一个房间的新实例时,您都会将数据附加到这个类级列表中,但第一个索引是由您的游戏逻辑访问的

def get_Desc(self):
    return self.room[0]

etc...
将始终是同一房间的值

在方法内部创建时,列表不再位于类级别,您的问题已得到解决

class Room():
    def __init__(self, desc, north, east, west, south, northwest, southwest, northeast, southeast):
        self.room = []

这里的代码太多了。请将其缩减到演示问题所需的最小值。问题是我不知道代码的哪一部分使其无法工作。
class Room():
    def __init__(self, desc, north, east, west, south, northwest, southwest, northeast, southeast):
        self.room = []