Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.57 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 colorama
  10. import time
  11. import random
  12. import winregistry
  13. chars = {1: "←", 2: "→", 3: "↓", 4: "↑"}
  14. keys = {"left": "←", "right": "→", "down": "↓", "up": "↑"}
  15. inv_keys = {keys[key]: key for key in keys}
  16. reg = winregistry.WinRegistry()
  17. try:
  18.     highscore = reg.read_value(r"HKCR\SOFTWARE", "Score")["data"]
  19. except FileNotFoundError:
  20.     highscore = 0
  21. score = 0
  22. line = ["_" for _ in range(51)]
  23. running = True
  24. interval = .75
  25. unlocked = True
  26. colorama.init(convert=True)
  27. combo = 0
  28. maxcombo = 0
  29. score_earned = 0
  30. scorecap = 10
  31. pause = False
  32. print("Welcome to Dance Game!")
  33. print()
  34. print("Rules are simple:")
  35. print(" *When arrow(←, →, ↓ or ↑) comes next to square(#) you should tap on corresponding arrow key!")
  36. print(" *If you tap correctly you get 1 point")
  37. print(" *Else, you lose 5 points")
  38. print()
  39. print("Warning! To exit, press 'Q', otherwise highscore WILL NOT be saved!")
  40. print()
  41. print("Made by Cosmic47 and Livy!")
  42. print()
  43. input("Press Enter to start...")
  44. os.system('cls')
  45.  
  46.  
  47. def clear():
  48.     os.system("cls")
  49.  
  50.  
  51. def OnTap(e):
  52.     global line
  53.     global score
  54.     global running
  55.     global inv_keys
  56.     global combo
  57.     global score_earned
  58.     global pause
  59.     if e.name == "_":
  60.         pass
  61.     elif e.name == inv_keys.get(line[0]):
  62.         score += 1
  63.         line[0] = "_"
  64.         combo += 1
  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.1:
  79.         interval -= 0.05
  80.         scorecap += 10
  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.     print("#" + "".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