Advertisement
Guest User

Untitled

a guest
Jul 22nd, 2019
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.62 KB | None | 0 0
  1. # -*- coding: utf-8 -*-
  2. """
  3. Created on Fri Jul 19 12:54:39 2019
  4.  
  5. @author: Llama
  6. """
  7. import keyboard
  8. import os
  9. import time
  10. import sys
  11. import colorama
  12. import random
  13. import winregistry
  14. chars = {1: "←", 2: "→", 3: "↓", 4: "↑"}
  15. keys = {"left": "←", "right": "→", "down": "↓", "up": "↑"}
  16. inv_keys = {keys[key]: key for key in keys}
  17. reg = winregistry.WinRegistry()
  18. try:
  19.     highscore = reg.read_value(r"HKCR\SOFTWARE", "Score")["data"]
  20. except FileNotFoundError:
  21.     highscore = 0
  22. score = 0
  23. line = ["_" for _ in range(51)]
  24. running = True
  25. interval = .05
  26. unlocked = True
  27. combo = 0
  28. maxcombo = 0
  29. score_earned = 0
  30. not_missed = True
  31. scorecap = 10
  32. pause = False
  33. print("Welcome to Dance Game!")
  34. print()
  35. print("Rules are simple:")
  36. print(" *When arrow(←, →, ↓ or ↑) comes next to square(#) you should tap on corresponding arrow key!")
  37. print(" *If you tap correctly you get 1 point")
  38. print(" *Else, you lose 5 points")
  39. print()
  40. print("Warning! To exit, press 'Q', otherwise highscore WILL NOT be saved!")
  41. print()
  42. print("Made by Cosmic47 and Livy!")
  43. print()
  44. input("Press Enter to start...")
  45. colorama.init()
  46.  
  47. def clear():
  48.     print("\x1b[2J\x1b[H",end="")
  49.  
  50. def OnTap(e):
  51.     global line
  52.     global score
  53.     global running
  54.     global inv_keys
  55.     global combo
  56.     global score_earned
  57.     global pause
  58.     if e.name == "_":
  59.         pass
  60.     elif e.name == inv_keys.get(line[0]):
  61.         score += 1
  62.         line[0] = "_"
  63.         combo += 1
  64.         not_missed = True
  65.     elif e.name == "q":
  66.         reg.write_value(r'HKCR\SOFTWARE', 'Score', highscore, 'REG_DWORD')
  67.         running = False
  68.     elif e.name == "space":
  69.         pause = not pause
  70.     elif e.name != inv_keys.get(line[0]):
  71.         score = 0 if score <= 5 else score - 5
  72.         score_earned = 0 if score_earned <= 5 else score_earned - 5
  73.         combo = 0
  74.  
  75. clear()
  76. keyboard.on_press(OnTap)
  77. while running:
  78.     if score_earned == scorecap and interval > 0.02:
  79.         interval -= 0.02
  80.         scorecap += 5
  81.         score_earned = 0
  82.     unlocked = True
  83.     del line[0]
  84.     rannum = random.randint(1, 20)
  85.     line.append(chars[rannum] if rannum < 5 else "_")
  86.     if highscore < score:
  87.         highscore = score
  88.     if combo > maxcombo:
  89.         maxcombo = combo
  90.     sys.stdout.write("#" + "".join(line) + "\nScore: " + str(score) + "\nHighscore: " +
  91.           str(highscore) + "\nCombo: " + str(combo) + "\nMax Combo: " +
  92.           str(maxcombo) + "\nCurrent arrows' speed: " + str(1.0 / interval) +
  93.            " cells per second" + "\nPause: " + str(pause))
  94.     while pause:
  95.         pass
  96.     time.sleep(interval)
  97.     # clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement