Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # -*- coding: utf-8 -*-
- """
- Created on Fri Jul 19 12:54:39 2019
- @author: Llama
- """
- import keyboard
- import os
- import time
- import sys
- import colorama
- import random
- import winregistry
- chars = {1: "←", 2: "→", 3: "↓", 4: "↑"}
- keys = {"left": "←", "right": "→", "down": "↓", "up": "↑"}
- inv_keys = {keys[key]: key for key in keys}
- reg = winregistry.WinRegistry()
- try:
- highscore = reg.read_value(r"HKCR\SOFTWARE", "Score")["data"]
- except FileNotFoundError:
- highscore = 0
- score = 0
- line = ["_" for _ in range(51)]
- running = True
- interval = .05
- unlocked = True
- combo = 0
- maxcombo = 0
- score_earned = 0
- not_missed = True
- scorecap = 10
- pause = False
- print("Welcome to Dance Game!")
- print()
- print("Rules are simple:")
- print(" *When arrow(←, →, ↓ or ↑) comes next to square(#) you should tap on corresponding arrow key!")
- print(" *If you tap correctly you get 1 point")
- print(" *Else, you lose 5 points")
- print()
- print("Warning! To exit, press 'Q', otherwise highscore WILL NOT be saved!")
- print()
- print("Made by Cosmic47 and Livy!")
- print()
- input("Press Enter to start...")
- colorama.init()
- def clear():
- print("\x1b[2J\x1b[H",end="")
- def OnTap(e):
- global line
- global score
- global running
- global inv_keys
- global combo
- global score_earned
- global pause
- if e.name == "_":
- pass
- elif e.name == inv_keys.get(line[0]):
- score += 1
- line[0] = "_"
- combo += 1
- not_missed = True
- elif e.name == "q":
- reg.write_value(r'HKCR\SOFTWARE', 'Score', highscore, 'REG_DWORD')
- running = False
- elif e.name == "space":
- pause = not pause
- elif e.name != inv_keys.get(line[0]):
- score = 0 if score <= 5 else score - 5
- score_earned = 0 if score_earned <= 5 else score_earned - 5
- combo = 0
- clear()
- keyboard.on_press(OnTap)
- while running:
- if score_earned == scorecap and interval > 0.02:
- interval -= 0.02
- scorecap += 5
- score_earned = 0
- unlocked = True
- del line[0]
- rannum = random.randint(1, 20)
- line.append(chars[rannum] if rannum < 5 else "_")
- if highscore < score:
- highscore = score
- if combo > maxcombo:
- maxcombo = combo
- sys.stdout.write("#" + "".join(line) + "\nScore: " + str(score) + "\nHighscore: " +
- str(highscore) + "\nCombo: " + str(combo) + "\nMax Combo: " +
- str(maxcombo) + "\nCurrent arrows' speed: " + str(1.0 / interval) +
- " cells per second" + "\nPause: " + str(pause))
- while pause:
- pass
- time.sleep(interval)
- # clear()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement