Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Emoji Match game challenge - chosen from list
- import os, random
- from random import shuffle, randint
- from guizero import App, Box, Picture, PushButton
- # set the path to the emoji folder on your computer
- emojis_dir = "emojis"
- # create a list of the locations of the emoji images
- emojis = [os.path.join(emojis_dir, f) for f in os.listdir(emojis_dir) if os.path.isfile(os.path.join(emojis_dir, f))]
- # shuffle the emojis
- shuffle(emojis)
- app = App("emoji match")
- # create a box to house the grid
- game_box= Box(app)
- pictures_box = Box(app, layout="grid")
- buttons_box = Box(game_box, layout="grid")
- # create an empty list to which pictures will be added
- matched = emojis.pop()
- pics = []
- for i in range(8):
- pics.append(emojis.pop())
- pics.append(matched)
- shuffle(pics)
- butts = []
- for i in range(8):
- butts.append(emojis.pop())
- butts.append(matched)
- pictures=[]
- for x in range(0,3):
- for y in range(0,3):
- # put the pictures into the list
- picture = Picture(pictures_box, grid=[x,y])
- pictures.append(picture)
- picture.image = pics.pop()
- # create an empty list to which buttons will be added
- buttons = []
- for x in range(0,3):
- for y in range(0,3):
- # put the pictures into the list
- button = PushButton(buttons_box, grid=[x,y])
- buttons.append(button)
- button.image = butts.pop()
- app.display()
Advertisement
Add Comment
Please, Sign In to add comment