File tree Expand file tree Collapse file tree 2 files changed +28
-5
lines changed
Expand file tree Collapse file tree 2 files changed +28
-5
lines changed Original file line number Diff line number Diff line change 88
99class Calc ():
1010
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+
1134 @staticmethod
1235 def distance (x1 , y1 , x2 , y2 ):
1336 x = x2 - x1
Original file line number Diff line number Diff line change @@ -39,10 +39,11 @@ def move_to(self, dest):
3939 self .enterprise .docked = False
4040 for p in area ._pieces :
4141 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 )
4647 if was_docked and self .enterprise .docked == False :
4748 ShipStarbase .launch_enterprise (self .enterprise )
4849 return pos
@@ -80,7 +81,6 @@ def run(self):
8081 if not self .command_prompt ():
8182 break
8283 except ErrorEnterpriseCollision as ex :
83- game .display ()
8484 if ex .glyph == Glyphs .KLINGON :
8585 self .display ("You flew into a KLINGON!" )
8686 if ex .glyph == Glyphs .STARBASE :
You can’t perform that action at this time.
0 commit comments