This repository has been archived by the owner on May 4, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
view.py
60 lines (46 loc) · 1.63 KB
/
view.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
55
56
57
58
59
60
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
__author__ = 'tenpaMk2'
import logging
import logging.config
logging.config.fileConfig("config/logging.conf")
import model
import observer
class Viewer(observer.Subject):
def __init__(self, map_model: "model.MapModel"):
observer.Subject.__init__(self)
self.map_model = map_model
def draw(self):
logging.info("Viewer")
self._draw_map()
self._draw_message()
def _draw_map(self):
map_buffer = [[None for _ in range(self.map_model.width)] for _ in range(self.map_model.height)]
for floor_object in self.map_model.floor_objects:
position = floor_object.get_position()
y = position[0]
x = position[1]
map_buffer[y][x] = floor_object
for obstacle_object in self.map_model.obstacle_objects:
position = obstacle_object.get_position()
y = position[0]
x = position[1]
map_buffer[y][x] = obstacle_object
for y in range(self.map_model.height):
for x in range(self.map_model.width):
print(map_buffer[y][x].icon, end='')
print('')
def _draw_message(self):
print('#' * self.map_model.width)
print("# " + self.map_model.message)
print('#' * self.map_model.width)
@staticmethod
def draw_message_before_input():
logging.info("Viewer")
print('')
print('')
def draw_message_after_input(self, input_message):
logging.info("Viewer")
print('>' * self.map_model.width, end='')
print(' ', end='')
print(input_message)