我将代码与其他训练示例代码进行了比较,并进行了比较,所有内容都匹配。这是我的问题:我有一个生命条,当我受到伤害时,条就会减少。
问题是,当我在我的代码中使用█时,管道线条永远不会停留在原地,它总是动态移动。当我使用/时,管条总是保持不动,没有问题。我猜我的终端工具(使用Pycharm)中有一些东西它不喜欢ascii代码219。如果与阅读论坛有关,则该工具设置为UTF-8。下面的示例可能格式不正确,但是当使用█时,你可以看到顶部的|被移位,而当使用/时,底部是正常的。

______________________________ __________
CARLOS: 2210/3260 |■■■■■■■■■■■■■■■■■ | 132/132 |//////////|
__________________ __________
CARLOS: 2219/3260 |///////////////// | 132/132 |//////////|代码:
def get_stats(self):
hp_bar = ""
bar_ticks = (self.hp / self.maxhp) * 100 / 4
mp_bar = ""
mp_ticks = (self.mp / self.maxmp) * 100 / 10
while bar_ticks > 0:
hp_bar += '█'
bar_ticks -= 1
#num_spaces_needed = (100/4) - len(hp_bar)
#str_spaces_needed = ""
#while num_spaces_needed > 0:
#str_spaces_needed += " "
#num_spaces_needed -= 1
while len(hp_bar) < 25:
hp_bar += " "
while mp_ticks > 0:
mp_bar += "/"
mp_ticks -= 1
while len(mp_bar) < 10:
mp_bar += " "
hp_string = str(self.hp) + "/" + str(self.maxhp)
current_hp = ""
if len(hp_string) < 9:
decreased = 9 - len(hp_string)
while decreased > 0:
current_hp += " "
decreased -= 1
current_hp += hp_string
else:
current_hp = hp_string
mp_string = str(self.mp) + "/" + str(self.maxmp)
current_mp = ""
if len(mp_string) < 7:
decreased = 7 - len(mp_string)
while decreased > 0:
current_mp += " "
decreased -= 1
current_mp += mp_string
else:
current_mp = mp_string
print(" _______________________________ __________ ")
print(bcolors.BOLD + self.name + " " +
current_hp + " |" + bcolors.BAR + hp_bar + bcolors.ENDC + "| " +
current_mp + " |" + bcolors.OKBLUE + mp_bar + bcolors.ENDC + "| ")发布于 2018-08-25 03:52:22
您必须更改字体类型
< Code >G29
发布于 2017-05-18 03:58:32
在脚本的顶部尝试执行以下操作:
import sys
reload(sys)
sys.setdefaultencoding('utf8')https://stackoverflow.com/questions/44033604
复制相似问题