not really known
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.5 KiB

  1. import random
  2. print ("<h1>👥 Memorize</h1><hr>", end='')
  3. pairs = ['🐇','🐈','🐒','🐋','🐎','🐍','🐢','🐝','🐂']
  4. count = len(pairs)
  5. nums = list(random.shuffle(pairs))\
  6. .concat(list(random.shuffle(pairs)))
  7. def mem_button(num):
  8. button = document.createElement('button')
  9. button.innerHTML = '&nbsp;'
  10. button.onclick = show(num)
  11. return (button)
  12. for num in nums:
  13. document.body.appendChild(mem_button(num))
  14. window.last_btn = Object()
  15. def show(num):
  16. return def():
  17. button = this
  18. button.innerHTML = num
  19. if button==window.last_btn:
  20. return
  21. if window.last_btn.innerHTML==button.innerHTML:
  22. button.disabled = True
  23. window.last_btn.disabled = True
  24. button.innerHTML=window.last_btn.innerHTML=num
  25. window.last_btn = Object()
  26. window.count = count - 1
  27. if count==0:
  28. win()
  29. return
  30. window.last_btn.innerHTML = '&nbsp;'
  31. window.last_btn = button
  32. def win():
  33. print('<span id="prize">🏆</h1>')
  34. print('<h2>Congratulations!</h2>')
  35. for b in document.getElementsByTagName('button'):
  36. b.style.display = 'none'
  37. print('''<style>\
  38. body {\
  39. text-align: center; }\
  40. #prize {\
  41. font-size:100pt;\
  42. font-family: Noto Emoji;\
  43. }\
  44. button {\
  45. font-size: 48pt;\
  46. font-family: Noto Emoji;\
  47. margin: 1px;\
  48. width:120px;\
  49. height:120px;\
  50. display: inline;\
  51. }</style>'''