Question
The battleship game is basically as follows: -It consists of two boards, one for each player, on 10x10 squares-Each player has 6 ships, one with
The battleship game is basically as follows: -It consists of two boards, one for each player, on 10x10 squares-Each player has 6 ships, one with length 5, two with length 4, two with length 3 and one with length 2-Eachplayer should place his ships out on the board as he pleases.The ships can stand either horizontally or vertically.The ships can not overlap or cross each other.-Then each player should try to shoot down the ships of the other player.In turn, the player says which route he / she is shooting on.The opponent says if he hit a ship and if the ship sank.A player can only shoot on the same route once.The player basically does not know where the opponent has placed his ships.-A ship sinks if all the squares it is in have been shot at by the opponent.-A player loses the game when all his / her ships are sunk.The other player wins.
The task is to create and test the class for a simple ship game.A ship has the properties start_x, start_y, direction, length, and the number of hits the ship has taken.A ship shall have the following methods: -A constructor who makes the ship.The designer must take values of all properties except the number of hits as parameters.You can use length 2 and horizontal direction as default values. The number of hits should be set equal to 0.
A __str__ method that creates and returns a string that at least contains the start coordinates, length and number of hits the ship has taken -A method hit () that registers that the ship has taken a hit by increasing the number of hits property by 1-A method is_sunk that returns Trueif the ship is sunk and False if it is still floating.
You will create this class as well as an if __name__ == __main__: block that tests it by making at least two ships, of different lengths, and shoots them with hits () until they sink, but no longer.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started