我正在用python开发纸牌游戏。我已经制作了一张卡片 Class和一个Deck Class。我正在使用pygame,所以我制作了一个函数,将字符串卡片套装转换为符号以将它们显示在卡片顶部。我的问题是,在类中还是在类之外编写这些函数效率更高,为什么。谢谢!
里面:
class Card:
def __init__(self, value, suit):
self.value = value
self.suit = suit
def get_suit(self):
if self.suit == "Clubs":
return '♣'
elif self.suit == "Hearts":
return '♥'
elif self.suit == "Diamonds":
return '♦'
elif self.suit == "Spades":
return '♠'
def get_value(self):
if self.value >= 7 and self.value <= 10:
return self.value
elif self.value == 11:
return "J"
elif self.value == 12:
return "Q"
elif self.value == 13:
return "K"
elif self.value == 14:
return "A"
或外面:
def get_suit(suit):
if suit == "Clubs":
return '♣'
elif suit == "Hearts":
return '♥'
elif suit == "Diamonds":
return '♦'
elif suit == "Spades":
return '♠'
def get_value(value):
if value >= 7 and value <= 10:
return value
elif value == 11:
return "J"
elif value == 12:
return "Q"
elif value == 13:
return "K"
elif value == 14:
return "A"
class Card:
def __init__(self, value, suit):
self.value = value
self.suit = suit