import simpleguitk as simplegui
import pickle
import random
import time
import math
#
画布的尺寸
WIDTH = 480
HEIGHT = 150
#
牌的尺寸
CARD_WIDTH = 60
CARD_HEIGHT = 100
cards = []
#
保存
4
对牌的列表
flipped_cards = []
#
记录翻过的牌
steps = 0
all_characters= ['A','B','C','D','E','F','G','H','I','J','K','L','M',
'N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
#
初始化一组字母牌
def init_cards():
global all_characters, cards
cards.clear()
random.shuffle(all_characters)
for i in range(4):
one_card = all_characters.pop();
#
注意:
cards
中的元素也是列表。该列表的第一个元素是某个字母,
#
第二个元素表示该牌是否被翻过来,
0
表示没翻过来,
1
表示翻过来。
cards.append([one_card, 0])
cards.append([one_card, 0])
random.shuffle(cards)
def new_game():
global steps
flipped_cards.clear()
steps = 0
init_cards()
def draw(canvas):
#
显示步数
canvas.draw_text('
步数:
'+str(steps), [0, HEIGHT], 12, 'White')
#
显示牌
for i, card in enumerate(cards):
point_list = [(i*CARD_WIDTH, 0), ((i+1)*CARD_WIDTH, 0), ((i+1)*CARD_WIDTH, CARD_HEIGHT), (i*CARD_WIDTH,
CARD_HEIGHT)]
char_position = [(i+0.25)*CARD_WIDTH, CARD_HEIGHT*0.8]
if card[1] == 0: