|
| 1 | +from colorama import Fore, Back, Style |
| 2 | +import os |
| 3 | +import time |
| 4 | + |
| 5 | + |
| 6 | +class Main: |
| 7 | + def __init__(self): |
| 8 | + self.bullets = [0, 0] |
| 9 | + self.sorted_bullets = [] |
| 10 | + |
| 11 | + def clear(self): |
| 12 | + os.system('cls' if os.name == 'nt' else 'clear') |
| 13 | + self.print_logo() |
| 14 | + self.print_bullets() |
| 15 | + |
| 16 | + def print_logo(self): |
| 17 | + print(r''' |
| 18 | + ____ _ _ _ ____ _ _ |
| 19 | +| __ ) __ _ ___| | _____| |__ ___ | |_ | _ \(_) __| | ___ _ __ ___ |
| 20 | +| _ \ / _` |/ __| |/ / __| '_ \ / _ \| __| | |_) | |/ _` |/ _ \| '__/ __| |
| 21 | +| |_) | (_| | (__| <\__ \ | | | (_) | |_ | __/| | (_| | (_) | | \__ \ |
| 22 | +|____/ \__,_|\___|_|\_\___/_| |_|\___/ \__| |_| |_|\__,_|\___/|_| |___/ |
| 23 | + ''') |
| 24 | + |
| 25 | + def print_bullets(self): |
| 26 | + print(f"| Боевых: {Fore.RED}{self.bullets[0]}{Style.RESET_ALL}\tХолостых: {Fore.GREEN}{self.bullets[1]}{Style.RESET_ALL}") |
| 27 | + combat_count = self.sorted_bullets.count(1) |
| 28 | + blank_count = self.sorted_bullets.count(0) |
| 29 | + unknown_count = self.sorted_bullets.count(None) |
| 30 | + |
| 31 | + if self.sorted_bullets and self.sorted_bullets[0] == None: |
| 32 | + combat_left = self.bullets[0] - combat_count |
| 33 | + blank_left = self.bullets[1] - blank_count |
| 34 | + combat_percent = round((combat_left / unknown_count) * 100) if combat_left > 0 else "?" |
| 35 | + blank_percent = round((blank_left / unknown_count) * 100) if blank_left > 0 else "?" |
| 36 | + elif self.sorted_bullets: |
| 37 | + combat_percent = "100" if self.sorted_bullets[0] == 1 else '0' |
| 38 | + blank_percent = "100" if self.sorted_bullets[0] == 0 else '0' |
| 39 | + else: |
| 40 | + combat_percent = "?" |
| 41 | + blank_percent = "?" |
| 42 | + |
| 43 | + print(f"| {Fore.RED}{combat_percent}%{Style.RESET_ALL}\t\t\t{Fore.GREEN}{blank_percent}%{Style.RESET_ALL}") |
| 44 | + print(f"| {' '.join(f'{Fore.RED}Б{Style.RESET_ALL}' if x == 1 else f'{Fore.GREEN}Х{Style.RESET_ALL}' if x is not None else f'?' for x in self.sorted_bullets)}") |
| 45 | + |
| 46 | + def input_bullets(self): |
| 47 | + self.clear() |
| 48 | + try: |
| 49 | + print('\nВведите число пуль (Б/Х)', end='') |
| 50 | + self.bullets = [int(x) for x in input("> ")] |
| 51 | + |
| 52 | + if len(self.bullets) != 2: |
| 53 | + self.bullets = [0, 0] |
| 54 | + self.input_bullets() |
| 55 | + |
| 56 | + self.sorted_bullets = [None] * sum(self.bullets) |
| 57 | + self.process_define_bullet() |
| 58 | + except ValueError: |
| 59 | + self.input_bullets() |
| 60 | + |
| 61 | + def process_define_bullet(self): |
| 62 | + combat_left = self.bullets[0] - self.sorted_bullets.count(1) |
| 63 | + blank_left = self.bullets[1] - self.sorted_bullets.count(0) |
| 64 | + if combat_left == 0: |
| 65 | + self.sorted_bullets = [0 if x is None else x for x in self.sorted_bullets] |
| 66 | + elif blank_left == 0: |
| 67 | + self.sorted_bullets = [1 if x is None else x for x in self.sorted_bullets] |
| 68 | + |
| 69 | + def define_bullet(self): |
| 70 | + self.clear() |
| 71 | + try: |
| 72 | + print('\nВведите пулю (Номер/Пуля)', end='') |
| 73 | + bullet_data = [x for x in input("> ")] |
| 74 | + |
| 75 | + if not len(bullet_data): |
| 76 | + self.menu() |
| 77 | + |
| 78 | + if len(bullet_data) != 2: |
| 79 | + self.define_bullet() |
| 80 | + |
| 81 | + if int(bullet_data[0]) > sum(self.bullets): |
| 82 | + self.define_bullet() |
| 83 | + |
| 84 | + if bullet_data[1].lower() not in ['б', 'х']: |
| 85 | + self.define_bullet() |
| 86 | + |
| 87 | + self.sorted_bullets[int(bullet_data[0]) - 1] = 1 if bullet_data[1].lower() == 'б' else 0 |
| 88 | + |
| 89 | + self.process_define_bullet() |
| 90 | + self.menu() |
| 91 | + except ValueError: |
| 92 | + self.define_bullet() |
| 93 | + except IndexError: |
| 94 | + self.define_bullet() |
| 95 | + |
| 96 | + def menu(self): |
| 97 | + self.clear() |
| 98 | + print('\n[1] Сброс\n[2] Определить') |
| 99 | + option = input('> ').lower() |
| 100 | + match option: |
| 101 | + case '1': |
| 102 | + self.__init__() |
| 103 | + self.start() |
| 104 | + |
| 105 | + case '2': |
| 106 | + self.clear() |
| 107 | + self.define_bullet() |
| 108 | + |
| 109 | + case _: |
| 110 | + if option not in ['б', 'х']: |
| 111 | + self.menu() |
| 112 | + |
| 113 | + if option == 'б': |
| 114 | + self.bullets[0] -= 1 if self.bullets[0] > 0 else 0 |
| 115 | + else: |
| 116 | + self.bullets[1] -= 1 if self.bullets[1] > 0 else 0 |
| 117 | + |
| 118 | + self.sorted_bullets.pop(0) |
| 119 | + self.process_define_bullet() |
| 120 | + |
| 121 | + if sum(self.bullets) == 0: |
| 122 | + self.__init__() |
| 123 | + self.start() |
| 124 | + |
| 125 | + self.menu() |
| 126 | + |
| 127 | + def start(self): |
| 128 | + self.clear() |
| 129 | + self.input_bullets() |
| 130 | + self.menu() |
| 131 | + |
| 132 | + |
| 133 | +if __name__ == '__main__': |
| 134 | + main = Main() |
| 135 | + print('Саша лох') |
| 136 | + time.sleep(0.5) |
| 137 | + main.start() |
0 commit comments