| 103 | |
| 104 | |
| 105 | class Chips: |
| 106 | def __init__(self, amount): |
| 107 | """ |
| 108 | :param amount: the chips you own |
| 109 | """ |
| 110 | self._amount = amount |
| 111 | self._bet_amount = 0 |
| 112 | self._insurance = 0 |
| 113 | self.is_insurance = False |
| 114 | self.is_double = False |
| 115 | |
| 116 | def __bool__(self): |
| 117 | return self.amount > 0 |
| 118 | |
| 119 | @staticmethod |
| 120 | def get_tips(content): |
| 121 | fmt_tips = "{color}** TIPS: {content}! **{end}" |
| 122 | return fmt_tips.format( |
| 123 | color=COLOR.get("YELLOW"), content=content, end=COLOR.get("END") |
| 124 | ) |
| 125 | |
| 126 | @property |
| 127 | def amount(self): |
| 128 | return self._amount |
| 129 | |
| 130 | @amount.setter |
| 131 | def amount(self, value): |
| 132 | if not isinstance(value, int): |
| 133 | type_tips = "Please give a integer" |
| 134 | raise ValueError(Chips.get_tips(type_tips)) |
| 135 | if value < 0: |
| 136 | amount_tips = "Your integer should bigger than 0" |
| 137 | raise ValueError(Chips.get_tips(amount_tips)) |
| 138 | self._amount = value |
| 139 | |
| 140 | @property |
| 141 | def bet_amount(self): |
| 142 | return self._bet_amount |
| 143 | |
| 144 | @bet_amount.setter |
| 145 | def bet_amount(self, value): |
| 146 | type_tips = "Please give a integer" |
| 147 | amount_tips = "Your chips should between 1 - " + str(self.amount) + " " |
| 148 | try: |
| 149 | value = int(value) |
| 150 | except ValueError: |
| 151 | raise ValueError(Chips.get_tips(type_tips)) |
| 152 | else: |
| 153 | if not isinstance(value, int): |
| 154 | raise ValueError(Chips.get_tips(type_tips)) |
| 155 | if (value <= 0) or (value > self.amount): |
| 156 | raise ValueError(Chips.get_tips(amount_tips)) |
| 157 | self._bet_amount = value |
| 158 | |
| 159 | def double_bet(self): |
| 160 | if self.can_double(): |
| 161 | self._bet_amount *= 2 |
| 162 | self.is_double = True |