diff --git a/main.py b/main.py index d559392..fd1789b 100644 --- a/main.py +++ b/main.py @@ -1,9 +1,13 @@ import pygame +from loguru import logger from modules.Game import Game from modules.GameMenu import menu +from modules.Mathematics import start_calculating def main(): + logger.info("Игра запущена") + start_calculating() running = True show_menu = True while running: diff --git a/modules/DB.py b/modules/DB.py index 85e32a2..5cb0ca8 100644 --- a/modules/DB.py +++ b/modules/DB.py @@ -5,7 +5,7 @@ class UseDB: def __init__(self, collection_name): self.series_collection = None self.client = MongoClient('localhost', 27017) - self.db = self.client['stepik'] + self.db = self.client['toads'] self.series_collection = self.db[collection_name] def find_document(self, elements): diff --git a/modules/GameMenu.py b/modules/GameMenu.py index 7c91e44..8f81332 100644 --- a/modules/GameMenu.py +++ b/modules/GameMenu.py @@ -4,10 +4,10 @@ from pygame import * def menu(): init() - DISPLAYSURF = display.set_mode((480, 600)) + DISPLAYPORT = display.set_mode((480, 600)) display.set_caption('The Lonely Shooter') background = image.load('styles/background.jpeg').convert() - DISPLAYSURF.blit(background, background.get_rect()) + DISPLAYPORT.blit(background, background.get_rect()) display.update() while True: events = event.poll() diff --git a/modules/Mathematics.py b/modules/Mathematics.py new file mode 100644 index 0000000..5a01d7d --- /dev/null +++ b/modules/Mathematics.py @@ -0,0 +1,53 @@ +from modules.DB import UseDB +from loguru import logger +import random + + +def get_random_event(): + db = UseDB("events") + response = db.find_document({}) + random_event = random.choices([i["_id"] for i in response], weights=[i["probability"] for i in response]) + return db.find_document({"_id": random_event[0]})[0] + + +def recalculation_events(well): + if well: + db = UseDB("events") + not_well_events = db.find_document({"well": False}) + for i in not_well_events: + db.update_document({"_id": i["_id"]}, {"probability": i["probability"] + 5}) + well_events = db.find_document({"well": True}) + cooficent = len(not_well_events) * 5 / len(well_events) + for i in well_events: + db.update_document({"_id": i["_id"]}, {"probability": i["probability"] - cooficent}) + else: + db = UseDB("events") + well_events = db.find_document({"well": True}) + for i in well_events: + db.update_document({"_id": i["_id"]}, {"probability": i["probability"] + 5}) + not_well_events = db.find_document({"well": False}) + cooficent = len(well_events) * 5 / len(not_well_events) + for i in not_well_events: + db.update_document({"_id": i["_id"]}, {"probability": i["probability"] - cooficent}) + + +def start_calculating(): + logger.remove() + logger.add("conf/log.log", level="INFO") + logger.info("Валидация началась") + db = UseDB("events") + response = db.find_document({}) + sum_percent_probability = sum([i["probability"] for i in response]) + sum_percent_probability_in_events = sum([sum(i["probability_consequence"]) for i in response]) + if sum_percent_probability != 100: + logger.critical("Сумма вероятностей всех ивентов не равна 100, это плохо, не надо так") + quit(0) + if sum_percent_probability_in_events != len(response) * 100: + logger.critical("Проблема в каком-то ивенте, сумма вероятностей не правильная") + quit(0) + for i in response: + if not (len(i["variants"]) == len(i["consequence"]) == len(i["probability_consequence"])): + logger.critical(f"Ошибка в ивенте {i['name']}. Разница в длинах variants, consequence " + f"и probability_consequence") + quit(0) + logger.info("Валидация игры успешно прошла") diff --git a/styles/Retro.ttf b/styles/Retro.ttf deleted file mode 100644 index 02baf66..0000000 Binary files a/styles/Retro.ttf and /dev/null differ diff --git a/test.py b/test.py new file mode 100644 index 0000000..88834fc --- /dev/null +++ b/test.py @@ -0,0 +1,4 @@ +from modules.Mathematics import recalculation_events, get_random_event + +event = get_random_event() +recalculation_events(event["well"])