import random
class Card:
cards = []
player1 = []
player2 = []
player3 = []
player4 = []
def __init__(self, name):
self.name = name
def __str__(self):
return self.name
@classmethod
def init_cards(cls):
wan = ("一万", "二万", "三万", "四万", "五万", "六万", "七万", "八万", "九万",
"一万", "二万", "三万", "四万", "五万", "六万", "七万", "八万", "九万",
"一万", "二万", "三万", "四万", "五万", "六万", "七万", "八万", "九万",
"一万", "二万", "三万", "四万", "五万", "六万", "七万", "八万", "九万")
tong = ("幺鸡", "二筒", "三筒", "四筒", "五筒", "六筒", "七筒", "八筒", "九筒",
"幺鸡", "二筒", "三筒", "四筒", "五筒", "六筒", "七筒", "八筒", "九筒",
"幺鸡", "二筒", "三筒", "四筒", "五筒", "六筒", "七筒", "八筒", "九筒",
"幺鸡", "二筒", "三筒", "四筒", "五筒", "六筒", "七筒", "八筒", "九筒",
"幺鸡", "二筒", "三筒", "四筒", "五筒", "六筒", "七筒", "八筒", "九筒")
tiao = ("一条", "二条", "三条", "四条", "五条", "六条", "七条", "八条", "九条",
"一条", "二条", "三条", "四条", "五条", "六条", "七条", "八条", "九条",
"一条", "二条", "三条", "四条", "五条", "六条", "七条", "八条", "九条",
"一条", "二条", "三条", "四条", "五条", "六条", "七条", "八条", "九条")
wind = ("东风", "西风", "南风", "北风", "东风", "西风", "南风", "北风",
"东风", "西风", "南风", "北风", "东风", "西风", "南风", "北风",
"东风", "西风", "南风", "北风", "东风", "西风", "南风", "北风",
"东风", "西风", "南风", "北风", "东风", "西风", "南风", "北风")
word = ("红中", "发财", "白板", "红中", "发财", "白板",
"红中", "发财", "白板", "红中", "发财", "白板",
"红中", "发财", "白板", "红中", "发财", "白板",
"红中", "发财", "白板", "红中", "发财", "白板")
for wa in wan:
a = Card(wa)
cls.cards.append(a)
for to in tong:
b = Card(to)
cls.cards.append(b)
for ti in tiao:
c = Card(ti)
cls.cards.append(c)
for wi in wind:
d = Card(wi)
cls.cards.append(d)
for wo in word:
e = Card(wo)
cls.cards.append(e)
@classmethod
def show_cards(cls):
for card in cls.cards:
print(card, end=" ")
print()
@classmethod
def wash_cards(cls):
idxx = random.randint(1, 136)
for idx in range(136):
cls.cards[idx], cls.cards[idxx] = cls.cards[idxx], cls.cards[idx]
@classmethod
def send_cards(cls):
x = random.randint(2, 12)
for _ in range(3):
for _ in range(4):
cls.player1.append(cls.cards.pop(2 * x))
for _ in range(4):
cls.player2.append(cls.cards.pop(2 * x))
for _ in range(4):
cls.player3.append(cls.cards.pop(2 * x))
for _ in range(4):
cls.player4.append(cls.cards.pop(2 * x))
cls.player1.append(cls.cards.pop(2 * x))
cls.player2.append(cls.cards.pop(2 * x))
cls.player3.append(cls.cards.pop(2 * x))
cls.player4.append(cls.cards.pop(2 * x))
@classmethod
def show_player(cls):
print("玩家一:", end="")
for card in cls.player1:
print(card, end=" ")
print()
print("玩家二:", end="")
for card in cls.player2:
print(card, end=" ")
print()
print("玩家三:", end="")
for card in cls.player3:
print(card, end=" ")
print()
print("玩家四:", end="")
for card in cls.player4:
print(card, end=" ")
print()
Card.init_cards()
Card.show_cards()
Card.wash_cards()
Card.show_cards()
Card.send_cards()
Card.show_player()
复制代码