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

print "In this game you will try to go through the maze"
print " You know the rules. Try to go as fast as possible."
print " You will be timed."

arr = "     *        *  "
#starting positions, with the top left being 0, 0 
hpos = 6 # horizontal position
vpos = 9  # vertical position
x= ""

origscreen = [] # screen without a "*"
def formscreen():
   len = 10
   origscreen.append("-- |------")
   origscreen.append("_| |--- --")
   origscreen.append("_| |--- --")
   origscreen.append("_| |--  --")
   origscreen.append("/  |-- ---")
   origscreen.append("|  /     |")
   origscreen.append("| |  | | |")
   origscreen.append("| | || | |")
   origscreen.append("    || |--")
   origscreen.append("----|| ---")

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] == "|") or (x[hpos] == "/"):
                 print "Don't run into walls"

         x = x[:hpos] + ("*") + 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":

   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] == "|") or (x[hpos] == "_"):
                 print "Don't run into walls"
                 loseflag=1 
                 if x == "u":
                    vpos = vpos+1
                 if x == "d":
                    vpos = vpos-1
                 if x == "l":
                    hpos = hpos+1
                 if x == "r":
                    hpos = hpos-1
         x = x[:hpos] + ("*") + x[hpos+1:]
         screen[i] = x
         if (hpos == 2) and (vpos == 0):
            print "you win!!"
            x = "s"
      i = i+1
   for s in screen:
      print s

   if (x=="s"):
      break
   arr = (" ") + arr
   mybeforetime = time.time()
   # print mybeforetime
   x = raw_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
   print
   i=i+1


   

print totaltime
