diff --git a/conf/config.ini b/conf/config.ini index 72b1e1d..d97d121 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -1,4 +1,4 @@ [Settings] -difficulty = Простая +difficulty = sound = True diff --git a/modules/Book.py b/modules/Book.py index 1d8c204..975e901 100644 --- a/modules/Book.py +++ b/modules/Book.py @@ -3,12 +3,10 @@ import pygame as pg class Book: # Окно с необходимой информацией @staticmethod - def info(screen): + def info(screen, event): pg.draw.rect(screen, (38, 33, 55), (85, 0, 520, 500)) pg.draw.rect(screen, (255, 255, 255), (100, 90, 495, 280), 1) - - texts = ['День ***', 'Сегодня произошло следующее:', - '***'] # Если не вмещаются события, то в конце можно написать и т.д. + texts = ['День ***', 'Сегодня произошло следующее:', f"{event['name']}\n{event['description']}"] sizes = [60, 30, 30] coords = [(260, 30), (110, 100), (110, 150)] for i in range(len(texts)): diff --git a/modules/Game.py b/modules/Game.py index 144a175..8b11cea 100644 --- a/modules/Game.py +++ b/modules/Game.py @@ -1,10 +1,19 @@ +import configparser import pygame as pg from modules.Swamp import Swamp class Game: def __init__(self, difficulty): - pg.init() + config = configparser.ConfigParser() + config.read("conf/config.ini") + sound = config['Settings']['sound'] + if sound == "True": + print(sound) + pg.mixer.init() + pg.mixer.music.load('styles/background.mp3') + pg.mixer.music.play(loops=-1) + pg.init() size = 700, 500 self.screen = pg.display.set_mode(size) pg.display.set_caption(difficulty) diff --git a/modules/GameMenu.py b/modules/GameMenu.py index dc9690a..1b27b80 100644 --- a/modules/GameMenu.py +++ b/modules/GameMenu.py @@ -31,6 +31,19 @@ def start_the_game() -> None: menu.toggle() # останавливаю меню +def test(value: dict, _): + print(value) + if value[0][0] == "Да": + test = "True" + else: + test = "False" + config = configparser.ConfigParser() # создаю объект ConfigParser + config.read('conf/config.ini') # читаю файл + config['Settings']['sound'] = test # перезаписываю сложность + with open('conf/config.ini', 'w') as configfile: # открываю файл для записи + config.write(configfile) # записываю + + difficulty = "Простая" # временная переменная для сложности pygame.init() # запускаю pygame surface = pygame.display.set_mode((600, 400)) # создаю полотно @@ -41,6 +54,7 @@ menu = pygame_menu.Menu('Welcome', 600, 400, theme=mytheme) # создаю ме menu.add.label("Сложность") # добавляю label menu.add.selector('', [('Простая', 1), ('Средняя', 2), ('Сложная', 3), ('Проигрывать весело', 4)], onchange=set_difficulty) # добавляю selector с выбором сложности +menu.add.selector("музыка", [("Да", 1), ("Нет", 1)], onchange=test) menu.add.button('Play', start_the_game) # добавляю кнопку начала игры menu.add.button('Quit', pygame_menu.events.EXIT) # добавляю кнопку выхода menu.mainloop(surface) # запускаю меню diff --git a/modules/Swamp.py b/modules/Swamp.py index 7899ae8..711ca03 100644 --- a/modules/Swamp.py +++ b/modules/Swamp.py @@ -25,9 +25,11 @@ class Swamp: def render(self, screen): # Рисование поля, книги и болота myimage = pg.image.load("styles/background.jpg") - imagerect = myimage.get_rect() - scaled_image = pg.transform.smoothscale(myimage, (500, 500)) - screen.blit(scaled_image, imagerect) + rect = screen.get_rect() + x = rect[2] + y = rect[3] + scaled_image = pg.transform.smoothscale(myimage, (x, y)) + screen.blit(scaled_image, (0, 0)) pg.draw.rect(screen, (255, 255, 255), (630, 400, 50, 60)) # книга pg.draw.rect(screen, (132, 7, 8), (630, 400, 50, 55)) @@ -45,7 +47,11 @@ class Swamp: pg.draw.rect(screen, (252, 232, 131), (self.x, self.y, self.cell_size, self.cell_size)) if self.book_use is True: # При нажатии на книгу рисуется небольшой экран с информацией - self.book.info(screen) + from modules.Mathematics import recalculation_events, get_random_event + event = get_random_event() + print(event) + recalculation_events(event["well"]) + self.book.info(screen, event) if self.frogs == 0: # Если все лягушки вымрут, то открывается окно с Game over self.game_over.end(screen) diff --git a/styles/background.mp3 b/styles/background.mp3 new file mode 100644 index 0000000..25c6808 Binary files /dev/null and b/styles/background.mp3 differ diff --git a/test.py b/test.py index e69de29..856d0cb 100644 --- a/test.py +++ b/test.py @@ -0,0 +1,5 @@ +from modules.Mathematics import recalculation_events, get_random_event + +event = get_random_event() +print(event) +recalculation_events(event["well"])