Ships user C • Create a Ship.py module that contains a Ship class • The private members for the ship class should be – length (integer) doput on Te puthon – name (string) Vser – orientation (‘x’ or ‘y’) The methods should be Please use – __init_(name, length) – set Length (len) Variables, lens, loops, – get Length() etc. – set Name (shipname) – getName() – set orientation (orient) – get orientation () Battleships d In Pudhan of etc. • Create a Battleship.py module that contains a Battleship class and imports your ship class and random • The private member for the ship class should be Please use a -board (2D list that’s 10 x 10) • The methods should be Variables, len, loop, – __init__0 – creates an empty 10 x 10 board marked with O’s – put Ship (ship) – randomly selects a position to place a ship on the board using the ships orientation (x: horizontal, y: vertical) and marks coordinates with the first letter of the ship name. • Ships cannot over lap or lay diagonally or be placed outside the board – createShips () – creates 4 ships with random orientations and calls put Ship (ship) to put ships on the board • Destroyer: length = 1 • Submarine: length = 2 • Battleship: length = 3 • Carrier: length = 4 Battleships In Python Please use : Variables, lens, . The methods (cont.) loos, ete – getMove () – gets input from the user in the form of a letter (A-J) and number (0-9) that coincides with a coordinate on the board. It should keep asking user for input until they enter correct coordinates. – makeMove (coordinate) – Takes a parameter, marks the board and prints • “Missed”. If no ship is at the coordinate, marks with M • “Hit (ship name)” – if a ship is at the coordinate, marks with X • “You sunk the [ship name)” – If the whole ship has been marked – isGameOver() – Returns true if all ships are marked, false otherwise. – printBoard() – Prints the board with coordinates Play Battleships • Create a playBattleship.py file that imports your Battleship class • Add a function playGame (bship) that takes a Battleship parameter, calls CreateShips () and repeatedly calls getMove () and makeMove () until isGameOver() returns true then calls print Board() • Add a main() function that creates an instance of your Battleship class and passes it to playGame() Sample Output Output Enter your move: 15 Missed. Enter your move: H3 Hit Destroyer. You sunk the Destroyer! Game over A B C D E ооооо 1 омх 2 оооо з ооом 4 ooooo 5 омо 6 оох мооо 7 ooхooox x x x 8 омхмоооооо 9 ооооооооо нZooooxoxo ооооооохоо Notes Show transcribed image text Ships user C • Create a Ship.py module that contains a Ship class • The private members for the ship class should be – length (integer) doput on Te puthon – name (string) Vser – orientation (‘x’ or ‘y’) The methods should be Please use – __init_(name, length) – set Length (len) Variables, lens, loops, – get Length() etc. – set Name (shipname) – getName() – set orientation (orient) – get orientation () Battleships d In Pudhan of etc. • Create a Battleship.py module that contains a Battleship class and imports your ship class and random • The private member for the ship class should be Please use a -board (2D list that’s 10 x 10) • The methods should be Variables, len, loop, – __init__0 – creates an empty 10 x 10 board marked with O’s – put Ship (ship) – randomly selects a position to place a ship on the board using the ships orientation (x: horizontal, y: vertical) and marks coordinates with the first letter of the ship name. • Ships cannot over lap or lay diagonally or be placed outside the board – createShips () – creates 4 ships with random orientations and calls put Ship (ship) to put ships on the board • Destroyer: length = 1 • Submarine: length = 2 • Battleship: length = 3 • Carrier: length = 4
Battleships In Python Please use : Variables, lens, . The methods (cont.) loos, ete – getMove () – gets input from the user in the form of a letter (A-J) and number (0-9) that coincides with a coordinate on the board. It should keep asking user for input until they enter correct coordinates. – makeMove (coordinate) – Takes a parameter, marks the board and prints • “Missed”. If no ship is at the coordinate, marks with M • “Hit (ship name)” – if a ship is at the coordinate, marks with X • “You sunk the [ship name)” – If the whole ship has been marked – isGameOver() – Returns true if all ships are marked, false otherwise. – printBoard() – Prints the board with coordinates Play Battleships • Create a playBattleship.py file that imports your Battleship class • Add a function playGame (bship) that takes a Battleship parameter, calls CreateShips () and repeatedly calls getMove () and makeMove () until isGameOver() returns true then calls print Board() • Add a main() function that creates an instance of your Battleship class and passes it to playGame()
Sample Output Output Enter your move: 15 Missed. Enter your move: H3 Hit Destroyer. You sunk the Destroyer! Game over A B C D E ооооо 1 омх 2 оооо з ооом 4 ooooo 5 омо 6 оох мооо 7 ooхooox x x x 8 омхмоооооо 9 ооооооооо нZooooxoxo ооооооохоо Notes
Expert Answer
Answer to Ships user C • Create a Ship.py module that contains a Ship class • The private members for the ship class should be…