Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1from abc import ABC, abstractmethod
3from banco_imobiliario.config import settings
6class BasePlayer(ABC):
8 def __init__(
9 self, strategy, position=0,
10 money=settings.ENV_PLAYER_MONEY
11 ):
12 self.position = position
13 self.money = money
14 self.strategy = strategy
15 self.gameover = False
17 def __str__(self):
18 return f"{self.strategy}"
20 def __repr__(self):
21 return f"{self.strategy}"
23 def income_or_sale(self, patrimony, board=None):
24 if patrimony.type_of_strategy:
25 if self != patrimony.type_of_strategy:
26 self.paid(patrimony.rental_price, patrimony.type_of_strategy)
27 return
29 if self._roles_to_payment(patrimony):
30 patrimony.type_of_strategy = self
32 @abstractmethod
33 def _roles_to_payment(self, patrimony, board):
34 raise NotImplementedError()
36 def paid(self, property_price, type_of_strategy=None):
37 self.money -= property_price
38 if type_of_strategy:
39 type_of_strategy.money += property_price
40 if not self.money:
41 self.gameover = True