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
@@ -291,9 +300,9 @@ def initialize_enemyFleet():
291
300
enemyFleet = GameController .initialize_ships ()
292
301
293
302
for ship in enemyFleet :
294
- ship_strating_point = get_random_position ()
303
+ ship_strating_point = get_random_position (board )
295
304
while not place_this_ship (ship ,ship_strating_point , enemyFleet ):
296
- ship_strating_point = get_random_position ()
305
+ ship_strating_point = get_random_position (board )
297
306
298
307
299
308
# print(enemyFleet)
0 commit comments