Advertisement
davidhellam

Python: Emoji Game Layout 1

Aug 15th, 2019
282
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.88 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. # create a box to house the grid
  17. pictures_box = Box(app, layout="grid")
  18.  
  19. header=Text(pictures_box, text="Emoji Match Game", size=28, grid=[0,0,8,1])
  20.  
  21. # create an empty list to which pictures will be added
  22. pictures = []
  23. for x in range(0,3):
  24.     for y in range(1,4):
  25.         # put the pictures into the list
  26.         picture = Picture(pictures_box, grid=[x,y])
  27.         pictures.append(picture)
  28.  
  29. picture = Picture(pictures_box, grid=[3,4])
  30. pictures.append(picture)
  31. picture = Picture(pictures_box, grid=[4,4])
  32. pictures.append(picture)
  33.  
  34. for x in range(5,8):
  35.     for y in range(1,4):
  36.         # put the pictures into the list
  37.         picture = Picture(pictures_box, grid=[x,y])
  38.         pictures.append(picture)
  39. # for each picture in the list
  40. counter = 0
  41. for picture in pictures:
  42.     # make the picture a random emoji
  43.     pictures[counter].image = emojis[counter]
  44.     counter=counter+1
  45.  
  46. pictures[9].image = blank
  47. pictures[10].image = blank
  48. sourcepic = randrange(0,9)
  49. copypic = randrange(11,20)
  50. pictures[copypic].image = pictures[sourcepic].image
  51.  
  52. P1_label=Text(pictures_box, text="Player 1\nScore:", size=10, align="right",grid=[0,4])
  53. P1_score=Text(pictures_box, text="xxxx", size=20, align="left", grid=[1,4])
  54. P2_label=Text(pictures_box, text="Player 2\nScore:", size=10, align="right",grid=[5,4])
  55. P2_sore=Text(pictures_box, text="xxxx", size=20, align="left", grid=[6,4])
  56.  
  57.  
  58.  
  59. #print(emojis)
  60. app.display()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement