Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
zmx0142857
GitHub Repository: zmx0142857/mini-games
Path: blob/master/py/maze.py
363 views
1
"""A maze game generator"""
2
3
__author__ = 'zmx0142857'
4
5
import random
6
7
class Maze(object):
8
9
def __init__(self, rows, cols):
10
11
walls = ('┌','┬','┐','├','┼','┤','└','┴','┘','─','│')
12
specials = ('A','B')
13
14
def my_choice(i, j):
15
top = (i == 0)
16
bottom = (i == rows-1)
17
left = (j == 0)
18
right = (j == cols-1)
19
if left:
20
if top:
21
return '┌'
22
elif bottom:
23
return '└'
24
else:
25
return random.choice(('├','│'))
26
elif right:
27
if top:
28
return '┐'
29
elif bottom:
30
return '┘'
31
else:
32
return random.choice(('┤','│'))
33
elif top:
34
return random.choice(('┬','─'))
35
elif bottom:
36
return random.choice(('┴','─'))
37
else:
38
return random.choice(walls)
39
40
self._map = '\n'.join(''.join(my_choice(i, j) for j in range(cols)) for i in range(rows))
41
42
def __str__(self):
43
return self._map
44
45
__repr__ = __str__
46
47
def detailize(self):
48
pass
49
50