This game can be cheated by pressing enter or entering any input before an enemy appears. Is there a way to pause user input until it is necessary so that this code works properly?
import random
import os
hp = 20
Shp = str(hp)
score = 0
def shoot():
hp = 20
score = 0
while hp > 0:
wait = random.randint(1, 7)
time.sleep(wait)
os.system("clear")
print("An Enemy!")
now = time.time()
hit = input("")
if time.time() - now < 0.4:
print("You hit them!")
score = score+1
time.sleep(1)
os.system('clear')
else:
print("They hit you first.")
hp = hp-5
time.sleep(1)
os.system('clear')
print("Game over. You scored", score)
print("When an enemy appears, press ENTER to shoot.\n You start with "+Shp+"HP, if the enemy hits you before you hit them, you lose HP.\n\n Press ENTER to begin.")
start = input("")
os.system('clear')
shoot()