app.ships module
- exception LocationOutsideOfRangeError
Bases:
IndexError
- exception IncorrectOrientationError
Bases:
ValueError
- exception UnlocatedShipHitError
Bases:
ValueError
- exception HitOutsideOfRangeError
Bases:
IndexError
- exception HitDestroyedSquareError
Bases:
IndexError
- class Ship(size: int)
Bases:
Sequence
Ship base object
- Parameters
size (int) – size of the ship
- property squares: list
List of the ship’s ‘squares’ containing
True
/False
values. (False
- destroyed)- Returns
squares
- Return type
list
- property size: int
Size of the ship - number of its squares
- Returns
size
- Return type
int
- property strength: int
Strength of the ship - number of undestroyed squares
- Returns
strength
- Return type
int
- property uuid: int
Ship’s unique identifier - used to identify it on the board
- Returns
uuid
- Return type
int
- property location: tuple | None
Ship location tuple
(x: int, y: int)
. If the location is not set it returnsNone
.- Returns
location
- Return type
tuple | None
- Raises
LocationOutsideOfRangeError – location is not on the board
- property orientation: str
Ship’s orientation
"UP", "DOWN", "LEFT","RIGHT"
Default:
"UP"
- Returns
orientation
- Return type
str
- Raises
IncorrectOrientationError – Orientation is not
"UP", "DOWN", "LEFT", "RIGHT"
- property under_edition
- take_a_hit(targetIndex: int)
Destroys a given square
- Parameters
targetIndex (int) – index of the square to be destroyed
- Raises
UnlocatedShipHitError – if the ship is not located
HitOutsideOfRangeError – if the targetIndex is not in range
HitDestroyedSquareError – if the targeted square already is
False
- Returns
strength after the hit (
0
is destroyed)- Return type
int
- _abc_impl = <_abc._abc_data object>
- class Carrier
Bases:
Ship
Ship with
self.size = BOAT_SIZES['Carrier']
(Default:5
)- _abc_impl = <_abc._abc_data object>
- class Battleship
Bases:
Ship
Ship with
self.size = BOAT_SIZES['Battleship']
(Default:4
)- _abc_impl = <_abc._abc_data object>
- class Destroyer
Bases:
Ship
Ship with
self.size = BOAT_SIZES['Destroyer']
(Default:3
)- _abc_impl = <_abc._abc_data object>
- class Submarine
Bases:
Ship
Ship with
self.size = BOAT_SIZES['Submarine']
(Default:3
)- _abc_impl = <_abc._abc_data object>
- class PatrolBoat
Bases:
Ship
Ship with self.size =
BOAT_SIZES['PatrolBoat']
(Default:2
)- _abc_impl = <_abc._abc_data object>
- get_default_ship_set()