diff --git a/conf/config.ini b/conf/config.ini index d97d121..72b1e1d 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 new file mode 100644 index 0000000..1d8c204 --- /dev/null +++ b/modules/Book.py @@ -0,0 +1,50 @@ +import pygame as pg + + +class Book: # Окно с необходимой информацией + @staticmethod + def info(screen): + pg.draw.rect(screen, (38, 33, 55), (85, 0, 520, 500)) + pg.draw.rect(screen, (255, 255, 255), (100, 90, 495, 280), 1) + + texts = ['День ***', 'Сегодня произошло следующее:', + '***'] # Если не вмещаются события, то в конце можно написать и т.д. + sizes = [60, 30, 30] + coords = [(260, 30), (110, 100), (110, 150)] + for i in range(len(texts)): + font = pg.font.Font(None, sizes[i]) + text = font.render(texts[i], True, (255, 255, 255)) + screen.blit(text, coords[i]) + + frogs = [('Квакуша', [100, 100]), + ('Квакша', [100, 100]), + ('Квак', [100, 100]), + ('Ква', [100, 100]), + ('Кваква', [100, 100]), + ('Джабба-хатт', [100, 100]), + ('Квендальф', [100, 100]), + ('Лягуша', [100, 100]), + ('Жаба', [100, 100]), + ('Абажаю', [100, 100]), + ('Пучеглазый', [100, 100]), + ('Вафля', [100, 100])] # Имя лягушки со здоровьем и сытостью (как пример) + + font = pg.font.Font(None, 15) # Здесь будет указана информация о некоторых лягушках + for col in range(4): + for row in range(3): + pg.draw.rect(screen, (255, 255, 255), (100 + 120 * col, 375 + 40 * row, 35, 35), + 1) # Рамка с портретом лягушки + if col == 0: + i = row + elif col == 1: + i = row + 3 + elif col == 2: + i = row + 6 + else: + i = row + 9 + text = font.render(f'{frogs[i][0]} - ', True, (255, 255, 255)) + screen.blit(text, (140 + 120 * col, 375 + 40 * row)) + text = font.render(f'{frogs[i][-1][0]}% зд.,', True, (255, 255, 255)) + screen.blit(text, (140 + 120 * col, 385 + 40 * row)) + text = font.render(f'{frogs[i][-1][1]}% сыт.', True, (255, 255, 255)) + screen.blit(text, (140 + 120 * col, 395 + 40 * row)) diff --git a/modules/Game.py b/modules/Game.py index 892f074..144a175 100644 --- a/modules/Game.py +++ b/modules/Game.py @@ -1,36 +1,25 @@ -import pygame -from modules.Board import Board -from modules.Mathematics import recalculation_events, get_random_event +import pygame as pg +from modules.Swamp import Swamp class Game: def __init__(self, difficulty): - pygame.init() - size = 500, 500 - self.screen = pygame.display.set_mode(size) - pygame.display.set_caption(difficulty) - self.board = Board(5, 7, self.screen) - self.board.set_view(100, 100, 50) + pg.init() + size = 700, 500 + self.screen = pg.display.set_mode(size) + pg.display.set_caption(difficulty) + self.swamp = Swamp() + self.swamp.set_view(120, 160, 35) + self.swamp.set_book(400, 680, 460, 630) self.running = True def start(self): while self.running: - self.event() - self.render() - pygame.quit() - - def event(self): - for event in pygame.event.get(): - if event.type == pygame.QUIT: - 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)) - self.board.render() - pygame.display.flip() + for event in pg.event.get(): + if event.type == pg.QUIT: + self.running = False + if event.type == pg.MOUSEBUTTONDOWN: + self.swamp.get_click(event.pos) + self.screen.fill((93, 101, 48)) + self.swamp.render(self.screen) + pg.display.flip() diff --git a/modules/GameOver.py b/modules/GameOver.py new file mode 100644 index 0000000..418f283 --- /dev/null +++ b/modules/GameOver.py @@ -0,0 +1,18 @@ +import pygame as pg + + +class GameOver: # Окно, на котором будет отображаться Game Over + @staticmethod + def end(screen): + pg.draw.rect(screen, (38, 33, 55), (0, 0, 700, 500)) + font = pg.font.Font(None, 70) + text = font.render('Game Over', True, (255, 255, 255)) + screen.blit(text, (210, 30)) + + font = pg.font.Font(None, 40) + text = font.render('Кол-во прожитых дней - ***', True, (255, 255, 255)) + screen.blit(text, (30, 110)) + text = font.render('Максимальное кол-во лягушек - ***.', True, (255, 255, 255)) + screen.blit(text, (30, 150)) + text = font.render('Кол-во умерших лягушек - ***.', True, (255, 255, 255)) + screen.blit(text, (30, 190)) diff --git a/modules/Swamp.py b/modules/Swamp.py new file mode 100644 index 0000000..7899ae8 --- /dev/null +++ b/modules/Swamp.py @@ -0,0 +1,90 @@ +import pygame as pg +from math import pi +from modules import Book, GameOver + + +class Swamp: + def __init__(self): + self.left_book = None + self.down_book = None + self.right_book = None + self.top_book = None + self.top_area = None + self.left_area = None + self.y = None + self.x = None + self.width = 13 + self.height = 8 + self.board = [[0] * 13 for _ in range(8)] # Матрица + self.cell_size = 30 + + self.book_use = False # Если self.book_use является True, то активируется класс Book + self.book = Book.Book() + self.frogs = 3 # кол-во лягушек + self.game_over = GameOver.GameOver() + + 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) + + pg.draw.rect(screen, (255, 255, 255), (630, 400, 50, 60)) # книга + pg.draw.rect(screen, (132, 7, 8), (630, 400, 50, 55)) + pg.draw.rect(screen, (98, 0, 15), (630, 400, 5, 60)) + pg.draw.line(screen, (231, 113, 0), [640, 420], [675, 420], 3) + + for row in range(self.width): # Клетчатое поле + for col in range(self.height): + self.x = self.left_area + row * self.cell_size + self.y = self.top_area + col * self.cell_size + if self.board[col][row] == 0: + pg.draw.rect(screen, (100, 100, 100), + (self.x, self.y, self.cell_size, self.cell_size), 1) + elif self.board[col][row] == 1: + 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) + + if self.frogs == 0: # Если все лягушки вымрут, то открывается окно с Game over + self.game_over.end(screen) + + def set_view(self, left, top, cell_size): + self.left_area = left + self.top_area = top + self.cell_size = cell_size + + def set_book(self, top, right, down, left): # Координаты сторон книги + self.top_book = top + self.right_book = right + self.down_book = down + self.left_book = left + + def get_cell(self, mouse_pos): + board_width = self.width * self.cell_size + board_height = self.height * self.cell_size + if self.left_area < mouse_pos[0] < self.left_area + board_width: + if self.top_area < mouse_pos[1] < self.top_area + board_height: + cell_coords = (mouse_pos[0] - self.top_area) // self.cell_size + 1, \ + (mouse_pos[1] - self.left_area) // self.cell_size - 1 + return cell_coords + elif self.left_book < mouse_pos[0] < self.right_book: + if self.top_book < mouse_pos[1] < self.down_book and self.book_use is False: + self.book_use = True + elif self.book_use is True and self.top_book < mouse_pos[1] < self.down_book: + self.book_use = False + return None + + def on_click(self, mouse_pos): # Действия после клика на клетчатое поле + if mouse_pos is None: + self.board = [[0] * 13 for _ in range(8)] + elif self.board[mouse_pos[1]][mouse_pos[0]] == 0: + self.board = [[0] * 13 for _ in range(8)] + self.board[mouse_pos[1]][mouse_pos[0]] = 1 + elif self.board[mouse_pos[1]][mouse_pos[0]] == 1: + self.board[mouse_pos[1]][mouse_pos[0]] = 0 + + def get_click(self, mouse_pos): + cell = self.get_cell(mouse_pos) + self.on_click(cell) diff --git a/styles/background.jpeg b/styles/background.jpeg index 26b6ad0..bc37d9e 100644 Binary files a/styles/background.jpeg and b/styles/background.jpeg differ diff --git a/styles/background.jpg b/styles/background.jpg index 26b6ad0..4efb422 100644 Binary files a/styles/background.jpg and b/styles/background.jpg differ diff --git a/test.py b/test.py index 3d280fe..e69de29 100644 --- a/test.py +++ b/test.py @@ -1,8 +0,0 @@ -from modules.DB import UseDB - -db = UseDB("events") -for i in db.find_document({}): - print(i) - # db.del_document({"name": i["name"]}) -# db.update_document({"name": "test not bad"}, {"probability": 50}) -db.update_document({"name": "test bad "}, {"probability": 50})