Skip to content

Commit 9030ec1

Browse files
committed
Fixed generous starbase docking logic.
1 parent 8b72d8b commit 9030ec1

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

Calculators.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,29 @@
88

99
class 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

StarTrek2020.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff 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:

0 commit comments

Comments
 (0)