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
@@ -182,7 +191,7 @@ def initialize_game():
182191 initialize_enemyFleet ()
183192 initialize_myFleet ()
184193
185-
194+
186195
187196def initialize_myFleet ():
188197 global myFleet
@@ -287,25 +296,16 @@ def place_this_ship(ship:Ship, st_point:Position, enemyFleet:List[Ship]):
287296 else :
288297 return False
289298
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-
300299def initialize_enemyFleet ():
301300 global enemyFleet
301+ global board
302302
303303 enemyFleet = GameController .initialize_ships ()
304304
305305 for ship in enemyFleet :
306- ship_strating_point = get_random_position_2 ( )
306+ ship_strating_point = get_random_position ( board )
307307 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 )
309309
310310
311311 #print(enemyFleet)
0 commit comments