Advertisement
mrFitzpatrick

EmojiGamePt5

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