Skip to content

Commit fecd7d7

Browse files
committed
Docking assured. Safe warp-ins enabled.
1 parent 2ba84c4 commit fecd7d7

File tree

6 files changed

+63
-74
lines changed

6 files changed

+63
-74
lines changed

Calculators.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
from MapGame import *
55
from AbsShip import *
6-
from Points import Destination
6+
from Points import *
77

88
class Calc():
99

Console.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
from AbsDisplay import abs_display
2-
from Points import Destination
2+
from Points import *
33

44
class Con(abs_display):
55
'''
@@ -33,19 +33,15 @@ def read_xypos(self, prompt = "Location (alpha,num)"):
3333
Example: b,4
3434
'''
3535
text = input(prompt + ': ')
36-
return Destination.parse_xypos(text)
36+
return SubDest.parse(text)
3737

3838
def read_sector(self, prompt= "Helm: sector 1-64, speed 1.0-9.0?"):
3939
text = input(prompt + ': ')
40-
return Destination.parse_warp(text)
41-
42-
def read_nav(self, prompt= "Helm: sector 1-64, a-h, 1-8?"):
43-
text = input(prompt + ': ')
44-
return Destination.parse_sector(text)
40+
return WarpDest.parse(text)
4541

4642
def read_xypos(self, prompt= "Helm: a-h, 1-8?"):
4743
text = input(prompt + ': ')
48-
return Destination.parse_xypos(text)
44+
return SubDest.parse(text)
4945

5046

5147
if __name__ == '__main__':

ErrorCollision.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,3 @@ def __init__(self, glyph):
77
self.glyph = glyph
88

99

10-
11-

MapGame.py

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33

44
import Glyphs
55
from ShipKlingon import ShipKlingon
6-
from Points import Destination
6+
from Points import *
77
from Quadrant import Quadrant
88
from ErrorCollision import ErrorEnterpriseCollision
99

@@ -58,12 +58,14 @@ def place(self, takers):
5858

5959
def enterprise_in(self, dest=None):
6060
''' Place the ENTERPRISE at the destination, else a
61-
random one.
61+
random one.
6262
6363
Will raise an ErrorEnterpriseCollision, upon same.
6464
6565
Returns the final x, y location upon success '''
6666
area = self.pw_area()
67+
if not dest:
68+
return area.place_glyph(Glyphs.ENTERPRISE)
6769
berror = False
6870
if area:
6971
for p in area._pieces:
@@ -211,29 +213,35 @@ def get_map(self):
211213
return area.get_map()
212214

213215
def random_jump(self):
214-
dest = Destination(
216+
dest = SubDest(
215217
random.randint(1, 64),
216218
random.randint(0, 7),
217219
random.randint(0, 7)
218220
)
219221
self._go_to(dest)
220222

221223
def _go_to(self, dest):
222-
'''
224+
''' Either a WARP ~or~ a SUBSPACE destination is ok.
223225
Place the main player (Enterprise, for now) into the Area.
224226
Returns the final, effective, player location.
225227
'''
228+
if not dest:
229+
return
226230
if self.last_nav:
227231
self.enterprise_out()
228-
if dest.sector > 0:
229-
self.sector = dest.sector
230-
if dest.xpos != -1:
231-
self.xpos = dest.xpos
232-
self.ypos = dest.ypos
233-
dest.sector = self.sector
234-
dest.xpos = self.xpos
235-
dest.ypos = self.ypos
236-
pos = self.enterprise_in(dest)
232+
pos = None
233+
if isinstance(dest, WarpDest):
234+
if dest.sector > 0:
235+
self.sector = dest.sector
236+
dest.sector = self.sector
237+
pos = self.enterprise_in() # SAFE WARP-IN!
238+
else:
239+
if dest.xpos != -1:
240+
self.xpos = dest.xpos
241+
self.ypos = dest.ypos
242+
dest.xpos = self.xpos
243+
dest.ypos = self.ypos
244+
pos = self.enterprise_in(dest) # CAPIN' KNOWS BEST?
237245
dest.xpos = pos[0]
238246
dest.ypos = pos[1]
239247
self.last_nav = dest

Points.py

Lines changed: 33 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,52 @@
1-
2-
3-
class Destination():
4-
''' Zero based, Map navigation '''
5-
def __init__(self, sector=-1, xpos=-1, ypos=-1, warp=0):
1+
class WarpDest():
2+
''' Warp Speed:
3+
One's based GALAXY navigation.
4+
Guaranteed SAFE placement.
5+
'''
6+
def __init__(self, sector=-1, warp=0):
67
if sector > 64: sector = 64 # zOuter Limits =)
7-
if xpos > 7: xpos = 7
8-
if ypos > 7: ypos = 7
9-
if xpos < 0: xpos = 0
10-
if ypos < 0: ypos = 0
118
if warp > 10: warp = 10
129
if warp < 0: warp = 0
1310
self.warp = warp
1411
self.sector = sector
15-
self.xpos = xpos
16-
self.ypos = ypos
1712

1813
@staticmethod
19-
def parse_sector(dest, sep=','):
14+
def parse(dest, sep=','):
2015
'''
21-
Parse: sector#, alpha-col, row-num
22-
Example: 5,b,1
16+
Parse: sector-num, speed-float - None on error
17+
Example: 5,1.1
2318
'''
2419
dest = str(dest)
2520
cols = dest.split(sep)
26-
if len(cols) == 3:
21+
if len(cols) == 2:
2722
try:
28-
sector = int(cols[0]) % 8
29-
if str(cols[1]).isalpha():
30-
xpos = ((ord(cols[1]) - ord('a')) % 8)
31-
ypos = int(cols[2]) % 8
32-
return Destination(sector, xpos, ypos)
23+
sector = int(cols[0].strip())
24+
if sector < 1:
25+
sector = 1
26+
speed = float(cols[1].strip())
27+
if speed < 0: speed = 0.1
28+
if speed > 9: speed = 9.0
29+
return WarpDest(sector, speed)
3330
except:
3431
pass
3532
return None
3633

34+
35+
class SubDest():
36+
''' Sublight Navigation:
37+
Zero based, AREA placement.
38+
Caveat, User! ;-)
39+
'''
40+
def __init__(self, xpos=-1, ypos=-1):
41+
if xpos > 7: xpos = 7
42+
if ypos > 7: ypos = 7
43+
if xpos < 0: xpos = 0
44+
if ypos < 0: ypos = 0
45+
self.xpos = xpos
46+
self.ypos = ypos
47+
3748
@staticmethod
38-
def parse_xypos(dest, sep=','):
49+
def parse(dest, sep=','):
3950
'''
4051
WARNING: USER 1's -> 0-BASED TRANSLATION HERE
4152
@@ -57,34 +68,8 @@ def parse_xypos(dest, sep=','):
5768
num = int(alph)
5869
xpos = num
5970
ypos = int(cols[1].strip()[0])
60-
return Destination(-1, xpos-1, ypos-1, -1)
71+
return SubDest(xpos-1, ypos-1)
6172
except:
6273
pass
6374
return None
6475

65-
@staticmethod
66-
def parse_warp(dest, sep=','):
67-
'''
68-
Parse: sector-num, speed-float - None on error
69-
Example: 5,1.1
70-
'''
71-
dest = str(dest)
72-
cols = dest.split(sep)
73-
if len(cols) == 2:
74-
try:
75-
sector = int(cols[0].strip())
76-
if sector < 1:
77-
sector = 1
78-
speed = float(cols[1].strip())
79-
if speed < 0: speed = 0.1
80-
if speed > 9: speed = 9.0
81-
return Destination(sector, -1, -1, speed)
82-
except:
83-
pass
84-
return None
85-
86-
87-
88-
89-
90-

StarTrek2020.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
from Calculators import Calc
99
from Controls import Control
1010
from Reports import Stats
11-
from Points import Destination
11+
from Points import *
1212
from Quips import Quips
1313
from MapGame import *
1414

@@ -32,6 +32,7 @@ def move_to(self, dest):
3232
if p.xpos + 1 == pos.xpos or p.ypos + 1 == pos.ypos or \
3333
p.xpos - 1 == pos.xpos or p.ypos - 1 == pos.ypos:
3434
self.enterprise.docked = True
35+
ShipStarbase.dock_enterprise(self.enterprise)
3536
return pos
3637

3738
def run(self):
@@ -43,7 +44,7 @@ def run(self):
4344
aliens = random.randrange(12, 16)
4445
starbases = random.randrange(6, 8)
4546
game.game_map.randomize(starbases, stars, aliens)
46-
dest = Destination(64, 5, 5)
47+
dest = WarpDest(64, 0)
4748
game.move_to(dest)
4849
game.game_map.get_area(64).name = 'Outer Limits'
4950
self.print_mission()
@@ -70,6 +71,7 @@ def run(self):
7071
self.destroyed = True
7172
game.display()
7273
self.display(Quips.jibe_fatal_mistake())
74+
game.display()
7375
game.display(';-)')
7476
return False
7577

0 commit comments

Comments
 (0)