zoukankan      html  css  js  c++  java
  • 面向对象实现扎金花

    见代码

     1 import random
     2 
     3 
     4 class Card:
     5     def __init__(self, color, style, value):
     6         self.color = color
     7         self.style = style
     8         self.value = value
     9 
    10 
    11 class Cards:
    12 
    13     def __init__(self):
    14         self.card_list = []
    15         self.card_style = ['2', '3', '4', '5', '6', '7', '8', '9', '10', 'J', 'Q', 'K', 'A']
    16         self.card_3 = []
    17 
    18     def group(self):
    19         for i in "♣♠♦♥":
    20             for index, j in enumerate(self.card_style):
    21                 self.card_list.append(Card(i, j, index))
    22 
    23     def send(self):
    24         for t in range(3):
    25             index_3 = (random.randint(0, len(self.card_list))-1)
    26             self.card_3.append(self.card_list[index_3])
    27             del self.card_list[index_3]
    28         self.card_3.sort(key=lambda v: v.value)
    29         for u in self.card_3:
    30             print(u.color+u.style, end=' ')
    31 
    32         if self.card_3[0].value == self.card_3[1].value and self.card_3[1].value == self.card_3[2].value:
    33             print("-三条")
    34         elif self.card_3[0].value == self.card_3[1].value or self.card_3[1].value == self.card_3[2].value or self.card_3[0].value == self.card_3[2].value:
    35             print("-二条")
    36         elif self.card_3[0].value+1 == self.card_3[1].value == self.card_3[2].value-1 and self.card_3[0].color == self.card_3[1].color == self.card_3[2].color:
    37             print("-同花顺")
    38         elif self.card_3[0].color == self.card_3[1].color == self.card_3[2].color:
    39             print("-同花")
    40         elif self.card_3[0].value+1 == self.card_3[1].value == self.card_3[2].value-1:
    41             print("-顺子")
    42         else:
    43             print("-杂牌")
    44 
    45 
    46 c = Cards()
    47 c.group()
    48 c.send()
  • 相关阅读:
    Jenkins+postman+Newman之API自动化测试
    python之路——迭代器和生成器
    文件操作
    函数
    python基础数据类型二
    dp的一种理解角度及[NOI2020]命运 题解
    从零开始“发明”Treap
    博客停更
    [转]Linux下C语言-RPC远程调用编程rpcgen用法
    一位编程小白的自述 —— 从小学到现在
  • 原文地址:https://www.cnblogs.com/tttzqf/p/9346450.html
Copyright © 2011-2022 走看看