| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
checkmark = Actor('checkmark') |
| 11 |
steve = Actor('card_back', (50, 50)) |
| 12 |
steve.topleft = (0, 0) |
| 13 |
|
| 14 |
import random |
| 15 |
import time |
| 16 |
|
| 17 |
COLS = 4 |
| 18 |
ROWS= 3 |
| 19 |
IMSIZE = 200 |
| 20 |
STATUS = [] |
| 21 |
ignore = [] |
| 22 |
|
| 23 |
|
| 24 |
START_IMAGES= [ "im"+str(i+1) for i in range(COLS*ROWS//2)]*2 |
| 25 |
random.shuffle(START_IMAGES) |
| 26 |
|
| 27 |
STATUS=[] |
| 28 |
|
| 29 |
board = [] |
| 30 |
for row in range(ROWS): |
| 31 |
new_row=[] |
| 32 |
for col in range(COLS): |
| 33 |
image_name = START_IMAGES.pop() |
| 34 |
temp=Actor(image_name, (col*IMSIZE, row*IMSIZE)) |
| 35 |
temp.image_name = image_name |
| 36 |
temp.topleft=(col*IMSIZE, row*IMSIZE) |
| 37 |
new_row.append(temp) |
| 38 |
board.append(new_row) |
| 39 |
|
| 40 |
def draw(): |
| 41 |
screen.clear() |
| 42 |
for row in range(ROWS): |
| 43 |
for col in range(COLS): |
| 44 |
if (row, col) in ignore: |
| 45 |
checkmark.topleft = IMSIZE*col, IMSIZE*row |
| 46 |
checkmark.draw() |
| 47 |
elif (row, col) in STATUS: |
| 48 |
board[row][col].draw() |
| 49 |
else: |
| 50 |
steve.topleft = IMSIZE*col, IMSIZE*row |
| 51 |
steve.draw() |
| 52 |
|
| 53 |
def findTile(pos): |
| 54 |
y, x = pos |
| 55 |
result = x // IMSIZE , y // IMSIZE |
| 56 |
return result |
| 57 |
|
| 58 |
def showTile(): |
| 59 |
pass |
| 60 |
|
| 61 |
|
| 62 |
def on_mouse_down(pos, button): |
| 63 |
if len(STATUS) == 2: |
| 64 |
return |
| 65 |
if pos in ignore: |
| 66 |
return |
| 67 |
if button == mouse.LEFT and (pos): |
| 68 |
|
| 69 |
coords = findTile(pos) |
| 70 |
if coords not in STATUS: |
| 71 |
STATUS.append(coords) |
| 72 |
if len(STATUS) == 1: |
| 73 |
pass |
| 74 |
elif len(STATUS) == 2: |
| 75 |
(x1, y1), (x2, y2) = STATUS |
| 76 |
if board[x1][y1].image_name == board[x2][y2].image_name: |
| 77 |
print("Success sound") |
| 78 |
|
| 79 |
for pos in STATUS: |
| 80 |
ignore.append(pos) |
| 81 |
else: |
| 82 |
print("Failure sound") |
| 83 |
clock.schedule_unique(next_turn, 2.0) |
| 84 |
|
| 85 |
def next_turn(): |
| 86 |
del STATUS[:] |
| 87 |
|