Question: python assigment The task is to create a single class for an imaginary game as well as to create code that tests this class and

python assigment

The task is to create a single class for an imaginary game as well as to create code that tests this class and checks that it works. It is possible that a simple singleplayer version of the entire game is given as Exercise 8, and that a GUI version is given as Exercise 10. The Game Battleship The Battleship game is basically as follows: -It consists of two boards, one for each player, of 10x10 router-Each player has 6 ships, one with length 5, two with length 4, two with length 3 and one with length 2-Each player must place his ships out on the board as he wishes. 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 The task in Exercise 5 is to create and test the class for a single 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, the length and number of hits the ship has taken -A method hits () that registers that the ship has taken a hit by increasing the number of hits property by 1-A method is_sunk that returns True if 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

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!