import random
import time
plocationX = 0
plocationY = 0
clocationX = 0
clocationY = 0
position = 0
current_list = []
userG = 0
scores = []
scores_disp = {}
timemark = 0
score = 0
z = 0
blnNHS = False
def move_dot():
clocationX = random.randint(0,4)
clocationY = random.randint(0,4)
global position
position = clocationX + (5*clocationY)
global current_list
if position > 24 or position < 0:
re_set()
else:
current_list[position] = 1
def user_guess():
global userG
plocationX = int(input("Enter x cord from 1-5")) - 1
plocationY = int(input("Enter y cord from 1-5")) - 1
userG = 0
userG = plocationX + (5*plocationY)
def re_set():
current = []
reset_tup = (0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0,
0,0,0,0,0)
for i in range(0,25):
current.append(reset_tup[i])
return current
def update_scores():
global userG
global position
global timemark
global score
global scores
global blnNHS
blnNHS = False
if userG == position:
score = time.time() - timemark
score = round(score,2)
else:
score = 9999999
if len(scores) >= 1:
blnNHS = score < scores[0]
scores.insert(0,score)
def sort_scores():
#following code largely inspired by www.geeksforgeeks.org
global scores
global z
global scores_disp
z = len(scores)
scores_disp.clear()
for i in range(z-1):
for j in range(0, z-i-1):
if scores[j] > scores[j+1] :
scores[j], scores[j+1] = scores[j+1], scores[j]
for p in range(len(scores)):
scores_disp[p+1] = scores[p]
print(scores_disp)
while True:
current_list = re_set()
move_dot()
print("",current_list[0],current_list[1],current_list[2],current_list[3],current_list[4],"\n",current_list[5],current_list[6],current_list[7],current_list[8],current_list[9],"\n",current_list[10],current_list[11],current_list[12],current_list[13],current_list[14],"\n",current_list[15],current_list[16],current_list[17],current_list[18],current_list[19],"\n",current_list[20],current_list[21],current_list[22],current_list[23],current_list[24])
timemark = time.time()
print()
user_guess()
update_scores()
sort_scores()
if blnNHS == True:
print("New High Score!")
print()
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 0 0 0 0
0 1 0 0 0
{1: 5.94}
0 0 0 0 0
0 0 0 0 0
0 0 1 0 0
0 0 0 0 0
0 0 0 0 0
KeyboardInterrupt: Interrupted by user