Python 如何让乌龟一次画一步
我有一个刽子手游戏,我想每写错一个字母就画一部分刽子手,但我不知道如何一次画一步乌龟 这就是我所拥有的:Python 如何让乌龟一次画一步,python,function,turtle-graphics,Python,Function,Turtle Graphics,我有一个刽子手游戏,我想每写错一个字母就画一部分刽子手,但我不知道如何一次画一步乌龟 这就是我所拥有的: def drawsturtle(userInput,word): 然后,我必须采取以下步骤: import turtle hangman = turtle.Turtle() hangman.circle(45) hangman.right(90) hangman.forward(150) .... 我如何编写代码,以便绘制这些步骤中不在word中的每个用户输入? 谢谢大家一旦你有了检测到
def drawsturtle(userInput,word):
然后,我必须采取以下步骤:
import turtle
hangman = turtle.Turtle()
hangman.circle(45)
hangman.right(90)
hangman.forward(150)
....
我如何编写代码,以便绘制这些步骤中不在word中的每个用户输入?
谢谢大家一旦你有了检测到猜错字母的代码,你可以调用
海龟。write
方法写出不正确的字母
请参阅下面的方法签名:
turtle.write(arg, move=False, align="left", font=("Arial", 8, "normal"))
Parameters:
arg – object to be written to the TurtleScreen
move – True/False
align – one of the strings “left”, “center” or right”
font – a triple (fontname, fontsize, fonttype)
Write text - the string representation of arg - at the current turtle position according to align (“left”, “center” or right”) and with the given font. If move is true, the pen is moved to the bottom-right corner of the text. By default, move is False.
有关详细信息:
如果您定义了一个计数变量来跟踪错误猜测的数量,那么您可以定义一个函数来提取所需的部分。在下面的例子中,我假设了3个错误的猜测。我添加了3秒钟的暂停,以便您可以看到输出
import turtle, time
hangman = turtle.Turtle()
def draw_hangman(count):
if count >= 1:
hangman.circle(45)
if count >= 2:
hangman.right(90)
if count == 3:
hangman.forward(150)
time.sleep(3)
draw_hangman(3)
我想画一个刽子手的一部分,每次它猜错字母,当他猜错字母的时候,我得到了,但不能让乌龟只画一部分,像头或手臂。。。