USE PYTHON Memory Game 1 You will have two arrays that are 4
USE PYTHON
Memory Game:
1. You will have two arrays that are 4 by 4.
2. One array will be called isVisible and contain all False values
3. The other array will be labeled board and contain pair of symbols:
Symbols are “$”,”@”,”!”,”%”,”^”,”&”,”*” and “~”
4. The symbols will be randomly placed.
Randomly select a row and column.
1. If that column or row is not initialized assign that symbol.
2. Hint: Use a method for this and pass in the 2D array.
2. Once this is done print both 2D arrays in square form (Using for loops) to make sure your game is setup correctly.
Game Play:
 1. The player starts with 10 points
2. Print the rows and columns around the 2D array.
1 2 3 4
1# # # #
2# # # #
3# # # #
4# # # #
2. IF the corresponding row/column in is Visible is equal to false you will print a “#” mark.
3. Otherwise, you will print the symbol that is in the board array.
4. Ask the user to select a row and column. (Remember you have to subtract 1 from each of the values)
5. Set the element at the entered row/column in isVisible to True
6. Redraw the board.
7. Ask the user to enter another row/column. Set the corresponding element in isVisible to True
8. Redraw the board.
9. IF the two elements in Board are the same increase the score by 1.
10. If the two elements in Board are NOT the same decrease the score by 1. Set the two elements in isVisible back to false.
11. While score is greater than 0 OR there are False values in isVisisble.
Solution
import simplegui
 import random
clk1 = 0
 clk2 = 0
# helper function to initialize globals
 def nw_gmme():
 global dck_crds, expld, trns, stat
 stat = 0
 trns = 0
 dck_crds = [i%8 for i in range(16)]
 expld = [False for i in range(16)]
   
 random.shuffle(dck_crds)
 label.set_text(\"Turns = \" + str(trns))
 pass
# define event handlers
 def mouseclick(pos):
 # add game stat logic here
 global stat, expld, clk1, clk2, trns, dck_crds
 choice = int(pos[0] / 50)
 if stat == 0:
 stat = 1
 clk1 = choice
 expld[clk1] = True
 elif stat == 1:
 if not expld[choice]:
 stat = 2
 clk2 = choice
 expld[clk2] = True
 trns += 1
 elif stat == 2:
 if not expld[choice]:
 if dck_crds[clk1] == dck_crds[clk2]:
 pass
 else:
 expld[clk1] = False
 expld[clk2] = False
 clk1 = choice
 expld[clk1] = True
 stat = 1   
 label.set_text(\"Turns = \" + str(trns))
 pass
   
   
 # cards are logically 50x100 pixels in size
 def drww(canvas):
 for i in range(16):
 if expld[i]:
 canvas.draw_text(str(dck_crds[i]), (50*i+10, 60), 40, \"Pink\")
 else:
 canvas.draw_polygon([(50*i, 0), (50*i, 100), (50*i + 50, 0), (50*i + 50, 100)], 3, \"White\", \"Grey\")
 pass
# create frame and add a button and labels
 frame = simplegui.cret_frm(\"Memory\", 800, 100)
 frame.add_button(\"Reset\", nw_gmme, 150)
 label = frame.add_label(\"Turns = 0\")
# register event handlers
 frame.set_mouseclick_handler(mouseclick)
 frame.set_draw_handler(drww)
# get things rolling
 nw_gmme()
 frame.start()



