shh_algo_PY

Slot Machine

Mar 4th, 2022 (edited)
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.10 KB | None | 0 0
  1. #game start
  2. import play
  3. from random import randint
  4.  
  5. w = play.screen.width
  6. h = play.screen.height
  7.  
  8. background = play.set_backdrop("pink")
  9.  
  10. #creating objects for the frontend
  11. place1 = play.new_box(color = 'light green', x = 0, y = 0, width = 100, height = 200, border_width=5, border_color='green')
  12. place2 = play.new_box(color = 'light green', x = 0, y = 0, width = 100, height = 200, border_width=5, border_color='green')
  13. place3 = play.new_box(color = 'light green', x = 0, y = 0, width = 100, height = 200, border_width=5, border_color='green')
  14.  
  15. hello = play.new_text(words = 'Hello! Press the button to try your luck!', x = 0, y = 0, font = None, font_size=40, color = 'green')
  16.  
  17. #==================================== ADD THIS ==============================================#
  18. result = play.new_text(words = 'You win!', x = 0, y = 0, font = None, font_size=40, color = 'green')
  19. #============================================================================================#
  20.  
  21. button = play.new_box(color = 'yellow', x = 0, y = 0, width = 150, height = 50)
  22. button_text = play.new_text(words= 'Let’s go!', x = 0, y = 0, font = None, font_size = 50)
  23.  
  24. #==================================== ADD THIS ==============================================#
  25. coin = play.new_text(words = '500 coins', x = 300, y = -250, font_size = 42, color = "white")
  26. coin.coins = 500
  27.  
  28. attempt = play.new_text(words = "Attempts: 0", x = -300, y = -250, font_size = 36)
  29. attempt.num = 0
  30. #============================================================================================#
  31.  
  32. #generating random numbers
  33. num1_text = play.new_text(words = '', x = -200, font_size = 100)
  34. num2_text = play.new_text(words = '', x = 0, font_size = 100)
  35. num3_text = play.new_text(words = '', x = 200, font_size = 100)
  36.  
  37. @play.when_program_starts
  38. def start():
  39.     place1.x = -200         # You don't need this if you have already put your (x,y) above!
  40.     place2.x = 0
  41.     place3.x = 200
  42.     hello.y = 250
  43.     result.y = -250
  44.     button.y = 170
  45.     button_text.y = 170
  46.  
  47.     num1_text.hide()
  48.     num2_text.hide()
  49.     num3_text.hide()
  50.     result.hide()           # ADD THIS IF YOU HAVE 'result'
  51.  
  52. @play.repeat_forever
  53. def do():
  54.     pass
  55.  
  56. @button.when_clicked
  57. async def clicking():
  58.     num1 = randint(0, 9)
  59.     num2 = randint(0, 9)
  60.     num3 = randint(0, 9)
  61.  
  62.     num1_text.words = str(num1)
  63.     num2_text.words = str(num2)
  64.     num3_text.words = str(num3)
  65.  
  66.     num1_text.show()
  67.     num2_text.show()
  68.     num3_text.show()
  69.     if num1 == num2 == num3:
  70.         result.words = 'You win!'               # ADD THIS LINE
  71.         coin.coins += 200                       # ADD THIS LINE
  72.     else:
  73.         result.words = 'You lose! Try again.'
  74.         coin.coins -= 5                         # ADD THIS LINE
  75.     attempt.num += 1                            # ADD THIS LINE
  76.     attempt.words = "Attempts: " + str(attempt.num) # ADD THIS LINE
  77.     coin.words = str(coin.coins)+" coins"           # ADD THIS LINE
  78.     result.show()                               # ADD THIS IF YOU HAVE 'result'
  79.    
  80.     await play.timer(seconds=2.0)
  81.     num1_text.hide()
  82.     num2_text.hide()
  83.     num3_text.hide()
  84.     result.hide()                               # ADD THIS IF YOU HAVE 'result'
  85.  
  86. play.start_program()
  87.  
  88.  
Advertisement
Add Comment
Please, Sign In to add comment