You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Telium冒险游戏NPC显示为None及燃料获取规则修改问题咨询

Telium冒险游戏bug修复方案

问题1:进入模块显示"There is 'None' here"修复

根因:

  • spawn_npcs() 函数没有返回值,调用后赋值给npc变量默认取值为None
  • 函数内全局变量名拼写错误:vent_shaft 应为 vent_shafts、greedy_info_panels 应为 info_panels
  • 不该在每次加载模块时重复调用spawn_npcs(),该函数仅需在游戏启动时调用1次完成NPC位置初始化,重复调用会反复重置所有NPC坐标
    修改步骤:
  1. 修正spawn_npcs()内的全局变量声明错误
  2. 删除output_module()内的npc = spawn_npcs()调用,改为直接判断当前模块对应的NPC/道具类型
  3. 调整输出逻辑,无NPC时输出匹配的提示内容

修改后的核心代码片段:

def spawn_npcs():
    # 修正全局变量名错误
    global num_modules, queen, vent_shafts, info_panels, workers
    module_set = []
    for counter in range(2,num_modules):
        module_set.append(counter)
    random.shuffle(module_set)
    i = 0
    queen = module_set[i]
    for counter in range(0,3):
        i=i+1
        vent_shafts.append(module_set[i])

    for counter in range(0,2):
        i=i+1
        info_panels.append(module_set[i])

    for counter in range(0,3):
        i=i+1
        workers.append(module_set[i])

def output_module():
    global module, queen, workers, info_panels    
    print()
    print("------------------------------------------------------------------")
    print()
    print("You are in module",module)
    print()
    # 直接判断当前模块的NPC类型
    if module == queen:
        npc = "queen alien"
    elif module in workers:
        npc = "worker alien"
    elif module in info_panels:
        npc = "information panel"
    else:
        npc = "nothing"
    print(f"There is {npc} here")

问题2:通风井燃料随机取值修复

根因: 通风井燃料获取值固定写死为50
修改步骤:
将check_vent_shafts()内的fuel_gained = 50替换为fuel_gained = random.choice([20,30,40,50])即可,修改后代码片段:

def check_vent_shafts():
    global num_modules, module, vent_shafts, fuel
    if module in vent_shafts:
        print("There is a bank of fuel cells here.")
        print("You load one into your flamethrower.")
        # 改为随机取值
        fuel_gained = random.choice([20,30,40,50])
        print("Fuel was",fuel,"now reading:",fuel+fuel_gained)
        fuel = fuel + fuel_gained
        print("The doors suddenly lock shut.")
        print("What is happening to the station?")
        print("Our only escape is to climb into the ventilation shaft.")
        print("We have no idea where we are going.")
        print("We follow the passages and find ourselves sliding down.")
        last_module = module
        module = random.randint(1,num_modules)
        load_module()

附带修复的隐性bug

  • get_action()内判断输入的action.higher()改为action.upper()(Python无higher字符串方法)
  • 移动扣减电力的power =- 1改为power -= 1(原写法是给power赋值为-1,不是逐次减1)
  • 电力耗尽时的alive == False改为alive = False(原写法是比较运算,不会修改alive变量状态)
  • check_vent_shafts()调用移到主循环内部的load_module()之后(原位置在主循环外,永远不会触发)
  • 修正代码中字符串非法换行的语法问题

完整修改后代码

#Telium - Game
import random

#Global Variables
num_modules = 17          #Number of modules in the space station
module = 1                #Module of space station we are in
last_module = 0           #Last module we were in
possible_moves = []       #List of possible moves we can make
alive = True              #Whether player is alive or not
won = False               #Whether player has won
power = 100               #Amount of power the space station has
fuel = 500                #Amount of fuel the player has in flamethrower
locked = 0                #Module that has been locked by the player
queen = 0                 #Location of queen alien
vent_shafts = []          #Location of ventilation shaft entrances
info_panels = []          #Location of info panels
workers = []              #Location of worker aliens

#procedure declarations
#This loads the global module 
def load_module():
    global module, possible_moves
    possible_moves = get_modules_from(module)
    output_module()

def get_modules_from(module):
    moves = []
    text_file = open("Charles_Darwin/module" + str(module) + ".txt", "r")
    for counter in range(0,4):
        move_read = text_file.readline()
        move_read = int(move_read.strip())   
        if move_read != 0:
            moves.append(move_read)
    text_file.close()
    return moves

def output_module():
    global module, queen, workers, info_panels    
    print()
    print("------------------------------------------------------------------")
    print()
    print("You are in module",module)
    print()
    if module == queen:
        npc = "queen alien"
    elif module in workers:
        npc = "worker alien"
    elif module in info_panels:
        npc = "information panel"
    else:
        npc = "nothing"
    print(f"There is {npc} here")

def output_moves():
    global possible_moves
    print()
    print("From here you can move to modules: | ",end='') 
    for move in possible_moves:
        print(move,'| ',end='')
    print()

def get_action():
    global module, last_module, possible_moves, power
    valid_action = False
    while valid_action == False:
        print("What do you want to do next ? (MOVE, SCANNER)")
        action = input(">")
        if action.lower() in ['move', 'm']:
            move = int(input("Enter the module to move to: "))
            if move in possible_moves:
                valid_action = True
                last_module = module
                module = move
                #power is decreased by 1 for every move
                power -= 1
            else:
                print("The module must be connected to the current module.")

def spawn_npcs():
    global num_modules, queen, vent_shafts, info_panels, workers
    module_set = []
    for counter in range(2,num_modules):
        module_set.append(counter)
    random.shuffle(module_set)
    i = 0
    queen = module_set[i]
    for counter in range(0,3):
        i=i+1
        vent_shafts.append(module_set[i])

    for counter in range(0,2):
        i=i+1
        info_panels.append(module_set[i])

    for counter in range(0,3):
        i=i+1
        workers.append(module_set[i])
    
def check_vent_shafts():
    global num_modules, module, vent_shafts, fuel
    if module in vent_shafts:
        print("There is a bank of fuel cells here.")
        print("You load one into your flamethrower.")
        fuel_gained = random.choice([20,30,40,50])
        print("Fuel was",fuel,"now reading:",fuel+fuel_gained)
        fuel = fuel + fuel_gained
        print("The doors suddenly lock shut.")
        print("What is happening to the station?")
        print("Our only escape is to climb into the ventilation shaft.")
        print("We have no idea where we are going.")
        print("We follow the passages and find ourselves sliding down.")
        last_module = module
        module = random.randint(1,num_modules)
        load_module()
    
#Main Program starts here
#Menu options
print("ENTER 1 for instructions")
print("ENTER 2 to play")
print("ENTER 3 to quit")

menu = int(input("Please enter a number corresponding to what you want to do: "))
if menu == 1:
    instructions = input("Do you want to read the instructions(Y/N): ")
    if instructions == "Y":
        print("You, the player are trying to navigate around a space station named the 'Charles Darwin' which contains many modules")
        print("The aim of the game is to find a and trap the queen alien called 'Telium' who is located somewhere randomly in the station, the queen will try to escape to connectinhg modules so beware")
        print("To win - you have to lock the queen in one of the modules so she is trapped, you can kill her with a flamethrower, there is also objects to help on the way so keep a look out")

spawn_npcs()
#Outputs where the queen, shafts, panels and workers are located
print("Queen alien is located in module:",queen)
print("Ventilation shafts are located in modules:",vent_shafts)
print("Information panels are located in modules:",info_panels)
print("Worker aliens are located in modules:",workers)


#when the players is alive, the module will load 
while alive and not won:
    load_module()
    check_vent_shafts()
    if won == False and alive == True:
        output_moves()
        get_action()
#if power is 0 then the user will die and the game will end
    if power <= 0:
        print("You ran out of life support, you died")
        alive = False

#win message once you have trapped the queen or when you run out of life support
if won == True:
    print("The queen is trapped and you burn it to death with your flamethrower.")
    print("Game over. You win!")
if alive == False:
    print("The station has run out of power. Unable to sustain life support, you die.")

内容的提问来源于stack exchange,提问作者Joss Glyn-Smith

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.25 02:54:04