Skip to content

Instantly share code, notes, and snippets.

@inesusvet
Created March 14, 2017 10:41
Show Gist options
  • Save inesusvet/16b9252bfcc6773b0ab21478e90f11c7 to your computer and use it in GitHub Desktop.
Save inesusvet/16b9252bfcc6773b0ab21478e90f11c7 to your computer and use it in GitHub Desktop.
Игра-бродилка
"""
Имеется лабиринт, нужно провести игрока к сокровищу
"""
import os
LOCATION_FILENAME = '.location'
TEST_LOCATION = [
[1, 1, 1],
[1, 0, 1],
[1, 1, 1],
]
WALLS = '-+|'
TREASURE = '*'
def get_sign(is_wall):
return '\u2588' if is_wall else ' '
def read_location(text):
lines = text.split('\n')
result = []
for line in lines:
row = []
for char in line:
value = 1 if char in WALLS else 0
row.append(value)
result.append(row)
return result
def show_location(location):
for row in location:
for column in row:
sign = get_sign(column)
print(sign, end='')
print(end='\n')
if __name__ == '__main__':
if os.path.exists(LOCATION_FILENAME):
text = open(LOCATION_FILENAME).read()
location = read_location(text)
else:
location = TEST_LOCATION
show_location(location)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment