From f92bc14d3a2c7a70d992f93cfe60b7ebb43e8f6e Mon Sep 17 00:00:00 2001 From: IljaP Date: Fri, 26 Apr 2024 09:07:16 +0300 Subject: [PATCH] syntasix fix --- domino.py | 9 ++++----- main.py | 15 ++++++--------- screens.py | 17 ++++++++--------- settings.py | 9 ++++----- 4 files changed, 22 insertions(+), 28 deletions(-) diff --git a/domino.py b/domino.py index f13a969..57060ec 100644 --- a/domino.py +++ b/domino.py @@ -56,11 +56,13 @@ class Domino(pygame.sprite.Sprite): # (self.rect.x + (self.w / 2), self.rect.y + (self.h / 4))) screen.blit(v_up, - (self.rect.x + (self.w / 2) - v_up.get_width()/2, self.rect.y + (self.h / 4) - v_up.get_height()/2)) + (self.rect.x + (self.w / 2) - v_up.get_width() / 2, + self.rect.y + (self.h / 4) - v_up.get_height() / 2)) # print(self.rect.x + (self.w / 2) - v_up.get_width(), self.rect.y + (self.h / 4) - v_up.get_height()) screen.blit(v_down, ( - self.rect.x + (self.w / 2) - v_down.get_width()/2, self.rect.y + (self.h / 4) * 3 - v_down.get_height()/2)) + self.rect.x + (self.w / 2) - v_down.get_width() / 2, + self.rect.y + (self.h / 4) * 3 - v_down.get_height() / 2)) # screen.blit(v_up, # (310, 16)) @@ -124,9 +126,6 @@ class Domino(pygame.sprite.Sprite): elif empty.pos == "both": move = True - - - # ставим домино на место пустышки, и добавляем в группу объектов игрового стола if move: self.surf.fill(self.color) diff --git a/main.py b/main.py index 9b83ffe..0745008 100644 --- a/main.py +++ b/main.py @@ -39,11 +39,9 @@ group_game_screen.add(game_screen) hand_screen = Hand_screen() group_hand_screen.add(hand_screen) - get_button = Button() group_hand_screen.add(get_button) - x = 100 y = SCREEN_HEIGHT - DOMINO_H / 2 - 25 @@ -57,7 +55,6 @@ for i in range(6): dominos.add(domino) group_hand_screen.add(domino) - pygame.display.flip() run = True @@ -118,7 +115,8 @@ while run: values = False if time() - r_click_time >= r_click_cd and len(dominos) != 0: - r_click_time, values, coor = get_button.active_button(mouse_new_pos[0], mouse_new_pos[1], r_click_time, dominos) + r_click_time, values, coor = get_button.active_button(mouse_new_pos[0], mouse_new_pos[1], r_click_time, + dominos) if values: domino_new = Domino(coor[0], coor[1], values, len(dominos) - 1) dominos.add(domino_new) @@ -135,6 +133,7 @@ while run: screen.fill((230, 230, 230)) + def blit_group(group): """блит группы""" for entity in group: @@ -146,11 +145,11 @@ while run: else: screen.blit(entity.surf, entity.rect) + # blit_group(group_game_screen) game_screen.blit_g_screen(screen, dominos) blit_group(group_hand_screen) - mouse_old_pos = [pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1]] # print(len(dominos), len(s.DOMINOS)) @@ -168,7 +167,6 @@ while run: # экран победы - if win: text = "You win!" else: @@ -193,10 +191,9 @@ while run: color = (255, 50, 50) surf.fill(color) - rect = surf.get_rect(center=(s.SCREEN_WIDTH/2, s.SCREEN_HEIGHT/2)) + rect = surf.get_rect(center=(s.SCREEN_WIDTH / 2, s.SCREEN_HEIGHT / 2)) screen.blit(surf, rect) + screen.blit(text, (s.SCREEN_WIDTH / 2 - 250, s.SCREEN_HEIGHT / 2 - 100)) - screen.blit(text,(s.SCREEN_WIDTH/2 - 250, s.SCREEN_HEIGHT/2 - 100)) - pygame.display.flip() diff --git a/screens.py b/screens.py index c1dbe2b..7bf3ceb 100644 --- a/screens.py +++ b/screens.py @@ -3,14 +3,17 @@ import settings as s from time import time from random import choice from json import dumps + # from domino import Domino pygame.font.init() my_font = pygame.font.SysFont('Calibri (Body)', 50) + class Hand_screen(pygame.sprite.Sprite): """рука игрока""" + def __init__(self): super().__init__() self.type = "hand_screen" @@ -33,21 +36,20 @@ class Button(pygame.sprite.Sprite): self.color = (101, 71, 60) self.surf = pygame.Surface((self.w, self.h)) self.surf.fill(self.color) - self.pos = (s.SCREEN_WIDTH-30, s.SCREEN_HEIGHT - 350) + self.pos = (s.SCREEN_WIDTH - 30, s.SCREEN_HEIGHT - 350) self.rect = self.surf.get_rect(center=(self.pos[0] - self.w / 2, self.pos[1])) self.text = "take new domino" - def blit_button(self, screen): # блит кнопки screen.blit(self.surf, self.rect) text = my_font.render(f"{self.text}", True, (255, 255, 255)) screen.blit(text, - (self.rect.x + (self.w / 2) - text.get_width() / 2, self.rect.y + (self.h / 2) - text.get_height() / 2)) + (self.rect.x + (self.w / 2) - text.get_width() / 2, + self.rect.y + (self.h / 2) - text.get_height() / 2)) # print(self.rect.x + (self.w / 2) - v_up.get_width(), self.rect.y + (self.h / 4) - v_up.get_height()) - def active_button(self, mouse_x, mouse_y, r_click_time, dominos): # если нажали на кнопку, добавляем домино в руку values = False @@ -63,8 +65,10 @@ class Button(pygame.sprite.Sprite): return time(), values, [x, y] return r_click_time, False, False + class Empty_domino(pygame.sprite.Sprite): """пустышка""" + def __init__(self, x, y, pos): super().__init__() self.type = "empty domino" @@ -100,8 +104,6 @@ class Game_screen(pygame.sprite.Sprite): self.group.add(empty_both) self.empty_group.add(empty_both) - - self.value_up = None self.value_down = None @@ -126,6 +128,3 @@ class Game_screen(pygame.sprite.Sprite): for entity in self.group: entity.rect.x -= mouse_x entity.rect.y -= mouse_y - - - diff --git a/settings.py b/settings.py index 3a80e10..0e12d9a 100644 --- a/settings.py +++ b/settings.py @@ -21,8 +21,10 @@ for v_up in values: # в каждом по 8 str_values = { - 0: ["32*0", "2^2-4", "7-3.5*2", "-5+2.5*2", "0-0+0", "0/43", "False", "[1, 0][1]", "8*(3-3)", "not 3", "6+6-6+6-6-6"], - 1: ["0^0", "24/24", "True", "23>4", "1 or 0", "10-1*9", "sqrt(1)", "5^1/5", "7-6", "1!", "36/6^2", "-2+3", "if 'str'", "bool(-3)"], + 0: ["32*0", "2^2-4", "7-3.5*2", "-5+2.5*2", "0-0+0", "0/43", "False", "[1, 0][1]", "8*(3-3)", "not 3", + "6+6-6+6-6-6"], + 1: ["0^0", "24/24", "True", "23>4", "1 or 0", "10-1*9", "sqrt(1)", "5^1/5", "7-6", "1!", "36/6^2", "-2+3", + "if 'str'", "bool(-3)"], 2: ["2!", "8^0.34", "int(e)", "True+True", "14/7", "sqrt(4)", "sqrt(4)^2", "int('2')", "(1<3)*2", "3-1", "1+1"], 3: ["2!*1.5", "9/3", "round(pi)", "sqrt(9)", "(18/2)^0.5", "True*3", "5-2", "6/2", "3+0^1", "0^0*3", "round(3)"], 4: ["2*2", "3+1*1", "0+4", "int(e)*2", "8/2", "6-3+1", "(8+4)/3", "int('5')-1", "int(float(str(4.9)))", "sqrt(16)"], @@ -38,7 +40,4 @@ for i in range(len(DOMINOS)): DOMINOS[i] = [[DOMINOS[i][0], v_up], [DOMINOS[i][1], v_down]] - # print(DOMINOS) - -