我正在开发一个涉及游戏的程序,该程序将根据用户输入更改笑脸(使用乌龟绘制)。 程序启动时,将绘制一张规则的笑脸(黄色的脸,黑色的眼睛和嘴巴,微笑)。 然后,通过以下菜单提示用户更改面孔:

换脸

1)让我皱眉

2)让我生气

3)让我的眼睛变蓝

0)退出

输入选择:

如果用户选择1,则将笑脸重新绘制,皱眉变成微笑,菜单将更改为:

换脸

1)让我微笑

2)让我生气

3)让我的眼睛变蓝

0)退出

输入选择:

如果用户选择2,将重新绘制笑脸并用皱眉填充红色,菜单将更改为:

换脸

1)让我微笑

2)让我开心

3)让我的眼睛变蓝

0)退出

输入选择:

我很难根据用户输入更改笑脸。 我该如何改变笑脸?

据我所知,请帮助!:

import turtle
turtle.up()
turtle.goto(0, -100) # center circle around origin
turtle.down()
turtle.begin_fill()
turtle.fillcolor("yellow") # draw head
turtle.circle(100)
turtle.end_fill()
turtle.up()
turtle.goto(-67, -40)
turtle.setheading(-60)
turtle.width(5)
turtle.down()
turtle.circle(80, 120) # draw smile
turtle.fillcolor("black")
for i in range(-35, 105, 70):
turtle.up()
turtle.goto(i, 35)
turtle.setheading(0)
turtle.down()
turtle.begin_fill()
turtle.circle(10) # draw eyes
turtle.end_fill()
class Face:
def __init__(self):
self.__smile = True
self.__happy = True
self.__dark_eyes = True
def draw_face(self):
turtle.clear()
self.__draw_head()
self.__draw_eyes()
self.__draw_mouth()
def is_smile(self):
self.__smile = False
def is_happy(self):
self.__happy = False
def is_dark_eyes(self):
self.__dark_eyes = False
def __draw_head(self):
self.__draw_head
def __draw_eyes(self):
self.__draw_eyes
def __draw_mouth(self):
self.__draw_mouth
def change_mouth(self):
self.__smile = not self.__smile
self.draw_face()
def change_emotion(self):
self.__happy = not self.__happy
self.draw_face()
def change_eyes(self):
self.__dark_eyes = not self.__dark_eyes
self.draw_face()
def main():
face = Face()
face.draw_face()
done = False
while not done:
print("Change My Face")
mouth = "frown" if face.is_smile() else "smile"
emotion = "angry" if face.is_happy() else "happy"
eyes = "blue" if face.is_dark_eyes() else "black"
print("1) Make me", mouth)
print("2) Make me", emotion)
print("3) Make my eyes", eyes)
print("0) Quit")
menu = int(input("Enter a selection: "))
if menu == 1:
face.change_mouth()
face.draw_face()
elif menu == 2:
face.change_emotion()
face.draw_face()
elif menu == 3:
face.change_eyes()
face.draw_face()
else:
break
print("Thanks for Playing")
turtle.hideturtle()
turtle.done()
main()

如何实现乌龟代码,以便可以根据用户输入绘制笑脸?