- 已关闭**。此问题为opinion-based。当前不接受答案。
- 想要改进此问题吗?**请更新此问题,以便editing this post可以用事实和引文来回答。
6天前关闭。
Improve this question
一般来说,我是一个新手,更不用说Python了。
在学习了一些教程之后,我决定尝试制作自己的简单Map导航系统,借鉴了我所知道的古老的MUD游戏(如Achaea)的工作原理。它工作正常,但我不知道它会有多健壮或可扩展性。
此处代码:
def r0_0():
print("You are in room 0,0")
while True:
a = input("You can move North or East.\n>")
if a == "n":
r1_0()
elif a == "e":
r0_1()
else:
print("You can't go that way.")
def r0_1():
print("You are in room 0,1")
while True:
a = input("You can move North or West.\n>")
if a == "n":
r1_1()
elif a == "w":
r0_0()
else:
print("You can't go that way.")
def r1_0():
print("You are in room 1,0")
while True:
a = input("You can move South or East.\n>")
if a == "s":
r0_0()
elif a == "e":
r1_1()
else:
print("You can't go that way.")
def r1_1():
print("You are in room 1,1")
while True:
a = input("You can move South, West, Up, or Down.\n>")
if a == "s":
r0_1()
elif a == "w":
r1_0()
elif a == "u":
r1_1_1()
elif a == "d":
r1_1_b1()
else:
print("You can't go that way.")
def r1_1_1():
print("You are in room 1,1,1")
a = input("You can move Down.\n>")
if a == "d":
r1_1()
else:
print("You can't go that way.")
def r1_1_b1():
print("You are in room 1,1,-1")
a = input("You can move Up.\n>")
if a == "u":
r1_1()
else:
print("You can't go that way.")
r0_0()
我主要是在寻找如何改进这个系统的反馈,或者它是否可靠。我应该继续使用这个系统,还是它以后会引起问题?
1条答案
按热度按时间eimct9ow1#
你用代码而不是数据来描述每个房间和Map,这对你自己来说太难了。
您应该将Map编码为数据结构,并编写(更少的)代码来导航Map。
例如,您可能有一个表示房间的数据结构,其中包含房间的名称、出口方向以及每个出口通向的房间的引用。
然后用一个对数据结构进行操作的函数替换所有这些房间函数。