rename field to tile, add mine attr, adjust factory to new attr
This commit is contained in:
parent
cc79adb81a
commit
d6caa9aad9
@ -1,4 +0,0 @@
|
|||||||
class Field:
|
|
||||||
def __init__(self, number: int, is_mined: bool):
|
|
||||||
self.number = number
|
|
||||||
self.is_mined = is_mined
|
|
@ -1,14 +0,0 @@
|
|||||||
from typing import List
|
|
||||||
|
|
||||||
from field import Field
|
|
||||||
|
|
||||||
|
|
||||||
class FieldsFactory:
|
|
||||||
def create_field(self, number: int) -> Field:
|
|
||||||
if number > 3:
|
|
||||||
return Field(number, True)
|
|
||||||
else:
|
|
||||||
return Field(number, False)
|
|
||||||
|
|
||||||
def get_fields_list(self) -> List[Field]:
|
|
||||||
return [self.create_field(i) for i in range(11)]
|
|
10
src/tile.py
Normal file
10
src/tile.py
Normal file
@ -0,0 +1,10 @@
|
|||||||
|
from typing import Union
|
||||||
|
|
||||||
|
from ap_mine import APMine
|
||||||
|
from at_mine import ATMine
|
||||||
|
|
||||||
|
|
||||||
|
class Tile:
|
||||||
|
def __init__(self, number: int, mine: Union[None, APMine, ATMine] = None):
|
||||||
|
self.number = number
|
||||||
|
self.mine = mine
|
18
src/tilesFactory.py
Normal file
18
src/tilesFactory.py
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
from typing import List
|
||||||
|
from importlib import import_module
|
||||||
|
|
||||||
|
from tile import Tile
|
||||||
|
from const import IMAGES
|
||||||
|
|
||||||
|
|
||||||
|
class TilesFactory:
|
||||||
|
def create_tile(self, number: int) -> Tile:
|
||||||
|
img = IMAGES[number]
|
||||||
|
if img.mine_type:
|
||||||
|
module = import_module(f'{img.mine_type.lower()}_mine')
|
||||||
|
return Tile(number, getattr(module, f'{img.mine_type}Mine'))
|
||||||
|
else:
|
||||||
|
return Tile(number, None)
|
||||||
|
|
||||||
|
def get_tiles_list(self) -> List[Tile]:
|
||||||
|
return [self.create_tile(i) for i in range(11)]
|
Loading…
Reference in New Issue
Block a user