Advertisement
mrFitzpatrick

EmojiGamePt4

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