JAWarr

Emoji game match challenge

May 6th, 2022
865
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.38 KB | None | 0 0
  1. # Emoji Match game challenge - chosen from list
  2. import os, random
  3. from random import shuffle, randint
  4. from guizero import App, Box, Picture, PushButton
  5.  
  6. # set the path to the emoji folder on your computer
  7. emojis_dir = "emojis"
  8. # create a list of the locations of the emoji images
  9. emojis = [os.path.join(emojis_dir, f) for f in os.listdir(emojis_dir) if os.path.isfile(os.path.join(emojis_dir, f))]
  10. # shuffle the emojis
  11. shuffle(emojis)
  12.  
  13. app = App("emoji match")
  14. # create a box to house the grid
  15.  
  16. game_box= Box(app)
  17.  
  18. pictures_box = Box(app, layout="grid")
  19.  
  20. buttons_box = Box(game_box, layout="grid")
  21.  
  22. # create an empty list to which pictures will be added
  23. matched = emojis.pop()
  24. pics = []
  25. for i in range(8):
  26.     pics.append(emojis.pop())
  27. pics.append(matched)
  28. shuffle(pics)
  29.  
  30. butts = []
  31. for i in range(8):
  32.     butts.append(emojis.pop())
  33. butts.append(matched)
  34.  
  35.  
  36. pictures=[]
  37. for x in range(0,3):
  38.     for y in range(0,3):
  39.         # put the pictures into the list
  40.         picture = Picture(pictures_box, grid=[x,y])
  41.         pictures.append(picture)
  42.         picture.image = pics.pop()
  43.  
  44. # create an empty list to which buttons will be added
  45. buttons = []
  46. for x in range(0,3):
  47.     for y in range(0,3):
  48.         # put the pictures into the list
  49.         button = PushButton(buttons_box, grid=[x,y])
  50.         buttons.append(button)
  51.         button.image = butts.pop()
  52.  
  53. app.display()
  54.  
Advertisement
Add Comment
Please, Sign In to add comment