Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #game start
- import play
- from random import randint
- w = play.screen.width
- h = play.screen.height
- background = play.set_backdrop("pink")
- #creating objects for the frontend
- place1 = play.new_box(color = 'light green', x = 0, y = 0, width = 100, height = 200, border_width=5, border_color='green')
- place2 = play.new_box(color = 'light green', x = 0, y = 0, width = 100, height = 200, border_width=5, border_color='green')
- place3 = play.new_box(color = 'light green', x = 0, y = 0, width = 100, height = 200, border_width=5, border_color='green')
- hello = play.new_text(words = 'Hello! Press the button to try your luck!', x = 0, y = 0, font = None, font_size=40, color = 'green')
- #==================================== ADD THIS ==============================================#
- result = play.new_text(words = 'You win!', x = 0, y = 0, font = None, font_size=40, color = 'green')
- #============================================================================================#
- button = play.new_box(color = 'yellow', x = 0, y = 0, width = 150, height = 50)
- button_text = play.new_text(words= 'Let’s go!', x = 0, y = 0, font = None, font_size = 50)
- #==================================== ADD THIS ==============================================#
- coin = play.new_text(words = '500 coins', x = 300, y = -250, font_size = 42, color = "white")
- coin.coins = 500
- attempt = play.new_text(words = "Attempts: 0", x = -300, y = -250, font_size = 36)
- attempt.num = 0
- #============================================================================================#
- #generating random numbers
- num1_text = play.new_text(words = '', x = -200, font_size = 100)
- num2_text = play.new_text(words = '', x = 0, font_size = 100)
- num3_text = play.new_text(words = '', x = 200, font_size = 100)
- @play.when_program_starts
- def start():
- place1.x = -200 # You don't need this if you have already put your (x,y) above!
- place2.x = 0
- place3.x = 200
- hello.y = 250
- result.y = -250
- button.y = 170
- button_text.y = 170
- num1_text.hide()
- num2_text.hide()
- num3_text.hide()
- result.hide() # ADD THIS IF YOU HAVE 'result'
- @play.repeat_forever
- def do():
- pass
- @button.when_clicked
- async def clicking():
- num1 = randint(0, 9)
- num2 = randint(0, 9)
- num3 = randint(0, 9)
- num1_text.words = str(num1)
- num2_text.words = str(num2)
- num3_text.words = str(num3)
- num1_text.show()
- num2_text.show()
- num3_text.show()
- if num1 == num2 == num3:
- result.words = 'You win!' # ADD THIS LINE
- coin.coins += 200 # ADD THIS LINE
- else:
- result.words = 'You lose! Try again.'
- coin.coins -= 5 # ADD THIS LINE
- attempt.num += 1 # ADD THIS LINE
- attempt.words = "Attempts: " + str(attempt.num) # ADD THIS LINE
- coin.words = str(coin.coins)+" coins" # ADD THIS LINE
- result.show() # ADD THIS IF YOU HAVE 'result'
- await play.timer(seconds=2.0)
- num1_text.hide()
- num2_text.hide()
- num3_text.hide()
- result.hide() # ADD THIS IF YOU HAVE 'result'
- play.start_program()
Advertisement
Add Comment
Please, Sign In to add comment