Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Emoji Game by Andrew Fitzpatrick
- import os
- from time import sleep
- from random import randint, shuffle
- from guizero import App, Box, Text, TextBox, PushButton
- app = App(width=600, height=400)
- def countdown():
- if int(timer.value) == 0:
- txt_status.value = "Game Over!"
- else:
- timer.value = int(timer.value) - 1
- timer = Text(app, text="Get ready!", size=24)
- def checkResult(x):
- print(x)
- if x == emojis[randomNumFirstGrid]:
- result.color = "green"
- result.value = "Winner"
- # set the path to the emoji folder on your computer
- emojis_dir = "images"
- # 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)
- #On-screen instructions for first part of the game
- score = 0
- score = int(score)
- txt_score = Text(app, text="Your score: ")
- txt_score.append(score)
- txt_status = Text(app, text="You're in play!", color="Green")
- bigGridBox = Box(app, layout="grid")
- txt_instructions = Text(bigGridBox, text="Study these 9 emojis!", grid=[0,0])
- #Display first grid of emojis
- box1 = Box(bigGridBox, grid=[0,1], layout="grid")
- img1 = PushButton(box1, image=emojis[0], grid=[0,0])
- img2 = PushButton(box1, image=emojis[1], grid=[0,1])
- img3 = PushButton(box1, image=emojis[2], grid=[0,2])
- img4 = PushButton(box1, image=emojis[3], grid=[1,0])
- img5 = PushButton(box1, image=emojis[4], grid=[1,1])
- img6 = PushButton(box1, image=emojis[5], grid=[1,2])
- img7 = PushButton(box1, image=emojis[6], grid=[2,0])
- img8 = PushButton(box1, image=emojis[7], grid=[2,1])
- img9 = PushButton(box1, image=emojis[8], grid=[2,2])
- randomNumFirstGrid = randint(0,8)
- randomNumSecondGrid = randint(9,17)
- emojis[randomNumSecondGrid] = emojis[randomNumFirstGrid]
- print(emojis[randomNumFirstGrid])
- spacer = Text(bigGridBox, text=" ", grid=[1,0])
- spacer2 = Text(bigGridBox, text=" ", grid=[1,1])
- instructions2 = Text(bigGridBox, text="Click the duplicate emoji in here!", grid=[2,0])
- box2 = Box(bigGridBox, grid=[2,1], layout="grid")
- img10 = PushButton(box2, image=emojis[9], grid=[0,0], command=checkResult)
- img11 = PushButton(box2, image=emojis[10], grid=[0,1])
- img12 = PushButton(box2, image=emojis[11], grid=[0,2])
- img13 = PushButton(box2, image=emojis[12], grid=[1,0])
- img14 = PushButton(box2, image=emojis[13], grid=[1,1])
- img15 = PushButton(box2, image=emojis[14], grid=[1,2])
- img16 = PushButton(box2, image=emojis[15], grid=[2,0])
- img17 = PushButton(box2, image=emojis[16], grid=[2,1])
- img18 = PushButton(box2, image=emojis[17], grid=[2,2])
- result = Text(app, text="")
- timer.value = 20
- timer.repeat(1000, countdown)
- app.display()
- #a function that is called when a button is pressed, and determines whether the button showed the matching emoji
- #a countdown timer that tells the player when they have run out of time
- #a widget to keep the score.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement