-
Notifications
You must be signed in to change notification settings - Fork 62
/
Dg8x.py
116 lines (95 loc) · 2.61 KB
/
Dg8x.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import random
players = []
table = []
class Player:
def __init__(self, name, coin):
self.name = name
self.coin = coin
def info(self):
print(self.name + ':' + str(self.coin))
def set_bet_coin(self, bet_coin):
self.coin -= bet_coin
print(self.name + 'は ' + str(bet_coin) + 'コイン BETしました。')
class Human(Player):
def __init__(self, name, coin):
super().__init__(name, coin)
def bet(self):
bet_message = '何枚BETしますか?:(1-99)'
bet_coin = input(bet_message)
while not self.enable_bet_coin(bet_coin):
bet_coin = input(bet_message)
super().set_bet_coin(int(bet_coin))
def enable_bet_coin(self, string):
if string.isdigit():
number = int(string)
if number >= 1 and number <= 99:
return True
else:
return False
else:
return False
class Computer(Player):
def __init__(self, name, coin):
super().__init__(name, coin)
def bet(self):
if self.coin >= 99:
max_bet_coin = 99
else:
max_bet_coin = self.coin
bet_coin = random.randint(1, max_bet_coin)
super().set_bet_coin(bet_coin)
class Cell:
def __init__(self, name, rate, color):
self.name = name
self.rate = rate
self.color = color
class ColorBase:
BLACK = '\033[30m'
RED = '\033[31m'
GREEN = '\033[32m'
END = '\033[0m'
def create_players():
global players
human = Human('MY', 500)
computer1 = Computer('C1', 500)
computer2 = Computer('C2', 500)
computer3 = Computer('C3', 500)
players = [human, computer1, computer2, computer3]
def create_table():
global table
table.append(Cell('R', 8, 'red'))
table.append(Cell('B', 8, 'black'))
table.append(Cell('1', 2, 'red'))
table.append(Cell('2', 2, 'black'))
table.append(Cell('3', 2, 'red'))
table.append(Cell('4', 2, 'black'))
table.append(Cell('5', 2, 'red'))
table.append(Cell('6', 2, 'black'))
table.append(Cell('7', 2, 'red'))
table.append(Cell('8', 2, 'black'))
def show_table():
for cell in table:
print(green_bar() + color(cell.color, cell.name + '(x' + str(cell.rate) + ')') + green_bar())
def color(color_name, string):
if color_name == 'red':
return ColorBase.RED + string + ColorBase.END
elif color_name == 'green':
return ColorBase.GREEN + string + ColorBase.END
else:
return string
def green_bar():
return color('green', '|')
def play():
print('デバッグログ:play()')
create_players()
create_table()
show_table()
#show_players()
def show_players():
for player in players:
player.info()
for player in players:
player.bet()
for player in players:
player.info()
play()