Skip to content

Commit c54e1e9

Browse files
committed
Fixed game object reporting.
1 parent 5a9545d commit c54e1e9

9 files changed

+260
-231
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,6 @@
3131
/__pycache__/MapSparse.cpython-37.pyc
3232
/__pycache__/MapSparce.cpython-37.pyc
3333
/__pycache__/Console.cpython-37.pyc
34+
/__pycache__/ShipStarbase.cpython-37.pyc
35+
/__pycache__/ShipKlingon.cpython-37.pyc
36+
/__pycache__/ShipEnterprise.cpython-37.pyc

AbsShip.py

Lines changed: 0 additions & 210 deletions
Original file line numberDiff line numberDiff line change
@@ -15,213 +15,3 @@ def __init__(self):
1515
def get_glyph(self):
1616
pass
1717

18-
class ShipStarbase(AbsShip):
19-
20-
def __init__(self):
21-
super().__init__()
22-
23-
def get_glyph(self):
24-
return Glyphs.STARBASE
25-
26-
@staticmethod
27-
def dock_enterprise(ship):
28-
ship.energy = 3000
29-
ship.photon_torpedoes = 10
30-
ship.navigation_damage = 0
31-
ship.short_range_scan_damage = 0
32-
ship.long_range_scan_damage = 0
33-
ship.shield_control_damage = 0
34-
ship.computer_damage = 0
35-
ship.photon_damage = 0
36-
ship.phaser_damage = 0
37-
ship.shield_level = 0
38-
ship.docked = True
39-
40-
@staticmethod
41-
def launch_enterprise(ship):
42-
ship.docked = False
43-
44-
45-
class ShipEnterprise(AbsShip):
46-
47-
def __init__(self):
48-
super().__init__()
49-
self.energy = 0
50-
self.docked = False
51-
self.condition = "GREEN"
52-
self.navigation_damage = 0
53-
self.short_range_scan_damage = 0
54-
self.long_range_scan_damage = 0
55-
self.shield_control_damage = 0
56-
self.computer_damage = 0
57-
self.photon_damage = 0
58-
self.phaser_damage = 0
59-
self.photon_torpedoes = 0
60-
ShipStarbase.dock_enterprise(self)
61-
ShipStarbase.launch_enterprise(self)
62-
63-
def get_glyph(self):
64-
return Glyphs.ENTERPRISE
65-
66-
def damage(self, game, item):
67-
'''
68-
Damage the Enterprise.
69-
'''
70-
if game.is_testing:
71-
return
72-
if random.randint(0, 6) > 0:
73-
return
74-
damage = 1 + random.randint(0, 4)
75-
if item < 0:
76-
item = random.randint(0, 6)
77-
if item == 0:
78-
self.navigation_damage = damage
79-
game.display(Quips.jibe_damage('Warp Engines'))
80-
elif item == 1:
81-
self.short_range_scan_damage = damage
82-
game.display(Quips.jibe_damage('Short Range Scanners'))
83-
elif item == 2:
84-
self.long_range_scan_damage = damage
85-
game.display(Quips.jibe_damage('Long Range Scanners'))
86-
elif item == 3:
87-
self.shield_control_damage = damage
88-
game.display(Quips.jibe_damage('Shield Controls'))
89-
elif item == 4:
90-
self.computer_damage = damage
91-
game.display(Quips.jibe_damage('Main Computer'))
92-
elif item == 5:
93-
self.photon_damage = damage
94-
game.display(Quips.jibe_damage('Photon Torpedo Controls'))
95-
elif item == 6:
96-
self.phaser_damage = damage
97-
game.display(Quips.jibe_damage('Phasers'))
98-
game.display()
99-
100-
def repair(self, game):
101-
'''
102-
Repair damage to the Enterprise.
103-
'''
104-
if self.navigation_damage > 0:
105-
self.navigation_damage -= 1
106-
if self.navigation_damage == 0:
107-
game.display("Warp engines have been repaired.")
108-
game.display()
109-
return True
110-
if self.short_range_scan_damage > 0:
111-
self.short_range_scan_damage -= 1
112-
if self.short_range_scan_damage == 0:
113-
game.display("Short range scanner has been repaired.")
114-
self.display()
115-
return True
116-
if self.long_range_scan_damage > 0:
117-
self.long_range_scan_damage -= 1
118-
if self.long_range_scan_damage == 0:
119-
game.display("Long range scanner has been repaired.")
120-
game.display()
121-
return True
122-
if self.shield_control_damage > 0:
123-
self.shield_control_damage -= 1
124-
if self.shield_control_damage == 0:
125-
game.display("Shield controls have been repaired.")
126-
game.display()
127-
return True
128-
if self.computer_damage > 0:
129-
self.computer_damage -= 1
130-
if self.computer_damage == 0:
131-
game.display("The main computer has been repaired.")
132-
game.display()
133-
return True
134-
if self.photon_damage > 0:
135-
self.photon_damage -= 1
136-
if self.photon_damage == 0:
137-
game.display("Photon torpedo controls have been repaired.")
138-
game.display()
139-
return True
140-
if self.phaser_damage > 0:
141-
self.phaser_damage -= 1
142-
if self.phaser_damage == 0:
143-
game.display("Phasers have been repaired.")
144-
game.display()
145-
return True
146-
return False
147-
148-
def short_range_scan(self, game):
149-
if self.short_range_scan_damage > 0:
150-
game.display(Quips.jibe_damage('Short Ranged Scanners'))
151-
game.display()
152-
else:
153-
quad = game.game_map.quad()
154-
Quadrant.display_area(game, quad)
155-
game.display()
156-
157-
def long_range_scan(self, game):
158-
if self.long_range_scan_damage > 0:
159-
game.display(Quips.jibe_damage('Long Ranged Scanners'))
160-
game.display()
161-
return
162-
sb = ""
163-
pw_sector = game.game_map.sector
164-
if pw_sector < 5:
165-
pw_sector = 6
166-
elif pw_sector > 59:
167-
pw_sector = 59
168-
dots = None
169-
for peek in range(pw_sector-5, pw_sector + 6):
170-
quad = game.game_map.scan_quad(peek)
171-
lines = \
172-
(f"| Sector: {quad.number:>02}",
173-
f"Enemies: {quad.klingons:>02}",
174-
f"Bases: {quad.starbases:>02}",
175-
f"Stars: {quad.stars:>03} |")
176-
str_ = ' | '.join(lines)
177-
dots = '-' * len(str_) + "\n"
178-
sb += dots
179-
sb += str_
180-
game.display(sb)
181-
sb = ""
182-
game.display(dots)
183-
game.display()
184-
185-
186-
class ShipKlingon(AbsShip):
187-
188-
def __init__(self):
189-
super().__init__()
190-
self.xpos = 0
191-
self.ypos = 0
192-
self.shield_level = 0
193-
194-
def get_glyph(self):
195-
return Glyphs.KLINGON
196-
197-
def from_map(self, xpos, ypos):
198-
self.xpos = xpos
199-
self.ypos = ypos
200-
self.shield_level = 300 + random.randint(0, 199)
201-
202-
@staticmethod
203-
def attack(game):
204-
from Calculators import Calc
205-
kships = game.game_map.get_area_klingons()
206-
if len(kships) > 0:
207-
for ship in kships:
208-
if game.enterprise.docked:
209-
game.display("Enterprise hit by ship at sector [{0},{1}]. No damage due to starbase shields.".format(
210-
ship.xpos + 1, ship.ypos + 1
211-
))
212-
else:
213-
dist = Calc.distance(
214-
game.game_map.xpos, game.game_map.ypos, ship.xpos, ship.ypos)
215-
delivered_energy = 300 * \
216-
random.uniform(0.0, 1.0) * (1.0 - dist / 11.3)
217-
game.enterprise.shield_level -= int(delivered_energy)
218-
if game.enterprise.shield_level < 0:
219-
game.enterprise.shield_level = 0
220-
game.destroyed = True
221-
game.display("Enterprise hit by ship at sector [{0},{1}]. Shields dropped to {2}.".format(
222-
ship.xpos + 1, ship.ypos + 1, game.enterprise.shield_level
223-
))
224-
if game.enterprise.shield_level == 0:
225-
return True
226-
return True
227-
return False

Controls.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
import random
22

33
import TrekStrings
4-
from AbsShip import *
4+
import Glyphs
5+
from ShipKlingon import ShipKlingon
6+
from ShipKlingon import ShipKlingon
7+
#from ShipStarbase import ShipStarbase
8+
from ShipEnterprise import ShipEnterprise
59
from Calculators import Calc
610
from Reports import Stats
711
from Quips import Quips

MapGame.py

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import TrekStrings
33

44
import Glyphs
5-
from AbsShip import ShipKlingon
5+
from ShipKlingon import ShipKlingon
66
from Points import Destination
77
from Quadrant import Quadrant
88

@@ -116,7 +116,7 @@ def scan_quad(self, sector):
116116
return Quadrant.from_area(area)
117117
return Quadrant()
118118

119-
def _count(self, glyph):
119+
def _count_area(self, glyph):
120120
''' Tally the number of glyphs in the AREA '''
121121
count = 0
122122
area = self.area()
@@ -127,9 +127,11 @@ def _count(self, glyph):
127127
return count
128128

129129
def update_counts(self):
130-
self.klingons = self._count(Glyphs.KLINGON)
131-
self.starbases = self._count(Glyphs.STARBASE)
132-
self.stars = self._count(Glyphs.STAR)
130+
self.klingons = self.starbases = self.stars = 0
131+
for area in self.areas():
132+
self.klingons += area.count_glyphs(Glyphs.KLINGON)
133+
self.starbases += area.count_glyphs(Glyphs.STARBASE)
134+
self.stars += area.count_glyphs(Glyphs.STAR)
133135

134136
def remove_items(self, removed):
135137
area = self.area()
@@ -150,13 +152,13 @@ def get_area_klingons(self):
150152
return results
151153

152154
def num_area_klingons(self):
153-
return self._count(Glyphs.KLINGON)
155+
return self._count_area(Glyphs.KLINGON)
154156

155157
def num_area_starbases(self):
156-
return self._count(Glyphs.STARBASE)
158+
return self._count_area(Glyphs.STARBASE)
157159

158160
def num_area_stars(self):
159-
return self._count(Glyphs.STAR)
161+
return self._count_area(Glyphs.STAR)
160162

161163
def get_area_objects(self):
162164
'''

Reports.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@ def show_ship_status(game):
2121
@staticmethod
2222
def show_galactic_status(game):
2323
game.display()
24-
game.display("-------------------------------------------------")
25-
game.display(
26-
f"{Glyphs.KLINGON}{game.game_map.klingons}|" +
27-
f"{Glyphs.STARBASE}|{game.game_map.starbases}|" +
28-
f"{Glyphs.STAR}{game.game_map.stars}")
29-
game.display("-------------------------------------------------")
30-
game.display()
24+
str_ = f"| KLINGONS: {game.game_map.klingons:>04} | " + \
25+
f"STARBASES: {game.game_map.starbases:>04} | " + \
26+
f"STARS: {game.game_map.stars:>04} |"
27+
dots = len(str_) * '-'
28+
game.display(dots)
29+
game.display(str_)
30+
game.display(dots)
3131

3232

3333
@staticmethod

0 commit comments

Comments
 (0)