我正在尝试为我的非常简单的游戏打印ASCII艺术作品。
当我尝试运行该程序时,它仅闪烁0.01秒然后消失。我还尝试为每个新行使用打印语句。
turtle1 = (r'''\ ___-------___
_-~~ ~~-_
_-~ /~-_
/^\__/^\ /~ \ / \
/| O|| O| / \_______________/ \
| |___||__| / / \ \
| \ / / \ \
| (_______) /______/ \_________ \
| / / \ / \
\ \^\\ \ / \ /
\ || \______________/ _-_ //\__//
\ ||------_-~~-_ ------------- \ --/~ ~\ || __/)
~-----||====/~ |==================| |/~~~~~
(_(__/ ./ / \_\ \.
(_(___/ \_____)_)''')
如果这很容易解决,但我很愚蠢,对不起。我只是一个初学者。 ;)
这是我的代码(http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.qrc0001m/index.html也可用):
import random
import os
import time
import sys
mageLvl = 1
def exit():
sys.exit()
def refreshScreen():
clear = lambda: os.system('cls')
clear()
def titleScreen():
print(" _ ___ _ _ ___ _ ")
print(" | |__ \ (_) | | |__ \| |")
print(" | | ) |_ ___ ______ _ _ __ __| |___ ) | |")
print(" | | / /\ \ /\ / / |_ / _` | '__/ _` / __|/ /| |")
print(" |_||_| \ V V /| |/ / (_| | | | (_| \__ \_| |_|")
print(" (_)(_) \_/\_/ |_/___\__,_|_| \__,_|___(_) (_)")
print(" ")
startOrExit = input("Start or exit? (y/n) ")
if(startOrExit == "y"):
refreshScreen()
loading1()
else:
exit()
refreshScreen()
def lvl1():
print(turtle1)
def character():
print(" _,._ ")
print(" .||, /_ _\\ ")
print(" \.`',/ |'L'| | ")
print(" = ,. = | -,| L ")
print(" / || \ ,-'\"/,'`. ")
print(" || ,' `,,. `. ")
print(" ,|____,' , ,;' \| | ")
print(" (3|\ _/|/' _| | ")
print(" ||/,-'' | >-'' _,\\ ")
print(" ||' ==\ ,-' ,' ")
print(" || | V \ ,| ")
print(" || | |` | ")
print(" || | | \ ")
print(" || | \ \ ")
print(" || | | \ ")
print(" || | \_,-' ")
print(" || |___,,--')_\ ")
print(" || |_| ccc/ ")
print(" || ccc/ ")
print(" || ")
turtle1 = (r'''\ ___-------___
_-~~ ~~-_
_-~ /~-_
/^\__/^\ /~ \ / \
/| O|| O| / \_______________/ \
| |___||__| / / \ \
| \ / / \ \
| (_______) /______/ \_________ \
| / / \ / \
\ \^\\ \ / \ /
\ || \______________/ _-_ //\__//
\ ||------_-~~-_ ------------- \ --/~ ~\ || __/)
~-----||====/~ |==================| |/~~~~~
(_(__/ ./ / \_\ \.
(_(___/ \_____)_)''')
def turtle():
print(" ___-------___ ")
print(" _-~~ ~~-_ ")
print(" _-~ /~-_ ")
print(" /^\__/^\ /~ \ / \ ")
print(" /| O|| O| / \_______________/ \ ")
print("| |___||__| / / \ \ ")
print("| \ / / \ \ ")
print("| (_______) /______/ \_________ \ ")
print("| / / \ / \ ")
print(" \ \^\\ \ / \ / ")
print(" \ || \______________/ _-_ //\__// ")
print(" \ ||------_-~~-_ ------------- \ --/~ ~\ || __/) ")
print(" ~-----||====/~ |==================| |/~~~~~ ")
print(" (_(__/ ./ / \_\ \. ")
print(" (_(___/ \_____)_) ")
def charName():
name = input("Enter your name: ")
print("Hello there", name, "lvl", mageLvl,"young mage!")
time.sleep(2)
lvl1()
def loading1():
for i in range(2):
print("You are a young wizard with a passion towards your fathers craft... You want to become the best and beat everyone! Survive every tournament!")
print("Loading.")
time.sleep(0.7)
print("Loading..")
time.sleep(0.7)
print("Loading...")
refreshScreen()
readyNo = input("Are you ready? (y/n): ")
if(readyNo == "y" or "yes"):
refreshScreen()
charName()
name = "no one"
titleScreen()
答案 0 :(得分:0)
给出您的代码 print_ascii_art.py
turtle = (r'''\ ___-------___
_-~~ ~~-_
_-~ /~-_
/^\__/^\ /~ \ / \
/| O|| O| / \_______________/ \
| |___||__| / / \ \
| \ / / \ \
| (_______) /______/ \_________ \
| / / \ / \
\ \^\\ \ / \ /
\ || \______________/ _-_ //\__//
\ ||------_-~~-_ ------------- \ --/~ ~\ || __/)
~-----||====/~ |==================| |/~~~~~
(_(__/ ./ / \_\ \.
(_(___/ \_____)_)''')
print(turtle)
打开命令提示符,然后在感兴趣的文件所在的文件夹中导航。
在正确的目录中后,输入:
python print_ascii_art.py
这应该可以解决您的问题。
注意::如果您只想双击就可以运行脚本,则应在代码末尾添加input()
行。这样,将打印出ascii art,并且程序将在关闭之前等待任何键盘输入。
答案 1 :(得分:0)
您忘记缩进对函数refreshScreen()
的最后一行titleScreen()
的调用(来自您的代码示例)。程序退出前刷新了屏幕,这消除了ASCII艺术。
这是更正的功能titleScreen
:
def titleScreen():
print(" _ ___ _ _ ___ _ ")
print(" | |__ \ (_) | | |__ \| |")
print(" | | ) |_ ___ ______ _ _ __ __| |___ ) | |")
print(" | | / /\ \ /\ / / |_ / _` | '__/ _` / __|/ /| |")
print(" |_||_| \ V V /| |/ / (_| | | | (_| \__ \_| |_|")
print(" (_)(_) \_/\_/ |_/___\__,_|_| \__,_|___(_) (_)")
print(" ")
startOrExit = input("Start or exit? (y/n) ")
if(startOrExit == "y"):
refreshScreen()
loading1()
else:
exit()
refreshScreen()