我正在尝试自己制作游戏,这是我的第一个游戏。在其中,我试图随着时间的推移添加功能,有一天我想出了一个为某些关键词添加颜色的想法。这就是我所拥有的:
print("The Text Based Game v0.1.0.0")
import time
import sys
time.sleep(1.5)
name = input("What is your name? ")
print("%s, are you a Warlock, Titan, or Hunter? Type 'list' if you would like a discription of each class." % (name))
playerclass = input()
if playerclass == ("list"):
print ("\nWarlocks are powerful guardians. They hit hard but can't take in much in return. \n\nTitans are tanks. In the front of the line taking in bullets for others.\n\nHunters are the middle man. They are fast but besides that they don't have much else to bring to the table.\n")
time.sleep(2)
print ("Will you chose to be a Warlock, Titan, or Hunter?")
playerclass = input()
现在,当代码询问你想成为什么职业时,我希望“术士”、“泰坦”和“猎人”这些词以不同的颜色显示。这就是我试图做的:
print("The Text Based Game v0.2.0.0")
import time
import sys
from colorama import Fore, Back, Style
print (Style.RESET_ALL)
Warlock = (Fore.BLUE + "Warlock" + Style.RESET_ALL)
Titan = (Fore.RED + "Titan" + Style.RESET_ALL)
Hunter = (Fore.GREEN + "Hunter" + Style.RESET_ALL)
time.sleep(1.5)
name = input("What is your name? ")
print ("%s, are you a " +str(Warlock)+ ", " +str(Titan)+", or" +str(Hunter)+ "? Type 'list' if you would like a discription of each class." % (name))
playerclass = input()
if playerclass == ("list"):
print ("\nWarlocks are powerful guardians. They hit hard but can't take in much in return. \n\nTitans are tanks. In the front of the line taking in bullets for others.\n\nHunters are the middle man. They are fast but besides that they don't have much else to bring to the table.\n")
time.sleep(2)
print ("Will you chose to be a Warlock, Titan, or Hunter?")
playerclass = input()
它提出一个错误,上面写着:
Traceback (most recent call last):
File "python", line 14, in <module>
TypeError: not all arguments converted during string formatting
我不想每次都在引号内写“Fore.BLUE + "Warlock" + Style.RESET_ALL",而是希望系统在我写术士。我认为我的想法应该有效,但我执行错了......
请注意,我在 Python 3.6.1 中在线在 Repl.it 中编写了所有这些内容,这是 Repl.it 中代码的链接:https ://repl.it/@Woah_its_boobe/Error