我在做一个文字冒险游戏。

我对如何实现我游戏的下一部分感到困惑。

接下来我要补充的是:

“添加拾取对象的功能。如果用户键入get key,则:拆分用户输入,这样就可以分离出一个变量,它等于“key”。在

1.使用内置在Python字符串中的split方法。例如:

command_words=用户_命令.拆分(“”)

这将把用户键入的内容拆分为一个列表。每个项目根据空格分开。在请更新您的指示,改为检查命令字[0]。在

添加get命令的检查。在

2.搜索列表,直到找到与用户尝试拾取的对象匹配的对象。在

这是我目前掌握的代码:done = False

object_list = []

room_list = []

class Object():

def __init__(self, name, description, room):

self.name = name

self.description = description

self.current_room = room

wand = Object("Holly Wand", "This wand is an 11\" supple wand made of holly and a single phoenix tail feather core.", 1)

object_list.append(wand)

dh_cloak = Object("Cloak of Invisibility", "This is part one part of the most powerful trifecta. \nThis cloak shields you from all wandering eyes. \nFind all three parts and you may just be able to escape from this castle.", 3)

object_list.append(dh_cloak)

class Room():

def __init__(self, describe, nw, n, ne, e, se, s, sw, w):

self.description = describe

self.northwest = nw

self.north = n

self.northeast = ne

self.east = e

self.southeast = se

self.south = s

self.southwest = sw

self.west = w

kitchen = Room("You are in the Kitchen. Look at the scrumptious roast chicken and kidney pudding! \nThere are doors leading to North, East, and West.", None, 4, None, 2, None, None, None, 0)

room_list.append(kitchen)

east_cooridor = Room("You apparated into the East Corridor. \nYou can apparate to the Northwest or the Southwest.", 8, None, None, None, None, None, 2, None)

room_list.append(east_cooridor)

great_hall = Room("You are in the Great Hall. What is that great smell? \nThere appears to be doors leading to the north and the south.", None, 7, None, None, None, 1, None, None)

room_list.append(great_hall)

owlery = Room("You are in the Owlery. WHOOs got mail? There is a glass door overlooking the Forbidden Forest. \nThere are doors in every direction.", None, 9, None, 8, None, 4, None, 6)

room_list.append(owlery)

room_list.append(forbidden_forest)

current_room = 4

while not done:

print(room_list[current_room].description)

key = current_room

i = 0

while i < len(object_list) and object_list[i].current_room != key:

i += 1

if i < len(object_list):

print("There is an object you can pick up in this room.")

print()

direction = input("Which direction would you like to travel? ")

print()

if direction.lower() == "n" and current_room == 9 or direction.lower() == "north" and current_room == 9:

print("You wandered too far into the Forbidden Forest with out all of the Deathly Hallows to protect you. \nYou have died.")

done = True

elif direction.lower() == "nw" or direction.lower() == "northwest":

next_room = room_list[current_room].northwest

if next_room == None:

print("TROLL! Troll in the dungeon!!")

else:

current_room = next_room

print()

elif direction.lower() == "n" or direction.lower() == "north":

next_room = room_list[current_room].north

if next_room == None:

print("Run away!!!!")

else:

current_room = next_room

print()

elif direction.lower() == "ne" or direction.lower() == "northeast":

next_room = room_list[current_room].northeast

if next_room == None:

print("Oh cool! Pixies! Wait...yikes! Bad idea!")

else:

current_room = next_room

print()

elif direction.lower() == "e" or direction.lower() == "east":

next_room = room_list[current_room].east

if next_room == None:

print("Don't go over there! The Whomping Willow is over there!")

else:

current_room = next_room

print()

elif direction.lower() == "se" or direction.lower() == "southeast":

next_room = room_list[current_room].southeast

if next_room == None:

print("Don't go in there...")

else:

current_room = next_room

print()

elif direction.lower() == "s" or direction.lower() == "south":

next_room = room_list[current_room].south

if next_room == None:

print("AHHH! It's Fluffy, the three-headed dog!")

else:

current_room = next_room

print()

elif direction.lower() == "sw" or direction.lower() == "southwest":

next_room = room_list[current_room].southwest

if next_room == None:

print("The third floor corridor is forbidden.")

else:

current_room = next_room

print()

elif direction.lower() == "w" or direction.lower() == "west":

next_room = room_list[current_room].west

if next_room == None:

print("I wouldn't go that way if I were you. You may run into something dangerous!")

else:

current_room = next_room

print()

elif direction.lower() == "q" or direction.lower() == quit:

done = True

else:

print("What kind of sorcery is this!? Try going an actual direction.")

print()

我试着按照给我的指示去做,但是我们没有学习到分割命令,我在网上找不到任何解释它的东西。

我希望有人能向我解释我是如何使用split命令将用户输入的内容“拆分”到一个列表中。我不太明白我为什么要这样做。

如有任何建议,我们将不胜感激。谢谢您!在

pythonsplit怎么使用_如何在Python中使用Split命令?相关推荐

  1. python执行的命令_如何在Python中执行外部命令

    Python子进程模块允许生成新进程,从Python脚本执行外部命令. 您可以使用这些教程来安装最新版本的Python. 此外,还有许多可用于Python IDE. 就像在Ubuntu系统上安装PyC ...

  2. python隐藏启动台_如何在Python中启动后台进程?

    如何在Python中启动后台进程? 我正在尝试将shell脚本移植到更易读的python版本. 原始shell脚本在后台使用"&"启动多个进程(实用程序,监视器等). 如何 ...

  3. python 线性回归模型_如何在Python中建立和训练线性和逻辑回归ML模型

    python 线性回归模型 Linear regression and logistic regression are two of the most popular machine learning ...

  4. python多项式回归_如何在Python中实现多项式回归模型

    python多项式回归 Let's start with an example. We want to predict the Price of a home based on the Area an ...

  5. python中用什么函数读取字符串_如何在Python中获得函数名作为字符串?

    在Python中,如何在不调用函数的情况下以字符串的形式获得函数名? 1 2 3 4def my_function(): pass print get_function_name_as_string( ...

  6. python set 排序_python set 排序_如何在Python中使用sorted()和sort()

    点击"蓝字"关注我们 ?"Python基础知识" 大卫·丰达科夫斯基  著 18财税3班 李潇潇    译 日期:2019年5月6日 一. 使用sorted() ...

  7. python 参数个数 同名函数_如何在python中编写不同参数的同名方法

    我在Java背景下学习Python(3.x). 我有一个python程序,我在其中创建一个personObject并将其添加到列表中.p = Person("John") list ...

  8. python 指定证书验证_如何在python中验证SSL证书?

    我需要验证我的自定义CA签署了证书.使用OpenSSL命令行实用程序很容易做到: # Custom CA file: ca-cert.pem # Cert signed by above CA: bo ...

  9. eval在python中是什么意思_如何在Python中使用eval ?

    Python中的 eval是什么? 在Python中,我们有许多内置方法,这些方法对于使Python成为所有人的便捷语言至关重要,而eval是其中一种.eval函数的语法如下: eval(expres ...

最新文章

  1. python做商品推荐系统_一种商品智能推荐系统的设计的制作方法
  2. 视频监控线缆选型须知 转
  3. 第四单元用计算机写作,计算机复习题
  4. .NET深入学习笔记(4):深拷贝与浅拷贝(Deep Copy and Shallow Copy)
  5. 1198. Jobbery
  6. 单例设计模式 (2)
  7. Linux系统C语言实现 根据进程号/进程名获取进程的运行时间
  8. 使用RestTemplate遇到的问题
  9. java使用redis的demo,Javaredisdemo
  10. eviews计算covar_第7章 我国商业银行风险溢出效应的度量—基于GARCH-CoVaR模型
  11. java生成zipf分布_数据存储中Zipf分布
  12. oracle节假日,oracle 产生节假日表
  13. 得空写的基于web的工作流表单设计器,大家看看怎么样
  14. 超简单的QFN封装芯片的手工焊接方法,先收藏
  15. 马哥教育N63期-第三周作业
  16. I/Q数据频谱分析仪简介
  17. 用DIV+CSS技术设计的游戏企业网页(网页制作课作业)
  18. 外文文献下载网站;数据获取网站;中文文献下载网站;论文原创性保真网站;外包项目申请网站;大数据比赛收录网站;提高编程能力;代码分享网站
  19. PPT作品分享——创建学习型组织,打造企业核心竞争力
  20. SpringBoot+Vue+ElementUI实现后台管理系统

热门文章

  1. Android基础性能检测与分析
  2. python推荐书-每一页都是干货,这10本Python新书,我必须推荐给你
  3. 如何用GraphPad Prism做统计?
  4. Python识别验证码----谷歌reCapture 4*4验证码
  5. Android 进阶技术汇总二: 流行框架组件 方案汇总
  6. PointPainting 复现
  7. Uni-app 课程详情页 获取课程详情 + 收藏 + 加入购物车
  8. 基于python+django+vue学生作业管理系统
  9. delphi直接打印jpg文件
  10. 我的世界32位红石计算机,我的世界4个超棒的红石作品 最后红石计算机看后要跪键盘...