Advertisement
davidhellam

Python: Emoji Gameplay 1

Aug 15th, 2019
153
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.26 KB | None | 0 0
  1. import os
  2. from random import shuffle,randrange
  3. from guizero import App, Box, Picture, Text
  4.  
  5. # set the path to the emoji folder on your computer
  6. emojis_dir = "emojis"
  7. # create a list of the locations of the emoji images
  8. emojis = [os.path.join(emojis_dir, f) for f in os.listdir(emojis_dir) if os.path.isfile(os.path.join(emojis_dir, f))]
  9. # shuffle the emojis
  10. shuffle(emojis)
  11. blank = "25fb.png"
  12.  
  13. #print(emojis)
  14.  
  15. app = App("Emoji Match Game",width=720, height=480)
  16.  
  17. def leftselected(event_data):
  18.     pic_clicked = event_data.widget
  19.     pictures[9].image = pic_clicked.image
  20.  
  21. def rightselected(event_data):
  22.     pic_clicked = event_data.widget
  23.     pictures[10].image = pic_clicked.image
  24.  
  25.  
  26. # create a box to house the grid
  27. pictures_box = Box(app, layout="grid")
  28.  
  29. header=Text(pictures_box, text="Emoji Match Game", size=28, grid=[0,0,8,1])
  30.  
  31. # create an empty list to which pictures will be added
  32. pictures = []
  33. for x in range(0,3):
  34.     for y in range(1,4):
  35.         # put the pictures into the list
  36.         picture = Picture(pictures_box, grid=[x,y])
  37.         pictures.append(picture)
  38.  
  39. picture = Picture(pictures_box, grid=[3,4])
  40. pictures.append(picture)
  41. picture = Picture(pictures_box, grid=[4,4])
  42. pictures.append(picture)
  43.  
  44. for x in range(5,8):
  45.     for y in range(1,4):
  46.         # put the pictures into the list
  47.         picture = Picture(pictures_box, grid=[x,y])
  48.         pictures.append(picture)
  49. # for each picture in the list
  50. counter = 0
  51. for picture in pictures:
  52.     # make the picture a random emoji
  53.     pictures[counter].image = emojis[counter]
  54.     counter=counter+1
  55.  
  56. pictures[9].image = blank
  57. pictures[10].image = blank
  58. sourcepic = randrange(0,9)
  59. copypic = randrange(11,20)
  60. pictures[copypic].image = pictures[sourcepic].image
  61.  
  62. P1_label=Text(pictures_box, text="Player 1\nScore:", size=10, align="right",grid=[0,4])
  63. P1_score=Text(pictures_box, text="xxxx", size=20, align="left", grid=[1,4])
  64. P2_label=Text(pictures_box, text="Player 2\nScore:", size=10, align="right",grid=[5,4])
  65. P2_sore=Text(pictures_box, text="xxxx", size=20, align="left", grid=[6,4])
  66.  
  67. for count in range(0,9):
  68.     pictures[count].when_clicked = leftselected
  69.  
  70. for count in range(11,20):
  71.     pictures[count].when_clicked = rightselected
  72.  
  73.  
  74. #print(emojis)
  75. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement