-
Notifications
You must be signed in to change notification settings - Fork 3
/
ship.py
40 lines (30 loc) · 916 Bytes
/
ship.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
from abc import ABC
class Ship(ABC):
def __init__(self, name, size):
self.name = name
self._size = size
@property
def size(self):
return self._size
def take_hit(self):
self._size -= 1
return self.get_hit_report()
def __str__(self):
return f"{type(self).__name__} {self.name}"
def get_hit_report(self):
if self._size > 0:
return str(self) + f" is criticaly hit. Remaining health: {self._size}"
else:
return str(self) + f" has been destroyed"
class AirCraftCarrier(Ship):
def __init__(self, name):
super().__init__(name, 5)
class Destroyer(Ship):
def __init__(self, name):
super().__init__(name, 3)
class SmallBoat(Ship):
def __init__(self, name):
super().__init__(name, 1)
class Submarine(Ship):
def __init__(self, name):
super().__init__(name, 2)