当我匹配所有对的时候,我怎么才能让我的记忆游戏结束呢

最喜欢的我几乎所有的代码都完成了。我的问题是,我在定义点击()下实现的计数器不起作用。我有16个项目所以当我的颜色比较时,我想要的是8次
import graphics as G
import random

WINDOW_WIDTH = 200
WINDOW_HEIGHT = 200
win = G.GraphWin(‘Memory Game’, WINDOW_WIDTH, WINDOW_HEIGHT)

def run_game():
random_assignment()
clicks()
#if count == 8:
# game_running = False
#if clicks() == True:
# count += 1
#if count == 8:
# game_running = False
#if game_running = False:

def clicks():
game_running = True
while game_running:
first_click = win.getMouse()
x_cell1 = int(first_click.getX()//50)
y_cell1 = int(first_click.getY()//50)
(first_r, first_c) = click_loc(first_click)
first_r.undraw()
second_click = win.getMouse()
x_cell2 = int(second_click.getX()//50)
y_cell2 = int(second_click.getY()//50)
(second_r, second_c) = click_loc(second_click)
second_r.undraw()
rgb1 = circles[y_cell1][x_cell1]
rgb2 = circles[y_cell2][x_cell2]
count = 0
if rgb1[0] == rgb2[0] and rgb1[1] == rgb2[1] and rgb1[2] == rgb2[2]:
count += 1
elif count == 8:
game_running = False
else:
first_r.draw(win)
second_r.draw(win)
win.close()
def click_loc(click):
x_cell = int(click.getX()//50)
y_cell = int(click.getY()//50)
(r, c) = board[x_cell][y_cell]
return (r, c)

run_game()

猜你喜欢

转载自blog.csdn.net/weixin_43198791/article/details/82773614