"""
Program: TODO
Author: TODO
Description: TODO
"""
from match_graphics import *
from random import seed, shuffle
def shuffle_cards():
'''
Generates a shuffled deck of cards. When done, cards[i][j] is the name of the card in
row i and column j. It is a 5x5 grid comprised of 12 card pairs and one extra card.
TODO (Final): document the parameters and return value
'''
# seed the random number generator
seed()
# TODO (Checkpoint A): implement the below logic
#
# The idea of how we shuffle is the following:
# (1) shuffle the images
# (2) pick out 12 of the images (these are the ones that will be pairs)
# (3) pick out the 'extra image' (this is the one that will have no pair)
# (4) create a list with 2 of each pair and the extra image
# (5) shuffle that list
# TODO (Checkpoint A): fix below.
#
# use the list of these 25 shuffled cards to build a 5x5 array of cards
cards = []
for i in range(5):
row = []
for j in range(5):
item = images[0] # currently, array is the same card, over and over
row.append(item)
cards.append(row)
return cards
def show_card(win, card_name, i, j):
'''
Shows the card at row i and column j in the 5x5 grid in the window.
TODO (Final): document the parameters and return value
'''
# TODO (Checkpoint A ): finish this function as described
#
# Draw a rectangle with a yellow border of line width 5
# at the location associated with card (i,j)
# Ex: card (0,0) has upper-right corner (XMARGIN, YMARGIN) and
# lower-right corner (XMARGIN+CARD_WIDTH, YMARGIN+CARD_HEIGHT)
# TODO (Checkpoint A):
# Draw the image for card_name at the center of the rectangle.
return
def hide_card(win, i, j):
'''
Takes the window and cards and hides the card at row i and column j.
TODO (Final): document the parameters and return value
'''
# TODO (Checkpoint B): finish this function as described
return
def mark_card(win, i, j):
'''
Takes the window and cards and marks the card at row i and column j with a red X.
TODO (Final): document the parameters and return value
'''
# TODO (Checkpoint B): finish this function as described
return
def get_col(x):
'''
Takes the x-coordinate value and returns the column.
If the x coordinate is outside the board, returns -1.
TODO (Final): document the parameters and return value
'''
# TODO (Checkpoint B): finish this function as described
return 0
def get_row(y):
'''
Takes the y-coordinate value and returns the row.
If the y-coordinate is outside the board, returns -1.
TODO (Final): document the parameters and return value
'''
# TODO (Checkpoint B): finish this function as described
return 0
def main():
'''
TODO (Final): describe how your main function works.
'''
# generate game window
win = create_board()
# shuffle the cards
cards = shuffle_cards()
# draw the 5x5 board with the cards on it
for i in range(5):
for j in range(5):
# For Checkpoint A, we place them face-up
show_card(win, cards[i][j], i, j)
# For Checkpoint B, edit to place them face-down
# TODO (Checkpoint B): implement the below logic
# in a forever-loop:
# get a mouse click
# figure out which card was clicked
# if this is a 'first pick':
# show the card
# else, if this is a 'second pick':
# show the card
# wait 1 second
# if we have a 'matched pair':
# mark both pairs as matched (Final Code)
# else:
# hide both cards
# if we just won:
# call the you_won function.
win.getMouse()
main()