import keyboard
import os
import time 
def screen_config(speed,height,width):
    d = []
    h = 1
    w = 1
    while not 'q' in d:
        d = []
        for i in range(5):
            time.sleep(0.001)
            d = press(d)
        if 'u' in d and h > 1:
            h += -1
        if 'd' in d and h < height:
            h += 1
        if 'l' in d and w > 1:
            w += -1
        if 'r' in d and w < width:
            w += 1
        #now creating a matrix to the sizes of w and h
        matrix = cre_mat(h,w)
        #now 'decorating' the edges with stars
        for row_n in range(h):
            matrix[row_n][w-1] = '*'
        for col_n in range(w):
            matrix[h-1][col_n] = '*'
        os.system("cls")
        Printm(matrix)
    #print w
    #print h
    return w,h

def cre_mat(height,width):#creates a matrix according to height and width
    matrix = []
    for row in range(height):
        row = []
        for column in range(width):
            row.append(' ')
        matrix.append(row)
    return matrix


def press(c_list):#adds to c_list all the directions being pressed 
    if keyboard.is_pressed('w'):
        if 'u' in c_list:
            pass
        else:
            c_list.append('u')
    if keyboard.is_pressed('s'):
        if 'd' in c_list:
            pass
        else:
            c_list.append('d')
    if keyboard.is_pressed('d'):
        if 'r' in c_list:
            pass
        else:
            c_list.append('r')
    if keyboard.is_pressed('a'):
        if 'l' in c_list:
            pass
        else:
            c_list.append('l')
    if keyboard.is_pressed('q'):
        if 'q' in c_list:
            pass
        else:
            c_list.append('q')
    return c_list
def PrintP(matrix,width,height,player):#prints the map, with the player in the center
    text = ""
    y = player.y
    h = player.h
    x = player.x #players location (x axis) - width 
    w = player.w #width of the full map 
    halfw = width/2 #halfw should be the distance between the player and the edges of the screen 
    halfh = height/2
    if halfw > x:#player is too close to wend for nofrmal screen view
        wstart = 0
        wend = width
    elif x > w - halfw:
        wstart = w - width
        wend = w
    else:
        wstart = x - halfw
        wend = x + halfw
    if halfh > y:
        hstart = 0
        hend = height
    elif y > h - halfh:
        hstart = h - height
        hend = h
    else:
        hstart = y - halfh
        hend = y + halfh

    for r in range(hstart,hend):
        text += "\n"
        for unit in matrix[r][wstart:wend]:
            
            if unit[1] == "-" or unit[1] == "_" or unit[1] == '|':#if there is a floor underline the space
                if unit[0] == ' ':
                    text += unit[1]
                else:
                    text += unit[0]
            else:
                text += unit[0]
    #print "player location\n x: {} y: {}".format(player.x,player.y)
    print (text)    
def Print(matrix):#get a matrix (the board) and prints it nicely 
    text = ""
    for r in range(len(matrix)):
        text += "\n"
        for unit in matrix[r]:
            if unit[1] == "-" or unit[1] == "_":#if there is a floor underline the space
                if unit[0] == ' ':
                    text += unit[1]
                else:
                    text += unit[0]
            else:
                text += unit[0]
    print (text)
def Printm(matrix):
    text = ""
    for r in range(len(matrix)):
        for unit in matrix[r]:
            text += unit
        text += "\n"
    print text
import keyboard
import os
import time 
def screen_config(speed,height,width):
    d = []
    h = 1
    w = 1
    while not 'q' in d:
        d = []
        for i in range(5):
            time.sleep(0.001)
            d = press(d)
        if 'u' in d and h > 1:
            h += -1
        if 'd' in d and h < height:
            h += 1
        if 'l' in d and w > 1:
            w += -1
        if 'r' in d and w < width:
            w += 1
        #now creating a matrix to the sizes of w and h
        matrix = cre_mat(h,w)
        #now 'decorating' the edges with stars
        for row_n in range(h):
            matrix[row_n][w-1] = '*'
        for col_n in range(w):
            matrix[h-1][col_n] = '*'
        os.system("cls")
        Printm(matrix)
    #print w
    #print h
    return w,h

def cre_mat(height,width):#creates a matrix according to height and width
    matrix = []
    for row in range(height):
        row = []
        for column in range(width):
            row.append(' ')
        matrix.append(row)
    return matrix


def press(c_list):#adds to c_list all the directions being pressed 
    if keyboard.is_pressed('w'):
        if 'u' in c_list:
            pass
        else:
            c_list.append('u')
    if keyboard.is_pressed('s'):
        if 'd' in c_list:
            pass
        else:
            c_list.append('d')
    if keyboard.is_pressed('d'):
        if 'r' in c_list:
            pass
        else:
            c_list.append('r')
    if keyboard.is_pressed('a'):
        if 'l' in c_list:
            pass
        else:
            c_list.append('l')
    if keyboard.is_pressed('q'):
        if 'q' in c_list:
            pass
        else:
            c_list.append('q')
    return c_list
def PrintP(matrix,width,height,player):#prints the map, with the player in the center
    text = ""
    y = player.y
    h = player.h
    x = player.x #players location (x axis) - width 
    w = player.w #width of the full map 
    halfw = width/2 #halfw should be the distance between the player and the edges of the screen 
    halfh = height/2
    if halfw > x:#player is too close to wend for nofrmal screen view
        wstart = 0
        wend = width
    elif x > w - halfw:
        wstart = w - width
        wend = w
    else:
        wstart = x - halfw
        wend = x + halfw
    if halfh > y:
        hstart = 0
        hend = height
    elif y > h - halfh:
        hstart = h - height
        hend = h
    else:
        hstart = y - halfh
        hend = y + halfh

    for r in range(hstart,hend):
        text += "\n"
        for unit in matrix[r][wstart:wend]:
            
            if unit[1] == "-" or unit[1] == "_" or unit[1] == '|':#if there is a floor underline the space
                if unit[0] == ' ':
                    text += unit[1]
                else:
                    text += unit[0]
            else:
                text += unit[0]
    #print "player location\n x: {} y: {}".format(player.x,player.y)
    print (text)    
def Print(matrix):#get a matrix (the board) and prints it nicely 
    text = ""
    for r in range(len(matrix)):
        text += "\n"
        for unit in matrix[r]:
            if unit[1] == "-" or unit[1] == "_":#if there is a floor underline the space
                if unit[0] == ' ':
                    text += unit[1]
                else:
                    text += unit[0]
            else:
                text += unit[0]
    print (text)
def Printm(matrix):
    text = ""
    for r in range(len(matrix)):
        for unit in matrix[r]:
            text += unit
        text += "\n"
    print text
#now creating a matrix to the sizes of w and h #now 'decorating' the edges with stars #print w #print h #creates a matrix according to height and width #adds to c_list all the directions being pressed #prints the map, with the player in the center #players location (x axis) - width #width of the full map #halfw should be the distance between the player and the edges of the screen #player is too close to wend for nofrmal screen view #if there is a floor underline the space #print "player location\n x: {} y: {}".format(player.x,player.y) #get a matrix (the board) and prints it nicely #if there is a floor underline the space