Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Emoji Match game challenge - chosen from list with minutes and seconds countdown
- import os, random
- from random import shuffle, randint
- from guizero import App, Box, Picture, PushButton, Text
- from time import sleep
- def timer():
- seconds.value = int(seconds.value) - 1
- if int (seconds.value) == 0:
- seconds.value = 60
- minutes.value = int(minutes.value) - 1
- if int (minutes.value) < 0:
- seconds.cancel(timer)
- seconds.value = 0
- minutes.value = ("Game Over")
- def match_emoji(matched):
- if matched:
- result.value = "correct"
- else:
- result.value = "incorrect"
- # set the path to the emoji folder
- 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 the timer text
- info_box= Box(app)
- score = Text(info_box, text="Time: ", align="left")
- seconds = Text(info_box, text = "60", align="right")
- seconds.repeat(1000, timer)
- minutes = Text(info_box, text = "1", align="right")
- # create a box to house the grid
- game_box= Box(app)
- pictures_box = Box(app, layout="grid")
- buttons_box = Box(game_box, layout="grid")
- result = Text(app)
- 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)
- # create an empty list to which pictures will be added
- 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()
- button.update_command(match_emoji, [False])
- app.display()
Add Comment
Please, Sign In to add comment