我非常擅长使用python并试图开始我的最终项目以进行计算类的介绍。我正在使用Zelle graphics模块来尝试创建一个python游戏。我使用图形模块创建了一个面,我想克隆这个面并让克隆版本向右移动50个空格。我已导入时间以移动对象。
以下是相关代码:
from graphics import *
import time
def main():
win = GraphWin("Guess the Faces", 1000, 500)
win.yUp()
win.setBackground(color_rgb(20, 20, 20))
def robotFaces():
robot1 = Rectangle(Point(25, 350), Point(100, 425))
robot1.setOutline(color_rgb(0, 0, 0))
robot1.setFill(color_rgb(180, 180, 180))
robot1.draw(win)
r1eye1 = Rectangle(Point(35, 390), Point(55, 415))
r1eye1.setOutline(color_rgb(0, 0, 0))
r1eye1.setFill(color_rgb(255, 255, 255))
r1eye1.draw(win)
r1eye2 = Rectangle(Point(70, 390), Point(90, 415))
r1eye2.setOutline(color_rgb(0, 0, 0))
r1eye2.setFill(color_rgb(255, 255, 255))
r1eye2.draw(win)
r1pupil1 = Rectangle(Point(42, 390), Point(48, 408))
r1pupil1.setFill(color_rgb(0, 0, 0))
r1pupil1.draw(win)
r1pupil2 = Rectangle(Point(77, 390), Point(83, 408))
r1pupil2.setFill(color_rgb(0, 0, 0))
r1pupil2.draw(win)
r1mouth = Polygon(Point(35, 360),
Point(90, 360),
Point(90, 370),
Point(85, 370),
Point(85, 365),
Point(40, 365),
Point(40, 370),
Point(35, 370))
r1mouth.setFill(color_rgb(255, 255, 255))
r1mouth.setOutline(color_rgb(0, 0, 0))
r1mouth.draw(win)
robot2 = robot1.clone
robot2.move(50, 0)
robot2.draw(win)
r2eye1 = r1eye1.clone
r2eye1.move(50, 0)
r2eye1.draw(win)
r2eye2 = r1eye2.clone
r2eye2.move(50, 0)
r2eye2.draw(win)
r2pupil1 = r1pupil1.clone
r2pupil1.move(50, 0)
r2pupil1.draw(win)
r2pupil2 = r1pupil2.clone
r2pupil2.move(50, 0)
r2pupil2.draw(win)
r2mouth = r1mouth.clone
r2mouth.move(50, 0)
r2mouth.draw(win)
robotFaces()
win.getMouse()
win.promptClose(win.getWidth()/2, 10)
main()
我希望有一个第二个机器人面,在原来的右侧有50个空间。 实际发生的是我得到这个属性错误:
AttributeError:'function'对象没有属性'move'
我还需要做些什么来使对象移动吗?
答案 0 :(得分:1)
你没有调用克隆方法。
robot2 = robot1.clone()
将来,请将您的代码减少到证明问题所需的最低限度,然后发布完整的追溯。