我写了一堆东西来打印一张随机生成的符号地图,并让一个角色四处移动,但每次我都需要用新行重新打印这些行
我尝试将printed.insert(乘数“\n”)放在不同的位置,但它只会放7行,然后再放几行,因此我不知道如何将a\n放在行的末尾。我把程序放在原处,这样你们就可以明白我们要做什么了
import random
import time
import os
def cls():
os.system('cls' if os.name=='nt' else 'clear')
randomnumber = random.randint(6,16)
block = []
printed = []
health = 10
blocks = "\x1b[1;37;48m#"
randumplace = random.randint(0, len(block))
multiplier = 47
def build(blocks):
for i in range (multiplier):
block.append(blocks)
printed.append(blocks)
i = random.randrange(1, 75)
if i == 4:
blocks = "\x1b[1;31;48mM"
elif i == 15:
blocks = "\x1b[1;36;48m~"
elif i == 25:
blocks = "\x1b[1;36;48m~"
elif i == 22:
blocks = "\x1b[1;33;48m$"
elif i == 1:
blocks = "\x1b[1;37;48m#"
elif i == 10 and "@" not in printed:
blocks = "@"
else:
blocks = "\x1b[1;37;48m."
counter = 1
print("# "+"# # # # # #" + " #" * (multiplier - 6))
while counter != randomnumber:
del block[:]
build(blocks)
print(*block)
counter += 1
print ("" + "# " * (multiplier +1))
position = printed.index("@")
while position != 38:
movement = input("Move which direction? (Type 'help' for commands)")
if movement == "d":
cls()
printed.pop(position+1)
printed.insert(position+1, "@")
printed.pop(position)
printed.insert(position, ".")
print(*printed)
position = printed.index("@")
if movement == "a":
cls()
printed.pop(position-1)
printed.insert(position-1, "@")
printed.pop(position)
printed.insert(position, ".")
print(*printed)
position = printed.index("@")
if movement == "w":
cls()
printed.pop(position-32)
printed.insert(position-32, "@")
printed.pop(position)
printed.insert(position, ".")
print(*printed)
position = printed.index("@")
if movement == "s":
cls()
printed.pop(position+33)
printed.insert(position+33, "@")
printed.pop(position)
printed.insert(position, ".")
print(*printed)
position = printed.index("@")
我希望它会重新打印地图,并改变“@”符号的位置,但它只是将所有内容组合在一起,没有新的线条
目前没有回答
相关问题 更多 >
编程相关推荐