8
8
from torpydo .ship import Color , Letter , Position , Ship
9
9
from torpydo .game_controller import GameController
10
10
from torpydo .telemetryclient import TelemetryClient
11
-
11
+ from playsound import playsound
12
12
import time
13
13
14
14
myFleet = []
@@ -93,6 +93,7 @@ def start_game():
93
93
is_hit = GameController .check_is_hit (enemyFleet , position )
94
94
add_position_to_board (board , position , True )
95
95
96
+ is_hit_sound (is_hit )
96
97
start_colouring (right_colour (is_hit ))
97
98
print ("Yeah ! Nice hit !" if is_hit else "Miss" )
98
99
TelemetryClient .trackEvent ('Player_ShootPosition' , {'custom_dimensions' : {'Position' : str (position ), 'IsHit' : is_hit }})
@@ -109,6 +110,7 @@ def start_game():
109
110
110
111
end_colouring ()
111
112
if is_fleet_down (enemyFleet ):
113
+ playsound ("sound/fireworks.mp3" )
112
114
start_colouring (Fore .MAGENTA )
113
115
print ("Congratulations! You are the winner \o/" )
114
116
end_colouring ()
@@ -117,8 +119,9 @@ def start_game():
117
119
print ("\n \n Computer is thinking..." )
118
120
time .sleep (3 )
119
121
# Computer
120
- position = get_random_position ()
122
+ position = get_random_position (board )
121
123
is_hit = GameController .check_is_hit (myFleet , position )
124
+ is_hit_sound (is_hit )
122
125
add_position_to_board (board , position , True )
123
126
start_colouring (right_colour (is_hit ))
124
127
@@ -143,6 +146,12 @@ def start_game():
143
146
144
147
print ("Thank you for playing!" )
145
148
149
+ def is_hit_sound (is_hit ):
150
+ if is_hit :
151
+ playsound ("sound/explosion.mp3" )
152
+ else :
153
+ playsound ("sound/splash.mp3" )
154
+
146
155
def is_fleet_down (fleet ):
147
156
return all (ship .is_sunk for ship in fleet )
148
157
@@ -182,7 +191,7 @@ def initialize_game():
182
191
initialize_enemyFleet ()
183
192
initialize_myFleet ()
184
193
185
-
194
+
186
195
187
196
def initialize_myFleet ():
188
197
global myFleet
@@ -287,25 +296,16 @@ def place_this_ship(ship:Ship, st_point:Position, enemyFleet:List[Ship]):
287
296
else :
288
297
return False
289
298
290
- def get_random_position_2 ():
291
- rows = 8
292
- lines = 8
293
-
294
- letter = Letter (random .randint (1 , lines ))
295
- number = random .randint (1 , rows )
296
- position = Position (letter , number )
297
-
298
- return position
299
-
300
299
def initialize_enemyFleet ():
301
300
global enemyFleet
301
+ global board
302
302
303
303
enemyFleet = GameController .initialize_ships ()
304
304
305
305
for ship in enemyFleet :
306
- ship_strating_point = get_random_position_2 ( )
306
+ ship_strating_point = get_random_position ( board )
307
307
while not place_this_ship (ship ,ship_strating_point , enemyFleet ):
308
- ship_strating_point = get_random_position_2 ( )
308
+ ship_strating_point = get_random_position ( board )
309
309
310
310
311
311
#print(enemyFleet)
0 commit comments