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
/
Copy pathcontroller.py
57 lines (46 loc) · 1.82 KB
/
controller.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
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
__author__ = 'tenpaMk2'
import logging
import logging.config
logging.config.fileConfig("config/logging.conf")
import model
import view
import observer
# TODO ControllerにあてるObserverは普通のObserverで良いんだろうか。というかNPCObserverなんてもんがあっちゃまずいのか?
# ControllerにObserverを当てる意味はないのでは…。
# FIXME inputを始めるときにマップの描画もしちゃえばええんや!これでObserverもすっきりするんちゃう?
# Observerを使うのは正しい。Modelから直接ControllerやViewが見えてはいけない。
# しかし、どうやってHeroとVillagerのObserverを区別するかが問題だ。
class Controller(observer.Subject):
def __init__(self, hero: "model.Hero", viewer: "view.Viewer"):
observer.Subject.__init__(self)
self.hero = hero
self.viewer = viewer
def start_input(self):
logging.info("Controller")
self.viewer.draw_message_before_input()
arg = input()
self.viewer.draw_message_after_input(arg)
self.input_parser(arg)
def input_parser(self, arg):
logging.info("Controller")
if arg in (0, 'S', 's'):
self.hero.move_south()
elif arg in (1, 'E', 'e'):
self.hero.move_east()
elif arg in (2, 'N', 'n'):
self.hero.move_north()
elif arg in (3, 'W', 'w'):
self.hero.move_west()
elif arg in ('i', 'I'):
self.hero.interact_to_front()
elif arg in ('r', 'R'):
self.hero.run()
elif arg in ('a', 'A'):
self.hero.attack_front()
elif arg in 'exec':
exec_arg = input()
exec(exec_arg)
else:
raise ValueError('Invalid command!')