回答編集履歴

1

1

2017/05/04 17:32

投稿

takasima20
takasima20

スコア7458

test CHANGED
@@ -11,3 +11,113 @@
11
11
  このあたりのさじ加減はなかなか難しいので
12
12
 
13
13
  よそのソースを参考にするなど…
14
+
15
+ --- 追記 ---
16
+
17
+ オブジェクトの利用に関しては他の方の回答をみていただくとして…
18
+
19
+
20
+
21
+ そのクラスが「何を扱うか」を常に意識しておかないと
22
+
23
+ ごちゃごちゃで分かりにくくて使いにくいものになります。
24
+
25
+ 例えばこんな感じのはどうでしょう
26
+
27
+ ```Python
28
+
29
+ class Gamen:
30
+
31
+ def __init__(self, w, h):
32
+
33
+ self.width = w
34
+
35
+ self.height = h
36
+
37
+ def loop_point(self, p):
38
+
39
+ # 位置を補正
40
+
41
+ # Pointオブジェクトを返す
42
+
43
+
44
+
45
+ class Point:
46
+
47
+ def __init__(self, x, y):
48
+
49
+ self.x = x
50
+
51
+ self.y = y
52
+
53
+ def up(self, d):
54
+
55
+ self.y = self.y + d
56
+
57
+ def down(self, d):
58
+
59
+ self.y = self.y - d
60
+
61
+ def right(self, d):
62
+
63
+ self.x = self.x + d
64
+
65
+ def left(self, d):
66
+
67
+ self.x = self.x - d
68
+
69
+
70
+
71
+ class Sousa:
72
+
73
+ def __init__(self, s, d):
74
+
75
+ self.dir = s
76
+
77
+ self.distance = d
78
+
79
+
80
+
81
+ def change_point(g, p, s):
82
+
83
+ if s.dir == "UP":
84
+
85
+ p.up(s.distance)
86
+
87
+ if s.dir == "DOWN":
88
+
89
+ p.down(s.distance)
90
+
91
+ if s.dir == "RIGHT":
92
+
93
+ p.right(s.distance)
94
+
95
+ if s.dir == "LEFT":
96
+
97
+ p.left(s.distance)
98
+
99
+ r = g.loop_point(p)
100
+
101
+ return r
102
+
103
+
104
+
105
+ if __name__ == '__main__':
106
+
107
+ width, height, x, y = [int(x) for x in input().split()]
108
+
109
+ Dir, Distance = input().split()
110
+
111
+ Distance = int(Distance)
112
+
113
+ g = Gamen(width, height)
114
+
115
+ p = Point(x, y)
116
+
117
+ s = Sousa(Dir, Distance)
118
+
119
+ p = change_point(g, p, s)
120
+
121
+ print(p.x, p.y)
122
+
123
+ ```