我有一个关于Python入门课程的最后一个项目,过去的几天我一直在研究,试图弄清楚如何通过使检查器块返回我在空白框中产生的点击来使检查器块移动。我知道我必须使用中点公式,但我只是不知道将得到的值放在哪里。我已经绘制了游戏板和棋子。 另外,我尝试实现一些我在网上看到的代码,但是根本无法使用。 继承人代码:
#Video_Game.py
from time import sleep
from graphics import *
import math
#creating graphics window
myWin = GraphWin("My Checkerboard",400,400)
myWin.setBackground("dark gray")
color =("red")
#Drawing checkerboard squares
for y in range(8):
for x in range(8):
point1 = Point(x*100,y*100)
point2 = Point(x*100+100,y*100+100)
myRect = Rectangle(point1,point2)
myRect.setFill(color)
myRect.draw(myWin)
if color == "red":
color = "black"
else:
color = "red"
if color == "red":
color = "black"
else:
color = "red"
#Drawing Red Checkerboard pieces
myList1 = []
xpos = 150
for x in range(2):
myList1.append(Circle(Point(xpos+(200*x),50),26))
myList1[x].setFill("red")
myList1[x].setOutline("blue")
myList1[x].setWidth(7)
myList1[x].draw(myWin)
#Drawing Black Checkerboard pieces
myList2 = []
xpos = 50
for x in range(2):
myList2.append(Circle(Point(xpos+(200*x),350),26))
myList2[x].setFill("black")
myList2[x].setOutline("white")
myList2[x].setWidth(7)
myList2[x].draw(myWin)
#Moving pieces
p = cir.getCenter()
p2 = win.getMouse()
dx = 1
dy = 1
keepGoing = True
while keepGoing == True:
d = 400
cir.move(dx,dy)
p = cir.getCenter()
p2 = win.checkMouse()
if ((p-getX() - 30)<= 0) or ((p-getX) + 30)>= 400)):
dx = dx
if ((p-getY() - 30)<= 0) or ((p-getY) + 30)>= 400)):
dy = dy
p3 = win.checkMouse()
if p3 != p2:
keepGoing = False
#Moving Checker pieces
for x in range(50,450,100):
myList1[0].move(100,100)
myList1[1].move(200,100)
myList[2].move(150,150)
myList
#Clicking to make piece move
while x > 5:
if
我正在使用John Zelle编写的graphics.py库。我的老师限制我们使用pygame和tkinter。我将不胜感激。