Program Description
Write a program that simulates a Destroyer’s depth charge attack on a submarine. The program will start by placing a rectangle, which represents the submarine, of random height and width at a random (x, y) position. This position represents the top left corner of the submarine. Assume the height of the submarine can only be between 10-20 meters and the length can only be between 40-70 meters. Assume your world starts with (0,0) in the top left corner and moves on to a maximum value of (300, 300) at the bottom right corner. No portion of the rectangle can be placed outside of the world as your intelligence tells you that the sub must be within this 300x300 meter area.
Ask the user to enter the (x, y) position of a circle, which represents a depth charge with a blast radius of 30 meters. Be sure to check that no part of the circle is found outside of the world by defining a method called circleLegal().
Create a method called directHit() which returns True if any part of the submarine is within 30 units from the depth charge. The method should return False otherwise.
Create a method named indirectHit() that returns True if any part of the submarine is within 50 units from the depth charge. The method should return False otherwise.
Use the methods above to output detailed messages about the status of the submarine. If the circle touches the rectangle, there has been a direct hit and the submarine is destroyed. If the circle is within 50 meters the radius of the circle we have a near miss and the submarine has taken damage. If a submarine has been damaged, another near miss will sink the sub.
The Destroyer has 5 depth charges. Good luck Captain!
Sample Output
Submarine has been spotted! Enter the x position of the depth charge: 500 Error! The submarine is within this 300x300 meter area! Re-enter the x position of the depth charge: 200 Enter the y position of the depth charge: 200 ** Intelligence shows the submarine has not taken damage. ** Enter the x position of the depth charge: 298 Error! The depth charge must explode within the spotted area! Re-enter the x position of the depth charge: 150 Enter the y position of the depth charge: 155 ** Direct Hit! ** The submarine has been destroyed! Another submarine has been spotted! Would you like to engage? No