我正在创造一种通过五个玩家手牌传递五张扑克牌的方法。我已经在main()
中创建了一种方法,但是我正在寻找一个创建一个函数的想法,该函数将卡片传递给另一只手,所以我不会在{{1}中重复我的代码行。 }}。只需要一些想法。
main()
答案 0 :(得分:0)
我想出了这个:
def passAgain():
# This line create all empty Hand objects.
table_hands = [Hand() for _ in range(5)]
# These 3 lines creates the 5 cards involved
for value in ["A", "2", "3", "4", "5"]:
for suite in ["s"]:
table_hands[0].add(Card(value, suite))
# Cycle the hands
for i, hand in enumerate(table_hands):
# Create pairs of hands, one giving and another receiving.
hands_passing = table_hands[i:i + 2]
if len(hands_passing) == 2:
# If we have two hands involved, create a list of cards that
# will be given.
giving_hand = hands_passing[0].cards[:]
for card in giving_hand:
hands_passing[0].give(card, hands_passing[1])
print(table_hands)
def main():
while True :
ans = input("Do you want to pass cards? Press y or yes: ")
if ans in ("y", "yes"):
passAgain()
else:
break