Question: Can someone help me out with this Python assignment? The task is to create a simple Battleship class in Python and test it. A ship

Can someone help me out with this Python assignment?

"The task is to create a simple Battleship class in Python and test it. A ship has the properties start_x, start_y, length, direction and amount of hits. A ship must have following methods.

- A constructor that makes the ship. It should take values of all the the qualities except amount of hits as parameters. You can use the length 2 and direction horizontal as default values. Amount of hits should be set to 0. A __str__ method that makes and returns a string that should as a minimum contain start coordinates, length and amount of hits.

- A method hit() that registers that the ship has been hit through increasing the hit quality by 1.

- A method is_sunk that returns True if the ship has sunk and False if not

You have to make this class as well as a if__name__ == <<__main__>>: block that tests it through making at least two ships with different lenghts and shoots at them with hits() until they sink, but not further."

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!