我在Python中制作了一个刽子手游戏,并且在我尝试使用curses之前愚蠢地没有保存。 :|现在,男人的身体显示在不同的位置。头部和手臂位于保持顶部的杆之前,身体和腿部应该是它们应该的位置。这是我的代码。这可能是我用Python编写的最丑陋的代码......
import random
import re
import curses
myscreen = curses.initscr()
myscreen.clear()
myscreen.border(0)
myscreen.refresh()
f = open("/usr/share/dict/words", "r")
c = f.read().split('\n')
d = {1:'o', 2:'\\o/', 3:'\n | \\o/\n | |', 4:'\n | \\o/\n | |\n | / \\'}
w = random.choice(c).lower()
i = 1
j = 6
n = []
t = []
b = ""
l=4
h=2
myscreen.addstr(2,6, "--------")
myscreen.addstr(3,6, "|")
myscreen.addstr(3,13, "|"+b)
for item in range(j+1):
myscreen.addstr(l, 2, " |\n")
l=l+1
myscreen.addstr(9,2,"__________\n")
for char in w:
n.append('_')
for item in n:
myscreen.addstr(10, h, item,)
h=h+2
myscreen.addstr(11, 2, '\n')
myscreen.refresh()
while n != w:
if not re.findall('_', ''.join(n)):
myscreen.clear()
myscreen.addstr(1,1, "You win!!\n\n")
myscreen.refresh()
break
myscreen.addstr(12,2,"Guess: ")
g = myscreen.getstr(12,9,1)
if 1:
if g in ''.join(t):
print "You already guessed that."
continue
if g in w:
k = [match.start() for match in re.finditer(re.escape(g), w)]
for item in k:
n[item]=g
t.append(g)
else:
if i!=5:
b = d[i]
i=i+1
j=j-1
t.append(g)
else:
myscreen.clear()
myscreen.addstr(1, 1, "You lose!")
myscreen.addstr(2, 1, "The word was %s.\n\n" % w)
myscreen.refresh()
break
myscreen.clear()
myscreen.addstr(2,6, "--------")
myscreen.addstr(3,6, "|")
myscreen.addstr(3,13, "|\n"+b)
l=4
for item in range(j):
myscreen.addstr(l, 6, "|\n")
l=l+1
myscreen.addstr(9,2,"__________\n")
l=2
for item in t:
myscreen.addstr(10, l, item)
l=l+2
l=2
for item in n:
myscreen.addstr(11, l, item)
l=l+2
myscreen.refresh()
else:
myscreen.addstr(12, 2, "Please enter a letter.")
myscreen.refresh()
它出了什么问题?
答案 0 :(得分:0)
D'哦!我放置了支撑它的杆后,我正在进行for循环,所以它“覆盖”了前一个。