File tree 2 files changed +28
-5
lines changed 2 files changed +28
-5
lines changed Original file line number Diff line number Diff line change 8
8
9
9
class Calc ():
10
10
11
+ @staticmethod
12
+ def surrounding (pos ):
13
+ '''
14
+ Return the complete set of
15
+ points surrounding a piece.
16
+ Sanity checking is not performed.
17
+ '''
18
+ results = []
19
+ if pos :
20
+ above = pos .ypos - 1
21
+ below = pos .ypos + 1
22
+ left = pos .xpos - 1
23
+ right = pos .xpos + 1
24
+ results .append ([left , above ])
25
+ results .append ([right , below ])
26
+ results .append ([left , below ])
27
+ results .append ([right , above ])
28
+ results .append ([pos .xpos , above ])
29
+ results .append ([pos .xpos , below ])
30
+ results .append ([left , pos .ypos ])
31
+ results .append ([right , pos .ypos ])
32
+ return results
33
+
11
34
@staticmethod
12
35
def distance (x1 , y1 , x2 , y2 ):
13
36
x = x2 - x1
Original file line number Diff line number Diff line change @@ -39,10 +39,11 @@ def move_to(self, dest):
39
39
self .enterprise .docked = False
40
40
for p in area ._pieces :
41
41
if p .glyph == Glyphs .STARBASE :
42
- if p .xpos + 1 == pos .xpos or p .ypos + 1 == pos .ypos or \
43
- p .xpos - 1 == pos .xpos or p .ypos - 1 == pos .ypos :
44
- self .enterprise .docked = True
45
- ShipStarbase .dock_enterprise (self .enterprise )
42
+ for point in Calc .surrounding (pos ):
43
+ if p .xpos == point [0 ] and \
44
+ p .ypos == point [1 ]:
45
+ self .enterprise .docked = True
46
+ ShipStarbase .dock_enterprise (self .enterprise )
46
47
if was_docked and self .enterprise .docked == False :
47
48
ShipStarbase .launch_enterprise (self .enterprise )
48
49
return pos
@@ -80,7 +81,6 @@ def run(self):
80
81
if not self .command_prompt ():
81
82
break
82
83
except ErrorEnterpriseCollision as ex :
83
- game .display ()
84
84
if ex .glyph == Glyphs .KLINGON :
85
85
self .display ("You flew into a KLINGON!" )
86
86
if ex .glyph == Glyphs .STARBASE :
You can’t perform that action at this time.
0 commit comments