88from torpydo .ship import Color , Letter , Position , Ship
99from torpydo .game_controller import GameController
1010from torpydo .telemetryclient import TelemetryClient
11-
11+ from playsound import playsound
1212import time
1313
1414myFleet = []
@@ -93,6 +93,7 @@ def start_game():
9393 is_hit = GameController .check_is_hit (enemyFleet , position )
9494 add_position_to_board (board , position , True )
9595
96+ is_hit_sound (is_hit )
9697 start_colouring (right_colour (is_hit ))
9798 print ("Yeah ! Nice hit !" if is_hit else "Miss" )
9899 TelemetryClient .trackEvent ('Player_ShootPosition' , {'custom_dimensions' : {'Position' : str (position ), 'IsHit' : is_hit }})
@@ -109,6 +110,7 @@ def start_game():
109110
110111 end_colouring ()
111112 if is_fleet_down (enemyFleet ):
113+ playsound ("sound/fireworks.mp3" )
112114 start_colouring (Fore .MAGENTA )
113115 print ("Congratulations! You are the winner \o/" )
114116 end_colouring ()
@@ -117,8 +119,9 @@ def start_game():
117119 print ("\n \n Computer is thinking..." )
118120 time .sleep (3 )
119121 # Computer
120- position = get_random_position ()
122+ position = get_random_position (board )
121123 is_hit = GameController .check_is_hit (myFleet , position )
124+ is_hit_sound (is_hit )
122125 add_position_to_board (board , position , True )
123126 start_colouring (right_colour (is_hit ))
124127
@@ -143,6 +146,12 @@ def start_game():
143146
144147 print ("Thank you for playing!" )
145148
149+ def is_hit_sound (is_hit ):
150+ if is_hit :
151+ playsound ("sound/explosion.mp3" )
152+ else :
153+ playsound ("sound/splash.mp3" )
154+
146155def is_fleet_down (fleet ):
147156 return all (ship .is_sunk for ship in fleet )
148157
@@ -291,9 +300,9 @@ def initialize_enemyFleet():
291300 enemyFleet = GameController .initialize_ships ()
292301
293302 for ship in enemyFleet :
294- ship_strating_point = get_random_position ()
303+ ship_strating_point = get_random_position (board )
295304 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 )
297306
298307
299308 # print(enemyFleet)
0 commit comments