Добавил определение случайного ивента и стабилизацию везения.

Почистил код.
Удалил лишнее.
This commit is contained in:
2022-12-24 14:23:20 +07:00
parent 4627e9d0d1
commit d1160a66e0
6 changed files with 64 additions and 3 deletions
+4
View File
@@ -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:
+1 -1
View File
@@ -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):
+2 -2
View File
@@ -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()
+53
View File
@@ -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("Валидация игры успешно прошла")
BIN
View File
Binary file not shown.
+4
View File
@@ -0,0 +1,4 @@
from modules.Mathematics import recalculation_events, get_random_event
event = get_random_event()
recalculation_events(event["well"])