добавил перезапись сложности в config.ini
добавил зависимости вероятностей от сложности немного английской грамматики добавил
This commit is contained in:
+3
-2
@@ -1,3 +1,4 @@
|
|||||||
[Settings]
|
[Settings]
|
||||||
difficult=easy
|
difficulty = Проигрывать весело
|
||||||
sound=True
|
sound = True
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,8 @@ from modules.Mathematics import start_calculating
|
|||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
logger.remove()
|
||||||
|
logger.add("conf/log.log", level="DEBUG")
|
||||||
logger.info("Игра запущена")
|
logger.info("Игра запущена")
|
||||||
start_calculating()
|
start_calculating()
|
||||||
from modules.GameMenu import difficulty
|
from modules.GameMenu import difficulty
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import pygame
|
import pygame
|
||||||
from modules.Board import Board
|
from modules.Board import Board
|
||||||
|
from modules.Mathematics import recalculation_events, get_random_event
|
||||||
|
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
@@ -24,6 +25,10 @@ class Game:
|
|||||||
self.running = False
|
self.running = False
|
||||||
if event.type == pygame.MOUSEBUTTONDOWN:
|
if event.type == pygame.MOUSEBUTTONDOWN:
|
||||||
self.board.get_click(event.pos)
|
self.board.get_click(event.pos)
|
||||||
|
if event.type == pygame.MOUSEWHEEL:
|
||||||
|
event = get_random_event()
|
||||||
|
recalculation_events(event["well"])
|
||||||
|
print(event)
|
||||||
|
|
||||||
def render(self):
|
def render(self):
|
||||||
self.screen.fill((0, 0, 0))
|
self.screen.fill((0, 0, 0))
|
||||||
|
|||||||
+7
-1
@@ -1,5 +1,6 @@
|
|||||||
import pygame
|
import pygame
|
||||||
import pygame_menu
|
import pygame_menu
|
||||||
|
import configparser
|
||||||
|
|
||||||
|
|
||||||
def set_difficulty(value, _):
|
def set_difficulty(value, _):
|
||||||
@@ -8,10 +9,15 @@ def set_difficulty(value, _):
|
|||||||
|
|
||||||
|
|
||||||
def start_the_game():
|
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()
|
menu.toggle()
|
||||||
|
|
||||||
|
|
||||||
difficulty = ""
|
difficulty = "Простая"
|
||||||
pygame.init()
|
pygame.init()
|
||||||
surface = pygame.display.set_mode((600, 400))
|
surface = pygame.display.set_mode((600, 400))
|
||||||
mytheme = pygame_menu.themes.THEME_DARK.copy()
|
mytheme = pygame_menu.themes.THEME_DARK.copy()
|
||||||
|
|||||||
+18
-10
@@ -1,6 +1,7 @@
|
|||||||
from modules.DB import UseDB
|
from modules.DB import UseDB
|
||||||
from loguru import logger
|
from loguru import logger
|
||||||
import random
|
import random
|
||||||
|
import configparser
|
||||||
|
|
||||||
|
|
||||||
def get_random_event():
|
def get_random_event():
|
||||||
@@ -11,30 +12,37 @@ def get_random_event():
|
|||||||
|
|
||||||
|
|
||||||
def recalculation_events(well):
|
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:
|
if well:
|
||||||
db = UseDB("events")
|
db = UseDB("events")
|
||||||
not_well_events = db.find_document({"well": False})
|
not_well_events = db.find_document({"well": False})
|
||||||
for i in not_well_events:
|
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})
|
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:
|
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:
|
else:
|
||||||
db = UseDB("events")
|
db = UseDB("events")
|
||||||
well_events = db.find_document({"well": True})
|
well_events = db.find_document({"well": True})
|
||||||
for i in well_events:
|
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})
|
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:
|
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():
|
def start_calculating():
|
||||||
logger.remove()
|
logger.debug("Валидация началась")
|
||||||
logger.add("conf/log.log", level="INFO")
|
|
||||||
logger.info("Валидация началась")
|
|
||||||
db = UseDB("events")
|
db = UseDB("events")
|
||||||
response = db.find_document({})
|
response = db.find_document({})
|
||||||
sum_percent_probability = sum([i["probability"] for i in response])
|
sum_percent_probability = sum([i["probability"] for i in response])
|
||||||
@@ -50,4 +58,4 @@ def start_calculating():
|
|||||||
logger.critical(f"Ошибка в ивенте {i['name']}. Разница в длинах variants, consequence "
|
logger.critical(f"Ошибка в ивенте {i['name']}. Разница в длинах variants, consequence "
|
||||||
f"и probability_consequence")
|
f"и probability_consequence")
|
||||||
quit(0)
|
quit(0)
|
||||||
logger.info("Валидация игры успешно прошла")
|
logger.debug("Валидация игры успешно прошла")
|
||||||
|
|||||||
Reference in New Issue
Block a user