-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgame.py
More file actions
59 lines (48 loc) · 1.9 KB
/
game.py
File metadata and controls
59 lines (48 loc) · 1.9 KB
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
from random import randint
from player import Player, PlayerStatus, PlayerType
class Game:
__count_kegs = 90
__kegs = []
__players = []
@staticmethod
def __generate_numbers(count, min, max):
result = []
if count > max - min + 1:
raise ValueError('Не верные входные данные для генерации мешка с боченками.')
while len(result) < count:
number = randint(min, max)
if number not in result:
result.append(number)
return result
def start(self):
self.__kegs = self.__generate_numbers(self.__count_kegs, 1, self.__count_kegs)
for index, keg in enumerate(self.__kegs):
print('\n\n')
if self.__play_round(keg, self.__count_kegs - index - 1):
return
def add_player(self, type_player, name):
self.__players.append(Player(type_player, name))
def clear_players(self):
self.__players.clear()
@property
def count_players(self):
return len(self.__players)
def __play_round(self, keg, keg_left):
print(f'Выпал бочонок: {keg} (осталось {keg_left})')
for item in self.__players:
if not item.status == PlayerStatus.LOST:
item.show_card()
for item in self.__players:
if item.type == PlayerType.HUMAN:
if not item.status == PlayerStatus.LOST:
choice = input(f'{item.name} зачеркнуть цифру? (y/n)')
if choice.lower() == 'y':
item.strike_out(keg)
else:
item.strike_out(keg)
end_game = False
for item in self.__players:
if item.status == PlayerStatus.WIN:
end_game = True
print(f'{item.name} выиграл!!!')
return end_game