1

我是Learning Python the Hard Way 的 52 个示例,其中包括创建基于文本的游戏。因此,我有两个重要的模块map.pyapp.py一个show_room.html我正在研究的模块。

map.py包含一个房间“激光武器军械库”,用户必须在其中猜测 4 位代码。
我正在尝试引入一个可以显示代码的作弊码。这包括在app.py.

地图.py

code=("%s%s%s%s"%(randint(0,9),randint(0,9),randint(0,9),randint(0,9))) 
class Room(object):

    def __init__(self, name, description):
        self.name = name
        self.description = description
        self.paths = {}

    def some_other_functions:
        ....

laser_weapon_armory = Room("Laser Weapon Armory",description)

app.py(阅读重要部分):

import web
from gothonweb import map

urls = ('/game', 'GameEngine',
       '/', 'Index',)
some_code

class GameEngine(object):
    def GET(self):
        if session.room:
            return render.show_room(room=session.room)

def POST(self):        
    form = web.input(action="")
    #Here is the important part:
    if session.room == map.laser_weapon_armory:
        if form.action == "you tell me":
            map.laser_weapon_armory.description+=map.code
        elif form.action != map.code:
            form.action ='*'


    if session.room and session.room.go(form.action):
        session.room = session.room.go(form.action)                   

    web.seeother("/game")

重要部分的 if 子句永远不会得到验证。主要是因为当 'session.room' 等于 'laser_weapon_armory' 时,它会显示为不同的对象。
IE:

print(laser_weapon_armory) ##<gothonweb.map.Room object at 0x01FDE550>

然而

print(session.room)  ##gives <gothonweb.map.Room object at 0x0205E230>

为什么会发生这种情况,而其他导入给出相同的对象?

4

0 回答 0