diff --git a/conf/config.ini b/conf/config.ini index d97d121..b7678ab 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -1,4 +1,4 @@ [Settings] -difficulty = +difficulty = Средняя sound = True diff --git a/modules/Board.py b/modules/Board.py index 8b8b10c..602e052 100644 --- a/modules/Board.py +++ b/modules/Board.py @@ -28,12 +28,14 @@ class Board: self.board[x][cell_coords[1]] = (self.board[x][cell_coords[1]] + 1) % 2 for y in range(self.width): self.board[cell_coords[0]][y] = (self.board[cell_coords[0]][y] + 1) % 2 - self.board[cell_coords[0]][cell_coords[1]] = (self.board[cell_coords[0]][cell_coords[1]] + 1) % 2 + new_cell = (self.board[cell_coords[0]][cell_coords[1]] + 1) % 2 + self.board[cell_coords[0]][cell_coords[1]] = new_cell def get_cell(self, mouse_pos): if self.left <= mouse_pos[1] < self.left + self.height * self.cell_size and \ self.top <= mouse_pos[0] < self.top + self.width * self.cell_size: - return int((mouse_pos[1] - self.left) / self.cell_size), int((mouse_pos[0] - self.top) / self.cell_size) + cell = int((mouse_pos[1] - self.left) / self.cell_size), int((mouse_pos[0] - self.top) / self.cell_size) + return cell else: return None diff --git a/modules/Book.py b/modules/Book.py index 844cf1a..8c59e93 100644 --- a/modules/Book.py +++ b/modules/Book.py @@ -2,6 +2,37 @@ import pygame as pg from modules import DB +def get_frogs_img(name): + frogs_img = { + "Квакуша": "1.jpg", + "Квакша": "2.jpg", + "Квак": "3.jpg", + "Ква": "4.jpg", + "Кваква": "5.jpg", + "Джабба-хатт": "6.jpg", + "Квендальф": "7.jpg", + "Лягуша": "8.jpg", + "Жаба": "9.jpg", + "Абажаю": "10.jpg", + "Пучеглазый": "11.jpg", + "Вафля": "12.jpg", + "13": "13.jpg", + "14": "14.jpg", + "15": "15.jpg", + "16": "16.jpg", + "17": "17.jpg", + "18": "18.jpg", + "19": "19.jpg", + "20": "20.jpg", + "21": "21.jpg", + "22": "22.jpg", + "23": "23.jpg" + } + frogs_img_prepare = frogs_img[name] + frogs_img_str = f"styles/frogs/{frogs_img_prepare}" + return frogs_img_str + + class Book: # Окно с необходимой информацией @staticmethod def info(screen, event): @@ -24,8 +55,6 @@ class Book: # Окно с необходимой информацией font = pg.font.Font(None, 15) # Здесь будет указана информация о некоторых лягушках for col in range(1): for row in range(1): - pg.draw.rect(screen, (255, 255, 255), (100 + 120 * col, 375 + 40 * row, 35, 35), - 1) # Рамка с портретом лягушки if col == 0: i = row elif col == 1: @@ -34,6 +63,11 @@ class Book: # Окно с необходимой информацией i = row + 6 else: i = row + 9 + myimage = pg.image.load(get_frogs_img(frogs[i][0])) + scaled_image = pg.transform.smoothscale(myimage, (34, 34)) + screen.blit(scaled_image, (100 + 120 * col + 1, 375 + 40 * row + 1)) + pg.draw.rect(screen, (0, 0, 0), (100 + 120 * col, 375 + 40 * row, 35, 35), + 3) # Рамка с портретом лягушки 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)) diff --git a/modules/Game.py b/modules/Game.py index 608fd5f..772e281 100644 --- a/modules/Game.py +++ b/modules/Game.py @@ -28,6 +28,8 @@ class Game: self.running = False if event.type == pg.MOUSEBUTTONDOWN: self.swamp.get_click(event.pos) + size = 700, 500 + self.screen = pg.display.set_mode(size) self.screen.fill((93, 101, 48)) self.swamp.render(self.screen) pg.display.flip() diff --git a/modules/Swamp.py b/modules/Swamp.py index d2ef881..f5b9c3e 100644 --- a/modules/Swamp.py +++ b/modules/Swamp.py @@ -37,6 +37,8 @@ class Swamp: scaled_image = pg.transform.smoothscale(myimage, (x, y)) screen.blit(scaled_image, (0, 0)) + pg.draw.rect(screen, (255, 255, 255), (0, 0, 40, 40)) + 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)) @@ -98,6 +100,9 @@ class Swamp: self.cell_info = self.board[-1][cell_coords[0]] self.time_to_close = 10 return cell_coords + if 0 <= mouse_pos[0] <= 40 and 0 <= mouse_pos[1] <= 40: + from modules.minigames.arkady import start + start() 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 diff --git a/modules/minigames/arkady.py b/modules/minigames/arkady.py new file mode 100644 index 0000000..19521a8 --- /dev/null +++ b/modules/minigames/arkady.py @@ -0,0 +1,129 @@ +import pygame as pg +from math import pi, sin, cos +from random import * + + +class Game: + def __init__(self): + self.line = None + self.old_color = None + self.interval_x = None + self.interval_y = None + self.colors = [tuple([randrange(50, 256, 40) for _ in range(3)]) for _ in range(10)] + self.intervals_x = [(430, 460), (350, 430), (245, 350), (165, 245), (130, 165), (130, 165), (165, 245), + (245, 350), (350, 430), (430, 460)] + self.intervals_y = [(170, 265), (113, 170), (113, 113), (113, 170), (170, 265), (265, 360), (360, 425), + (425, 425), (365, 425), (265, 365)] + self.line_color = choice(self.colors) + self.clock = pg.time.Clock() + self.speed = 15 # Здесь можно менять скорость + self.right = False + self.lose = False + self.corner = 440 + self.scores = 0 + self.x = 300 + self.y = 430 + + def render(self, screen_move): # Создание круга из случайных цветов и стрелки + pg.draw.arc(screen_move, (self.colors[0]), + (120, 90, 350, 350), 0, pi / 5, 7) + pg.draw.arc(screen_move, (self.colors[1]), + (120, 90, 350, 350), pi / 5, 2 * pi / 5, 7) + pg.draw.arc(screen_move, (self.colors[2]), + (120, 90, 350, 350), 2 * pi / 5, 3 * pi / 5, 7) + pg.draw.arc(screen_move, (self.colors[3]), + (120, 90, 350, 350), 3 * pi / 5, 4 * pi / 5, 7) + pg.draw.arc(screen_move, (self.colors[4]), + (120, 90, 350, 350), 4 * pi / 5, pi, 7) + pg.draw.arc(screen_move, (self.colors[5]), + (120, 90, 350, 350), pi, 6 * pi / 5, 7) + pg.draw.arc(screen_move, (self.colors[6]), + (120, 90, 350, 350), 6 * pi / 5, 7 * pi / 5, 7) + pg.draw.arc(screen_move, (self.colors[7]), + (120, 90, 350, 350), 7 * pi / 5, 8 * pi / 5, 7) + pg.draw.arc(screen_move, (self.colors[8]), + (120, 90, 350, 350), 8 * pi / 5, 9 * pi / 5, 7) + pg.draw.arc(screen_move, (self.colors[9]), + (120, 90, 350, 350), 9 * pi / 5, 2 * pi, 7) + pg.draw.line(screen_move, self.line_color, [300, 270], [self.x, self.y], 9) + + font = pg.font.Font(None, 50) + text = font.render('Счёт:', True, (255, 255, 255)) + screen_move.blit(text, (50, 500)) + text = font.render(f'{self.scores}/10', True, (255, 255, 255)) + screen_move.blit(text, (70, 540)) + if self.scores == 10: + print("Прекол") + + def side_change(self): # Изменение стороны и проверка + if not self.right: + self.right = True + elif self.right: + self.right = False + if color_change: + self.old_color = self.line_color + while self.old_color == self.line_color: + self.line_color = choice(self.colors) + + self.interval_x = self.intervals_x[self.colors.index(self.old_color)] + self.interval_y = self.intervals_y[self.colors.index(self.old_color)] + if self.interval_x[0] <= round(self.x) <= self.interval_x[1] and \ + ((round(self.y) <= self.interval_y[0] == self.interval_y[1]) or + (self.interval_y[0] <= round(self.y) <= self.interval_y[1])): + self.scores += 1 + self.speed += 10 + else: + print("Не прекол") + global running + running = False + + def animation(self): # анимация (изменение координат) + if self.right: + if self.corner > 90 and self.corner > 270: + self.y = sin(abs(self.corner)) * 165 + 270 + self.x = cos(abs(self.corner)) * 165 + 295 + else: + self.y = sin(abs(self.corner)) * 165 + 270 + self.x = -cos(abs(self.corner)) * 165 + 295 + self.corner += self.speed * self.clock.tick(50000) / 10000 + else: + if self.corner > 90 or self.corner > 270: + self.y = sin(abs(self.corner)) * 165 + 270 + self.x = cos(abs(self.corner)) * 165 + 295 + else: + self.y = sin(abs(self.corner)) * 165 + 270 + self.x = -cos(abs(self.corner)) * 165 + 295 + self.line = pg.transform.rotate(self.line, self.corner) + self.corner -= self.speed * self.clock.tick(50000) / 10000 + + +pg.init() +size = 600, 600 +animation = False +color_change = False +running = True + + +def start(): + global running, animation, color_change + pg.init() + screen = pg.display.set_mode(size) + game = Game() + animation = False + color_change = False + running = True + while running: + for event in pg.event.get(): + if event.type == pg.QUIT: + running = False + if event.type == pg.MOUSEBUTTONDOWN: # Запуск игры + animation = True + game.side_change() + color_change = True + if animation: + game.animation() + pg.display.update() + screen.fill((40, 40, 40)) + game.render(screen) + pg.display.flip() + pg.display.quit() diff --git a/test.py b/test.py index 1bf974d..e69de29 100644 --- a/test.py +++ b/test.py @@ -1,124 +0,0 @@ -import pygame as pg -from math import pi -from time import sleep -from random import * - - -class Game(): - def __init__(self): - self.colors = [tuple([randrange(50, 256) for _ in range(3)]) for _ in range(9)] - self.line_color = choice(self.colors) - self.right = choice([True, False]) - self.lose = False - self.win = False - self.scores = 0 - - def render(self, screen): # Создание круга из случайных цветов и стрелки - pg.draw.arc(screen, (self.colors[0]), - (120, 90, 350, 350), 0, pi / 9, 7) - pg.draw.arc(screen, (self.colors[1]), - (120, 90, 350, 350), pi / 9, 2 * pi / 9, 7) - pg.draw.arc(screen, (self.colors[2]), - (120, 90, 350, 350), 2 * pi / 9, 3 * pi / 9, 7) - pg.draw.arc(screen, (self.colors[3]), - (120, 90, 350, 350), 3 * pi / 9, 4 * pi / 9, 7) - pg.draw.arc(screen, (self.colors[4]), - (120, 90, 350, 350), 4 * pi / 9, 5 * pi / 9, 7) - pg.draw.arc(screen, (self.colors[5]), - (120, 90, 350, 350), 5 * pi / 9, 6 * pi / 9, 7) - pg.draw.arc(screen, (self.colors[6]), - (120, 90, 350, 350), 6 * pi / 9, 7 * pi / 9, 7) - pg.draw.arc(screen, (self.colors[7]), - (120, 90, 350, 350), 7 * pi / 9, 8 * pi / 9, 7) - pg.draw.arc(screen, (self.colors[8]), - (120, 90, 350, 350), 8 * pi / 9, pi, 7) - pg.draw.line(screen, (self.line_color), [300, 270], [300, 130], 9) - - font = pg.font.Font(None, 50) - text = font.render('Счёт:', True, (255, 255, 255)) - screen.blit(text, (50, 300)) - text = font.render(f'{self.scores}/10', True, (255, 255, 255)) - screen.blit(text, (70, 340)) - - if self.lose: - Lose.text(self) - elif self.win: - Win.text(self) - - def side_change(self): # Изменение стороны - if not self.right: - self.right = True - elif self.right: - self.right = False - if color_change: - self.old_color = self.line_color - while self.old_color == self.line_color: - self.line_color = choice(self.colors) - - def animation(self): # анимация (изменение координат) - if self.right: - sleep(0.4) - self.color = self.colors[0] - del self.colors[0] - self.colors.append(self.color) - else: - sleep(0.4) - self.colors.reverse() - self.color = self.colors[0] - del self.colors[0] - self.colors.append(self.color) - self.colors.reverse() - if self.scores == 10: - self.win = True - - def check(self): - if self.line_color == self.colors[3] or self.line_color == self.colors[5] or self.line_color == self.colors[4]: - self.scores += 1 - else: - self.lose = True - - -class Win: - def text(self): - pg.draw.rect(screen, (40, 40, 40), (0, 0, 599, 599)) - font = pg.font.Font(None, 70) - text = font.render('Вы выиграли!', True, (255, 255, 255)) - screen.blit(text, (120, 150)) - - -class Lose: - def text(self): - pg.draw.rect(screen, (40, 40, 40), (0, 0, 599, 599)) - font = pg.font.Font(None, 70) - text = font.render('Вы проиграли!', True, (255, 255, 255)) - screen.blit(text, (120, 150)) - - -if __name__ == '__main__': - pg.init() - size = 600, 400 - screen = pg.display.set_mode(size) - game = Game() - animation = False - color_change = False - running = True - - while running: - for event in pg.event.get(): - if event.type == pg.QUIT: - running = False - if event.type == pg.MOUSEBUTTONDOWN: # Запуск игры - if color_change == False: - animation = True - game.side_change() - color_change = True - else: - game.side_change() - game.check() - if animation: - game.animation() - pg.display.update() - screen.fill((40, 40, 40)) - game.render(screen) - pg.display.flip() - pg.display.quit()