# 初始化牌
@classmethod
def init_poke(cls):
flowers = ("♠", "♥", "♣", "♦")
nums = ("2", "3", "4", "5", "6", "7", "8", "9", "10", "J", "Q", "K", "A")
kings = {"big": "大王", "small": "小王"}
for f in flowers:
for n in nums:
p = Poke(f, n)
cls.pokes.append(p)
cls.pokes.append(kings["big"])
cls.pokes.append(kings["small"])
# 洗牌 第一种方法 从牌的第一张开始,随机生成一张互换位置,相当于互换54次
@classmethod
def wash_poke(cls):
for i in range(53):
num1 = random.randint(0, 53)
Poke.pokes, Poke.pokes[num1] = Poke.pokes[num1], Poke.pokes
# 洗牌 第二种方法 牌分成两部分,第一部分的选择一张随机插入到后面一部分
@classmethod
def wash1_poke(cls):
for i in range(28, 54):
Poke.pokes.insert(i, Poke.pokes.pop(0))
# 发牌
@classmethod
def send_poke(cls):
while True:
if len(Poke.pokes) <= 3:
break
Poke.player1.append(Poke.pokes.pop(0))
Poke.player2.append(Poke.pokes.pop(0))
Poke.player3.append(Poke.pokes.pop(0))
Poke.last = tuple(Poke.pokes) # 因为底牌不变,做成元组会比较好一点
# 显示牌的序列状态,在没有发牌以前临时使用
@classmethod
def show(cls):
for a in cls.pokes:
print(a, end="\t")
print()
# 显示玩家以及底牌
@classmethod
def player_show(cls):
print("第一位玩家的牌是:", end="")
for a in cls.player1:
print(a, end="\t")
print()
print("第二位玩家的牌是:", end="")
for a in cls.player2:
print(a, end="\t")
print()
print("第三位玩家的牌是:", end="")
for a in cls.player3:
print(a, end="\t")
print()
print("最后的底牌是:", end="")
for a in cls.last:
print(a, end="\t")
print()