#!/usr/bin/env python
#
# while statement
#

arr1= "************************************"
arr2= "<                                  >"
arr3= "<                            >"
arr4= "...................................."
origscreen = []
vposball=0
hposball=17
vpospad=29
hpospad=13
loseflag2=0
hitPad=0
hitCeil=1
hitRWall=0
hitLWall=0
padDetPos1=0
padDetPos2=0

def formscreen():
    len=30
    origscreen.append(arr1)
    i=1
    while i<len-1:
        origscreen.append(arr2)
        i=i+1
    origscreen.append(arr3)
    origscreen.append(arr4)

def printscreen():
    screen = []
    mylen = len(origscreen)
    i= 0
    global hitPad
    global hitCeil
    global hitLWall
    global hitRWall
    global loseflag2
    global done
    loseflag= 0
    while(i < mylen):
        y= origscreen[i]
        screen.append(y)
        if i== vpospad:
            y= y[:hpospad] + ("-------") + y[hpospad+1:]
            screen[i]=y
        if i== vposball:
            if(y[hposball] == "."):
               loseflag = 1
            if(y[hposball] == "-"):
                hitPad=1
            if(y[hposball] == "*"):
                hitCeil=1
            if(y[hposball] == "<"):
               hitLWall=1
            if(y[hposball] == ">"):
               hitRWall=1
            y= y[:hposball] + ("o") + y[hposball+1:]
            screen[i] = y
        i=i+1
    for s in screen:
        print s
    if loseflag== 1:
        loseflag2=1
        print "You lose"




formscreen()


k=0
angleVar=0
direction=1

while(loseflag2 !=1):
    
    printscreen()
    if(hitPad!=1 and angleVar==0):
        while(hitPad!= 1):
            
            k=k+1
            print k
            
            arr3 = (" ") + arr3
            x = raw_input("Use the 'j' and 'k' key to move the pad left and right")
            if x=="j":
                hpospad=hpospad-1
            if x=="k":
                hpospad=hpospad+1
                
            if k==28:
                padDetPos1=hpospad
            if k==29:
                padDetPos2=hpospad

            vposball=vposball+1
            printscreen()
            hitCeil=0
            angleVar= padDetPos2-padDetPos1
            print angleVar

        
    if(hitPad== 1 and angleVar==0):
        k=0
        hitPad=0
        while(hitCeil !=1):

              
            arr3 = (" ") + arr3
            x = raw_input("Use the 'j' and 'k' key to move the pad left and right")
            if x=="j":
                hpospad=hpospad-1
            if x=="k":
                hpospad=hpospad+1
                        
            vposball= vposball-1
            printscreen()


    if(hitPad== 1 and angleVar>0):
        k=0
        hitPad=0
       
        while(hitCeil !=1):
            
            if(hitLWall==1):
                hitLWall=0
                direction=-1
            if(hitRWall==1):
                hitRWall=0
                direction=1             
            arr3 = (" ") + arr3
            x = raw_input("Use the 'j' and 'k' key to move the pad left and right")
            if x=="j":
                hpospad=hpospad-1
            if x=="k":
                hpospad=hpospad+1
                
            vposball= vposball-1
            hposball= hposball-(1*direction)
            
            printscreen()

    if(hitPad== 1 and angleVar<0):
        k=0
        hitPad=0

        while(hitCeil !=1):

            if(hitLWall==1):
                hitLWall=0
                direction=1
            if(hitRWall==1):
                hitRWall=0
                direction=-1
            arr3 = (" ") + arr3
            x = raw_input("Use the 'j' and 'k' key to move the pad left and right")
            if x=="j":
                hpospad=hpospad-1
            if x=="k":
                hpospad=hpospad+1

            vposball= vposball-1
            hposball= hposball+(1*direction)

            printscreen()
            

    if(hitPad!=1 and angleVar>0):
        direction=1
        k=0
        while(hitPad!= 1):
            
            if(hitLWall==1):
                hitLWall=0
                direction=1
            if(hitRWall==1):
                hitRWall=0
                direction=-1            
            
            k=k+1
            print k
            
            arr3 = (" ") + arr3
            x = raw_input("Use the 'j' and 'k' key to move the pad left and right")
            if x=="j":
                hpospad=hpospad-1
            if x=="k":
                hpospad=hpospad+1
                
            if k==28:
                padDetPos1=hpospad
            if k==29:
                padDetPos2=hpospad

            vposball=vposball+1
            hposball= hposball+(1*direction)
            printscreen()
            hitCeil=0
            angleVar= padDetPos2-padDetPos1
            print angleVar


    if(hitPad!=1 and angleVar<0):
        direction=1
        k=0
        while(hitPad!= 1):
            
            if(hitLWall==1):
                hitLWall=0
                direction=-1
            if(hitRWall==1):
                hitRWall=0
                direction=+1            
            
            k=k+1
            print k
            
            arr3 = (" ") + arr3
            x = raw_input("Use the 'j' and 'k' key to move the pad left and right")
            if x=="j":
                hpospad=hpospad-1
            if x=="k":
                hpospad=hpospad+1
                
            if k==28:
                padDetPos1=hpospad
            if k==29:
                padDetPos2=hpospad

            vposball=vposball+1
            hposball= hposball-(1*direction)
            printscreen()
            hitCeil=0
            angleVar= padDetPos2-padDetPos1
            print angleVar
        
        




        









    
            
                
                
            

    
        
