repl.it
@tsimpson1379/

a-MAZE-ing

Python

No description

fork
loading
Files
  • main.py
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import shutil, time

c = {'grey': '\033[90m', 'red': '\033[91m', 'green': '\033[92m', 'yellow': '\033[93m', 'blue': '\033[94m', 'magenta': '\033[95m', 'cyan': '\033[96m', 'white': '\033[97m', 'default': '\033[98m'}
b = {'grey': '\033[40m', 'red': '\033[41m', 'green': '\033[42m', 'yellow': '\033[43m', 'blue': '\033[44m', 'magenta': '\033[45m', 'cyan': '\033[46m', 'white': '\033[47m', 'default': '\033[48m'}

'''
0 = blank
1 = wall
2 = start
3 = end
4 = down two portal
'''

maze = [[2,1,1,1,0,1,0,0],
        [0,1,0,0,0,1,1,0],
        [0,4,0,1,0,4,1,0],
        [0,1,1,0,4,1,0,0],
        [4,0,0,0,1,0,0,1],
        [1,1,0,1,0,1,0,0],
        [4,1,0,1,4,0,0,1],
        [0,0,0,0,0,1,0,3],]
        # character, text colour, background colour
key = {0:(' ','',''),
       1:(' ','',b['white']),
       2:('S','',b['blue']),
       3:('F','',b['blue']),
       4:(' ','',b['magenta']),}

def moveMouse(col, row): print("\033["+str(col)+";"+str(row)+"H")

def printMaze(maze, playerPos, key):
    E = '\033[0m'
    hPadding = round((rows-(len(maze)*3))/2)
    wPadding = round((columns-(len(maze[0])*6))/2)
    moveMouse(0, 0)
    out = '\n'*hPadding
    for row in maze:
        rowStr = ' '*wPadding
        for col in row:
            info = key[col]
            if ("placeholder!") == playerPos:
                rowStr += 'PLAYER'
            else:
                rowStr += info[1] + info[2] + info[0]*6 + E
        out += (rowStr+'\n'+b['white'])*3
    print(out)



columns, rows = shutil.get_terminal_size(fallback=(80, 24))
columns-=2
rows-=1
print((b['white']+(' '*(columns) +'\n')*(rows)).rstrip('\n'), end='')
printMaze(maze, (0, 0), key)
?