Skip to content

Commit e4bd3a4

Browse files
committed
Random damage & probability updates.
1 parent 1ed13d0 commit e4bd3a4

14 files changed

+244
-162
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@
3535
/__pycache__/ShipKlingon.cpython-37.pyc
3636
/__pycache__/ShipEnterprise.cpython-37.pyc
3737
/__pycache__/ErrorCollision.cpython-37.pyc
38+
/__pycache__/Sector.cpython-37.pyc
39+
/__pycache__/Difficulity.cpython-37.pyc

AbsShip.py

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

44
import Glyphs
55
from Quips import Quips
6-
from Quadrant import Quadrant
6+
from Sector import Sector
77

88
class AbsShip(abc.ABC):
99
''' The first step, into a much larger universe ... '''

Calculators.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from MapGame import *
55
from AbsShip import *
66
from Points import *
7+
from Difficulity import Probabilities
78

89
class Calc():
910

@@ -36,11 +37,11 @@ def sublight_navigation(game):
3637
game.display("Enterprise successfully docked with starbase.")
3738
game.display()
3839
else:
39-
if game.game_map.klingons > 0:
40+
if game.game_map.count_area_klingons() > 0:
4041
ShipKlingon.attack_if_you_can(game)
4142
game.display()
4243
elif not game.enterprise.repair(game):
43-
game.enterprise.damage(game, -1)
44+
game.enterprise.damage(game, Probabilities.LRS)
4445

4546
@staticmethod
4647
def warp_navigation(game):
@@ -80,11 +81,11 @@ def warp_navigation(game):
8081
game.display("Enterprise successfully docked with starbase.")
8182
game.display()
8283
else:
83-
if game.game_map.klingons > 0:
84+
if game.game_map.count_area_klingons() > 0:
8485
ShipKlingon.attack_if_you_can(game)
8586
game.display()
8687
elif not game.enterprise.repair(game):
87-
game.enterprise.damage(game, -1)
88+
game.enterprise.damage(game, Probabilities.RANDOM)
8889

8990

9091
@staticmethod
@@ -107,15 +108,11 @@ def show_torp_targets(game):
107108
game.display()
108109
kships = game.game_map.get_area_klingons()
109110
if len(kships) == 0:
110-
game.display("There are no enemies in this quadrant.")
111+
game.display("There are no enemies in this sector.")
111112
return
112113

113114
game.display("Enemies:")
114115
for ship in kships:
115116
game.display(f"\tKlingon [{ship.xpos},{ship.ypos}].")
116117
game.display()
117118

118-
119-
120-
121-

Controls.py

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
from Calculators import Calc
1010
from Reports import Stats
1111
from Quips import Quips
12+
from Difficulity import Probabilities
1213

1314
class Control():
1415

@@ -32,7 +33,7 @@ def computer(game):
3233
game.display()
3334
game.display("Invalid computer command.")
3435
game.display()
35-
game.enterprise.damage(game, 4)
36+
game.enterprise.damage(game, Probabilities.COMPUTER)
3637

3738

3839
@staticmethod
@@ -43,7 +44,7 @@ def phasers(game):
4344
return
4445
kships = game.game_map.get_area_klingons()
4546
if len(kships) == 0:
46-
game.display("There are no Klingon ships in this quadrant.")
47+
game.display("There are no Klingon ships in this sector.")
4748
game.display()
4849
return
4950
game.display("Phasers locked on target.")
@@ -72,11 +73,12 @@ def phasers(game):
7273
else:
7374
game.display(f"Hit ship at [{ship.xpos + 1},{ship.ypos + 1}].")
7475
game.display(f"Enemy shield down to {ship.shield_level}.")
75-
game.game_map.remove_items(destroyed_ships)
76-
if game.game_map.klingons > 0:
76+
game.game_map.remove_area_items(destroyed_ships)
77+
if game.game_map.count_area_klingons() > 0:
7778
game.display()
7879
ShipKlingon.attack_if_you_can(game)
7980
game.display()
81+
game.enterprise.damage(game, Probabilities.PHASERS)
8082

8183

8284
def shields(game):
@@ -111,6 +113,7 @@ def shields(game):
111113
game.enterprise.shield_level -= int(transfer)
112114
game.display("Shield strength is now {0}. Energy level is now {1}.".format(game.enterprise.shield_level, game.enterprise.energy))
113115
game.display()
116+
game.enterprise.damage(game, Probabilities.SHIELDS)
114117

115118

116119
def torpedos(game):
@@ -122,8 +125,8 @@ def torpedos(game):
122125
game.display("Photon torpedoes exhausted.")
123126
game.display()
124127
return
125-
if len(game.game_map.get_area_klingons()) == 0:
126-
game.display("There are no Klingon ships in this quadrant.")
128+
if game.game_map.count_area_klingons() == 0:
129+
game.display("There are no Klingon ships in this sector.")
127130
game.display()
128131
return
129132
shot = game.read_xypos()
@@ -140,33 +143,34 @@ def torpedos(game):
140143
print(f'{ship.glyph}({ship.xpos},{ship.ypos}), shot({shot.xpos},{shot.ypos})')
141144
if ship.xpos == shot.xpos and ship.ypos == shot.ypos:
142145
if ship.glyph == Glyphs.KLINGON:
143-
num = game.game_map.game_id(ship)
146+
num = game.game_map.get_game_id(ship)
144147
game.display(f"Klingon ship #{num} destroyed.")
145148
game.display(Quips.jibe_defeat('enemy'))
146-
game.game_map.remove_items([ship])
149+
game.game_map.remove_area_items([ship])
147150
hit = True
148151
break
149152
elif ship.glyph == Glyphs.STARBASE:
150-
game.game_map.starbases -= 1
151-
num = game.game_map.game_id(ship)
153+
game.game_map.game_starbases -= 1
154+
num = game.game_map.get_game_id(ship)
152155
game.display("Federation Starbase #{num} destroyed!")
153156
game.display(Quips.jibe_defeat('commander'))
154-
game.game_map.remove_items([ship])
157+
game.game_map.remove_area_items([ship])
155158
hit = True
156159
break
157160
elif ship.glyph == Glyphs.STAR:
158-
num = game.game_map.game_id(ship)
161+
num = game.game_map.get_game_id(ship)
159162
game.display(f"Torpedo vaporizes star #{num}!")
160163
game.display(Quips.jibe_defeat('academic'))
161-
game.game_map.remove_items([ship])
164+
game.game_map.remove_area_items([ship])
162165
hit = True
163166
break
164167
if not hit:
165168
game.display("Torpedo missed.")
166-
if len(game.game_map.get_area_klingons()) > 0:
169+
if game.game_map.count_area_klingons() > 0:
167170
game.display()
168171
ShipKlingon.attack_if_you_can(game)
169172
game.display()
173+
game.enterprise.damage(game, Probabilities.PHOTON)
170174

171175

172176

Difficulity.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import random
2+
3+
class Probabilities:
4+
'''
5+
Extracting allows for easier customization.
6+
'''
7+
_LEVEL = 4
8+
RANDOM = -1
9+
NAV = 0
10+
SRS = 1
11+
LRS = 2
12+
SHIELDS = 3
13+
COMPUTER = 4
14+
PHOTON = 5
15+
PHASERS = 6
16+
17+
@staticmethod
18+
def set_difficulity(game, level):
19+
'''
20+
The HIGHER the level, the MORE difficult
21+
the game will be. 0 = EASY, 6 = HIGHEST
22+
'''
23+
if level < 0: level = 0
24+
if level > 6: level = 6
25+
Probabilities._LEVEL = level
26+
27+
@staticmethod
28+
def calc_damage(game, item):
29+
'''
30+
How mch damage?
31+
'''
32+
return random.randint(1, 3)
33+
34+
@staticmethod
35+
def should_damage_enterprise(game, item):
36+
'''
37+
Should we damage?
38+
Lowest level (above) eliminates damage to ITEM
39+
'''
40+
if game.is_testing:
41+
return False
42+
if item == Probabilities.SHIELDS:
43+
return False
44+
if random.randint(0, 6) < Probabilities._LEVEL:
45+
return True
46+
return False
47+
48+
49+

0 commit comments

Comments
 (0)