* 3.7_10 change show

This commit is contained in:
Dmitry Belyaev 2024-04-15 14:56:04 +03:00
parent 20898206a7
commit 4e887c7782

View File

@ -69,26 +69,37 @@ Traceback (most recent call last):
...
IndexError: Недопустимый индекс
>>> pole.show_pole()
P.S. В программе на экран выводить ничего не нужно, только объявить классы.
"""
import random
from typing import Final, List
from typing import Dict, Final, List, Tuple
class SingletonMeta(type):
_instances = {}
_instances: Dict[type, type] = {}
def __call__(cls, *args, **kwargs):
if cls not in cls._instances:
@ -141,15 +152,8 @@ class Cell:
class GamePole(metaclass=SingletonMeta):
around_offsets = (
(-1, -1),
(-1, 0),
(-1, 1),
(0, -1),
(0, 1),
(1, -1),
(1, 0),
(1, 1),
around_offsets: Final[Tuple[Tuple[int, int], ...]] = tuple(
(dx, dy) for dx in range(-1, 2) for dy in range(-1, 2) if (dx, dy) != (0, 0)
)
def __init__(self, N: int, M: int, total_mines: int, pole=None):
@ -212,7 +216,15 @@ class GamePole(metaclass=SingletonMeta):
self.open_cell(i, j)
def __str__(self):
return "\n".join(" ".join(map(str, row)) for row in self.pole)
c = self.M - 1
result = (
f"╭─{'──┬─' * c}──╮\n"
+ f"├─{'──┼─' * c}──┤\n".join(
map(lambda row: f"{''.join(map(str, row))}\n", self.pole)
)
+ f"╰─{'──┴─' * c}──╯"
)
return result
def show_pole(self):
print(self)
@ -268,5 +280,7 @@ if __name__ == "__main__":
pole_game = GamePole(10, 8, 12)
pole_game.open_random(30)
pole_game.show_pole()
pole_game.open()
pole_game.show_pole()
else:
tests()