Overriding and inheritance seem to work differently than I expect, let me explain this situation. I have three classes: Map, Treasure, and Copper. Copper inherits from the Treasure and Treasure inherits from the Card. The only difference between Treasure and Card is the only method that Treasure overrides. The only difference between Treasure and Copper is the attribute that copper redefines. The attribute that Copper overrides originally belongs to the Map, and this is the attribute that Treasure uses in its unique method. The problem I'm facing is that when calling the Copper method, which it inherits from Treasure, it still uses the value of the Card attribute, not the value of the attribute that copper should override. Below is some code,any help is appreciated.
Card Class:
class Card:
normal_full_table = 6
pile_player_rate = 10
@staticmethod
def pile_setup(player_count):
pass
Treasure Class:
from card.card import Card
from math import floor
class Treasure(Card):
@staticmethod
def pile_setup(player_count):
return (floor(player_count/Card.normal_full_table) + 1) * Card.pile_player_rate
Copper class:
from card.basic.card_treasure import Treasure
class Copper(Treasure):
pile_player_rate = 60
What I expect will happen when Copper.pile_setup (6) is called, that pile_player_rate is 60 because Copper overrides that value, but it doesn’t matter anyway 10. Why is this? Is it because I say specifically Card.pile_player_rate? How can I get Copper to use its unique value for pile_player_rate, rather than the total in the Map? Thank.
source
share