Advertisement
davidhellam

Python: Emoji Gameplay 2

Aug 15th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.62 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. leftset=[]
  14. rightset=[]
  15.  
  16. for count in range(0,9):
  17.     leftset.append(emojis[count])
  18.     rightset.append(emojis[count+8])
  19.  
  20. shuffle(leftset)
  21. shuffle(rightset)
  22.  
  23. myemojis = []
  24.  
  25. for count in range(0,9):
  26.     myemojis.append(leftset[count])
  27.  
  28. myemojis.append(blank)
  29. myemojis.append(blank)
  30.  
  31. for count in range(0,9):
  32.     myemojis.append(rightset[count])
  33.  
  34. #print(emojis)
  35.  
  36. app = App("Emoji Match Game",width=720, height=480)
  37.  
  38. def leftselected(event_data):
  39.     pic_clicked = event_data.widget
  40.     pictures[9].image = pic_clicked.image
  41.  
  42. def rightselected(event_data):
  43.     pic_clicked = event_data.widget
  44.     pictures[10].image = pic_clicked.image
  45.  
  46.  
  47. # create a box to house the grid
  48. pictures_box = Box(app, layout="grid")
  49.  
  50. header=Text(pictures_box, text="Emoji Match Game", size=28, grid=[0,0,8,1])
  51.  
  52. # create an empty list to which pictures will be added
  53. pictures = []
  54. for x in range(0,3):
  55.     for y in range(1,4):
  56.         # put the pictures into the list
  57.         picture = Picture(pictures_box, grid=[x,y])
  58.         pictures.append(picture)
  59.  
  60. picture = Picture(pictures_box, grid=[3,4])
  61. pictures.append(picture)
  62. picture = Picture(pictures_box, grid=[4,4])
  63. pictures.append(picture)
  64.  
  65. for x in range(5,8):
  66.     for y in range(1,4):
  67.         # put the pictures into the list
  68.         picture = Picture(pictures_box, grid=[x,y])
  69.         pictures.append(picture)
  70. # for each picture in the list
  71. counter = 0
  72. for picture in pictures:
  73.     # make the picture a random emoji
  74.     pictures[counter].image = myemojis[counter]
  75.     counter=counter+1
  76.  
  77. #pictures[9].image = blank
  78. #pictures[10].image = blank
  79. #sourcepic = randrange(0,9)
  80. #copypic = randrange(11,20)
  81. #pictures[copypic].image = pictures[sourcepic].image
  82.  
  83. P1_label=Text(pictures_box, text="Player 1\nScore:", size=10, align="right",grid=[0,4])
  84. P1_score=Text(pictures_box, text="xxxx", size=20, align="left", grid=[1,4])
  85. P2_label=Text(pictures_box, text="Player 2\nScore:", size=10, align="right",grid=[5,4])
  86. P2_sore=Text(pictures_box, text="xxxx", size=20, align="left", grid=[6,4])
  87.  
  88. for count in range(0,9):
  89.     pictures[count].when_clicked = leftselected
  90.  
  91. for count in range(11,20):
  92.     pictures[count].when_clicked = rightselected
  93.  
  94.  
  95. #print(emojis)
  96. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement