forked from techgymjp/techgym_python
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRp8S.py
74 lines (59 loc) · 1.6 KB
/
Rp8S.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
import random
players = []
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.bet_coin = 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)
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 play():
print('デバッグログ:play()')
create_players()
show_players()
def show_players():
for player in players:
player.info()
for player in players:
player.bet()
for player in players:
player.info()
play()