#!/usr/bin/env python
#
# while statement
#
import time
import datetime

print("In this game you will try to go from top to bottom ")
print(" without eating a star(*) or hyphen(-). Try to go as fast as possible.")
print(" You will be timed.")

arr = "     *        *  "
hpos = 0 # horizontal position
vpos = 0  # vertical position

origscreen = [] # screen without a "o"
def formscreen():
   global origscreen # because we want to change origscreen here
   len = 20
   origscreen.append(arr)
   i = 1
   while i < len:
	origscreen.append(("-") + origscreen[i-1])
	i = i+1

def printscreen(origscreen, vpos, hpos):
   screen = []
   mylen = len(origscreen)
   i = 0
   loseflag = 0
   while (i < mylen):
	x = origscreen[i]
	screen.append(x)
	if i == vpos:
		if (x[hpos] == "-") or (x[hpos] == "*"):
			loseflag = 1
		x = x[:hpos] + ("o") + x[hpos+1:]
		screen[i] = x
	i = i+1
   for s in screen:
	print(s)
   if loseflag == 1:
   	print("You lose")

totaltime = 0
formscreen()
i = 0
x = ""
while x != "s":
    printscreen(origscreen, vpos, hpos)
    arr = (" ") + arr
    mybeforetime = time.time()
    # print mybeforetime
    x = input("Please hit u(up), d(down), l(left), r(right), or s(stop):")
    myaftertime = time.time()
    diff = myaftertime - mybeforetime
    print(("You hit the letter: ") + x)
    if x == "u":
	vpos = vpos-1
    if x == "d":
	vpos = vpos+1
    if x == "l":
        hpos = hpos-1
    if x == "r":
        hpos = hpos+1
    totaltime = totaltime + diff
    print(totaltime)
    i=i+1

print(totaltime)



