Advertisement
mrFitzpatrick

EmojiGamePt3

Sep 21st, 2019
180
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.55 KB | None | 0 0
  1. #Emoji Game by Andrew Fitzpatrick
  2. import os
  3.  
  4. from random import randint, shuffle
  5. from guizero import App, Box, Text, TextBox, PushButton
  6.  
  7. def checkResult(x):
  8.     if x == emojis[randomNumFirstGrid]:
  9.         result.color = "green"
  10.         result.value = "Winner"
  11.    
  12.  
  13. # set the path to the emoji folder on your computer
  14. emojis_dir = "images"
  15.  
  16. # create a list of the locations of the emoji images
  17. emojis = [os.path.join(emojis_dir, f)
  18. for f in os.listdir(emojis_dir) if os.path.isfile(os.path.join(emojis_dir, f))]
  19. # shuffle the emojis
  20. shuffle(emojis)
  21.  
  22. app = App(width=600, height=300)
  23.  
  24. #On-screen instructions for first part of the game
  25. score = 0
  26. txt_score = Text(app, text="Your score: ")
  27. txt_score.append(score)
  28.  
  29. bigGridBox = Box(app, layout="grid")
  30.  
  31. txt_instructions = Text(bigGridBox, text="Study these 9 emojis!", grid=[0,0])
  32.  
  33. #Display first grid of emojis
  34. box1 = Box(bigGridBox, grid=[0,1], layout="grid")
  35. img1 = PushButton(box1, image=emojis[0], grid=[0,0])
  36. img2 = PushButton(box1, image=emojis[1], grid=[0,1])
  37. img3 = PushButton(box1, image=emojis[2], grid=[0,2])
  38. img4 = PushButton(box1, image=emojis[3], grid=[1,0])
  39. img5 = PushButton(box1, image=emojis[4], grid=[1,1])
  40. img6 = PushButton(box1, image=emojis[5], grid=[1,2])
  41. img7 = PushButton(box1, image=emojis[6], grid=[2,0])
  42. img8 = PushButton(box1, image=emojis[7], grid=[2,1])
  43. img9 = PushButton(box1, image=emojis[8], grid=[2,2])
  44.  
  45. randomNumFirstGrid = randint(0,8)
  46. randomNumSecondGrid = randint(9,17)
  47.  
  48. emojis[randomNumSecondGrid] = emojis[randomNumFirstGrid]
  49.  
  50. spacer = Text(bigGridBox, text="        ", grid=[1,0])
  51. spacer2 = Text(bigGridBox, text="        ", grid=[1,1])
  52.  
  53. instructions2 = Text(bigGridBox, text="Click the duplicate emoji in here!", grid=[2,0])
  54.  
  55. box2 = Box(bigGridBox, grid=[2,1], layout="grid")
  56. img10 = PushButton(box2, image=emojis[9], grid=[0,0], command=checkResult)
  57. img11 = PushButton(box2, image=emojis[10], grid=[0,1])
  58. img12 = PushButton(box2, image=emojis[11], grid=[0,2])
  59. img13 = PushButton(box2, image=emojis[12], grid=[1,0])
  60. img14 = PushButton(box2, image=emojis[13], grid=[1,1])
  61. img15 = PushButton(box2, image=emojis[14], grid=[1,2])
  62. img16 = PushButton(box2, image=emojis[15], grid=[2,0])
  63. img17 = PushButton(box2, image=emojis[16], grid=[2,1])
  64. img18 = PushButton(box2, image=emojis[17], grid=[2,2])
  65.  
  66. result = Text(app, text="")
  67.  
  68. app.display()
  69.  
  70. #a function that is called when a button is pressed, and determines whether the button showed the matching emoji
  71. #a countdown timer that tells the player when they have run out of time
  72. #a widget to keep the score.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement