【发布时间】:2016-07-29 15:38:16
【问题描述】:
我正在尝试在 python 中制作 Connect 4,但我不知道如何获取屏幕点击的坐标,以便我可以使用它们。现在,我想画板,然后有人点击,画一个点,然后回到 while 循环的顶部,擦屏幕,然后再试一次。我尝试了几个不同的选项,但似乎没有一个适合我。
def play_game():
"""
When this function runs, allows the user to play a game of Connect 4
against another person
"""
turn = 1
is_winner = False
while is_winner == False:
# Clears screen
clear()
# Draws empty board
centers = draw_board()
# Decides whose turn it is, change color appropriately
if turn % 2 == 0:
color = RED
else:
color = BLACK
# Gets coordinates of click
penup()
onscreenclick(goto)
dot(HOLE_SIZE, color)
turn += 1
【问题讨论】:
-
您尝试过哪些选项?另外,您使用的是什么 GUI 库?不知道这一点,很难回答。
-
@wirefox 大概是乌龟——至少标题是这么说的
-
@WayneWerner 是的,对我来说,乌龟并没有明确地解析为 GUI 库;他可能一直在谈论通用海龟代理并使用其他东西来绘制