From f09ad6613af3d146638a5daa1fae6d39f6b95e6c Mon Sep 17 00:00:00 2001 From: dmitrium12 Date: Sat, 24 Dec 2022 22:21:08 +0700 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D0=B7=D0=B0=D0=BF=D0=B8=D1=81=D1=8C=20?= =?UTF-8?q?=D1=81=D0=BB=D0=BE=D0=B6=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20=D0=B2?= =?UTF-8?q?=20config.ini=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB=20?= =?UTF-8?q?=D0=B7=D0=B0=D0=B2=D0=B8=D1=81=D0=B8=D0=BC=D0=BE=D1=81=D1=82?= =?UTF-8?q?=D0=B8=20=D0=B2=D0=B5=D1=80=D0=BE=D1=8F=D1=82=D0=BD=D0=BE=D1=81?= =?UTF-8?q?=D1=82=D0=B5=D0=B9=20=D0=BE=D1=82=20=D1=81=D0=BB=D0=BE=D0=B6?= =?UTF-8?q?=D0=BD=D0=BE=D1=81=D1=82=D0=B8=20=D0=BD=D0=B5=D0=BC=D0=BD=D0=BE?= =?UTF-8?q?=D0=B3=D0=BE=20=D0=B0=D0=BD=D0=B3=D0=BB=D0=B8=D0=B9=D1=81=D0=BA?= =?UTF-8?q?=D0=BE=D0=B9=20=D0=B3=D1=80=D0=B0=D0=BC=D0=BC=D0=B0=D1=82=D0=B8?= =?UTF-8?q?=D0=BA=D0=B8=20=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D0=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/config.ini | 5 +++-- main.py | 2 ++ modules/Game.py | 5 +++++ modules/GameMenu.py | 8 +++++++- modules/Mathematics.py | 28 ++++++++++++++++++---------- test.py | 4 ---- 6 files changed, 35 insertions(+), 17 deletions(-) diff --git a/conf/config.ini b/conf/config.ini index 422fb08..bc2931c 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -1,3 +1,4 @@ [Settings] -difficult=easy -sound=True +difficulty = Проигрывать весело +sound = True + diff --git a/main.py b/main.py index 367966e..9254a2d 100644 --- a/main.py +++ b/main.py @@ -4,6 +4,8 @@ from modules.Mathematics import start_calculating def main(): + logger.remove() + logger.add("conf/log.log", level="DEBUG") logger.info("Игра запущена") start_calculating() from modules.GameMenu import difficulty diff --git a/modules/Game.py b/modules/Game.py index 49327c1..892f074 100644 --- a/modules/Game.py +++ b/modules/Game.py @@ -1,5 +1,6 @@ import pygame from modules.Board import Board +from modules.Mathematics import recalculation_events, get_random_event class Game: @@ -24,6 +25,10 @@ class Game: self.running = False if event.type == pygame.MOUSEBUTTONDOWN: self.board.get_click(event.pos) + if event.type == pygame.MOUSEWHEEL: + event = get_random_event() + recalculation_events(event["well"]) + print(event) def render(self): self.screen.fill((0, 0, 0)) diff --git a/modules/GameMenu.py b/modules/GameMenu.py index fbdb79c..bde8423 100644 --- a/modules/GameMenu.py +++ b/modules/GameMenu.py @@ -1,5 +1,6 @@ import pygame import pygame_menu +import configparser def set_difficulty(value, _): @@ -8,10 +9,15 @@ def set_difficulty(value, _): def start_the_game(): + config = configparser.ConfigParser() + config.read('conf/config.ini') + config['Settings']['difficulty'] = difficulty + with open('conf/config.ini', 'w') as configfile: + config.write(configfile) menu.toggle() -difficulty = "" +difficulty = "Простая" pygame.init() surface = pygame.display.set_mode((600, 400)) mytheme = pygame_menu.themes.THEME_DARK.copy() diff --git a/modules/Mathematics.py b/modules/Mathematics.py index 5a01d7d..3988c7e 100644 --- a/modules/Mathematics.py +++ b/modules/Mathematics.py @@ -1,6 +1,7 @@ from modules.DB import UseDB from loguru import logger import random +import configparser def get_random_event(): @@ -11,30 +12,37 @@ def get_random_event(): def recalculation_events(well): + difficulties = { + "Простая": [5, 5], + "Средняя": [5, 2], + "Сложная": [5, 1], + "Проигрывать весело": [10, 1] + } + config = configparser.ConfigParser() + config.read("conf/config.ini") + difficulty = config['Settings']['difficulty'] 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}) + db.update_document({"_id": i["_id"]}, {"probability": i["probability"] + difficulties[difficulty][0]}) well_events = db.find_document({"well": True}) - cooficent = len(not_well_events) * 5 / len(well_events) + ratio = len(not_well_events) * difficulties[difficulty][0] / len(well_events) for i in well_events: - db.update_document({"_id": i["_id"]}, {"probability": i["probability"] - cooficent}) + db.update_document({"_id": i["_id"]}, {"probability": i["probability"] - ratio}) 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}) + db.update_document({"_id": i["_id"]}, {"probability": i["probability"] + difficulties[difficulty][1]}) not_well_events = db.find_document({"well": False}) - cooficent = len(well_events) * 5 / len(not_well_events) + ratio = len(well_events) * difficulties[difficulty][1] / len(not_well_events) for i in not_well_events: - db.update_document({"_id": i["_id"]}, {"probability": i["probability"] - cooficent}) + db.update_document({"_id": i["_id"]}, {"probability": i["probability"] - ratio}) def start_calculating(): - logger.remove() - logger.add("conf/log.log", level="INFO") - logger.info("Валидация началась") + logger.debug("Валидация началась") db = UseDB("events") response = db.find_document({}) sum_percent_probability = sum([i["probability"] for i in response]) @@ -50,4 +58,4 @@ def start_calculating(): logger.critical(f"Ошибка в ивенте {i['name']}. Разница в длинах variants, consequence " f"и probability_consequence") quit(0) - logger.info("Валидация игры успешно прошла") + logger.debug("Валидация игры успешно прошла") diff --git a/test.py b/test.py index cb60590..e69de29 100644 --- a/test.py +++ b/test.py @@ -1,4 +0,0 @@ -# from modules.Mathematics import recalculation_events, get_random_event -# -# event = get_random_event() -# recalculation_events(event["well"])