| 1 | 1 | | class MineItem: |
| 1 | 2 | | _is_bomb: bool = False |
| 1 | 3 | | _is_cover: bool = True |
| 1 | 4 | | near_bombs_count: int = 0 |
| | 5 | |
|
| 1 | 6 | | def __init__(self, near_items=()): |
| 1 | 7 | | self.near_items = near_items |
| | 8 | |
|
| 1 | 9 | | def set_bomb(self): |
| 1 | 10 | | self._is_bomb = True |
| 1 | 11 | | for item in self.near_items: |
| 1 | 12 | | item.near_bombs_count += 1 |
| | 13 | |
|
| 1 | 14 | | @property |
| 1 | 15 | | def is_bomb(self): |
| 1 | 16 | | return self._is_bomb |
| | 17 | |
|
| 1 | 18 | | def __str__(self): |
| 1 | 19 | | if self._is_cover: |
| 1 | 20 | | return "." |
| 1 | 21 | | if self.is_bomb: |
| 1 | 22 | | return "*" |
| 1 | 23 | | return str(self.near_bombs_count) |
| | 24 | |
|
| 1 | 25 | | def click(self): |
| 1 | 26 | | if self._is_cover is False: |
| 1 | 27 | | return |
| 1 | 28 | | self._is_cover = False |
| | 29 | |
|
| 1 | 30 | | if self.near_bombs_count is 0: |
| 1 | 31 | | for item in self.near_items: |
| 1 | 32 | | item.click() |