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

print "In this game you will try to go through the maze all the way to the bottom "
print " without hitting a plus sign (+) or a minus sign (-). Try to go as fast as possible."
print " Controls are written at the bottom of the screen. You will be timed."

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

origscreen = [] # screen without a ":P"
def formscreen():
  len = 5
  origscreen.append(arr)
  i = 1
  while i < len:
	origscreen.append(("    -      -      -      -") + origscreen[i-1])
	i = i+1

def printscreen():
  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] + (":P") + 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()
   arr = (" ") + arr
   mybeforetime = time.time()
   # print mybeforetime
   x = raw_input("To do it as fast as possible, conveniently hit e for up, d for down, f for right and a for left or s for stop:")
   myaftertime = time.time()
   diff = myaftertime - mybeforetime
   print ("You hit the letter: ") + x
   if x == "e":
	vpos = vpos-1
   if x == "d":
	vpos = vpos+1
   if x == "a":
       hpos = hpos-1
   if x == "f":
       hpos = hpos+1
   totaltime = totaltime + diff
   print totaltime
   i=i+1

print totaltime

