syntasix fix
parent
eb504bc7f1
commit
f92bc14d3a
|
@ -56,11 +56,13 @@ class Domino(pygame.sprite.Sprite):
|
||||||
# (self.rect.x + (self.w / 2), self.rect.y + (self.h / 4)))
|
# (self.rect.x + (self.w / 2), self.rect.y + (self.h / 4)))
|
||||||
|
|
||||||
screen.blit(v_up,
|
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())
|
# 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, (
|
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,
|
# screen.blit(v_up,
|
||||||
# (310, 16))
|
# (310, 16))
|
||||||
|
|
||||||
|
@ -124,9 +126,6 @@ class Domino(pygame.sprite.Sprite):
|
||||||
elif empty.pos == "both":
|
elif empty.pos == "both":
|
||||||
move = True
|
move = True
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# ставим домино на место пустышки, и добавляем в группу объектов игрового стола
|
# ставим домино на место пустышки, и добавляем в группу объектов игрового стола
|
||||||
if move:
|
if move:
|
||||||
self.surf.fill(self.color)
|
self.surf.fill(self.color)
|
||||||
|
|
15
main.py
15
main.py
|
@ -39,11 +39,9 @@ group_game_screen.add(game_screen)
|
||||||
hand_screen = Hand_screen()
|
hand_screen = Hand_screen()
|
||||||
group_hand_screen.add(hand_screen)
|
group_hand_screen.add(hand_screen)
|
||||||
|
|
||||||
|
|
||||||
get_button = Button()
|
get_button = Button()
|
||||||
group_hand_screen.add(get_button)
|
group_hand_screen.add(get_button)
|
||||||
|
|
||||||
|
|
||||||
x = 100
|
x = 100
|
||||||
y = SCREEN_HEIGHT - DOMINO_H / 2 - 25
|
y = SCREEN_HEIGHT - DOMINO_H / 2 - 25
|
||||||
|
|
||||||
|
@ -57,7 +55,6 @@ for i in range(6):
|
||||||
dominos.add(domino)
|
dominos.add(domino)
|
||||||
group_hand_screen.add(domino)
|
group_hand_screen.add(domino)
|
||||||
|
|
||||||
|
|
||||||
pygame.display.flip()
|
pygame.display.flip()
|
||||||
run = True
|
run = True
|
||||||
|
|
||||||
|
@ -118,7 +115,8 @@ while run:
|
||||||
values = False
|
values = False
|
||||||
|
|
||||||
if time() - r_click_time >= r_click_cd and len(dominos) != 0:
|
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:
|
if values:
|
||||||
domino_new = Domino(coor[0], coor[1], values, len(dominos) - 1)
|
domino_new = Domino(coor[0], coor[1], values, len(dominos) - 1)
|
||||||
dominos.add(domino_new)
|
dominos.add(domino_new)
|
||||||
|
@ -135,6 +133,7 @@ while run:
|
||||||
|
|
||||||
screen.fill((230, 230, 230))
|
screen.fill((230, 230, 230))
|
||||||
|
|
||||||
|
|
||||||
def blit_group(group):
|
def blit_group(group):
|
||||||
"""блит группы"""
|
"""блит группы"""
|
||||||
for entity in group:
|
for entity in group:
|
||||||
|
@ -146,11 +145,11 @@ while run:
|
||||||
else:
|
else:
|
||||||
screen.blit(entity.surf, entity.rect)
|
screen.blit(entity.surf, entity.rect)
|
||||||
|
|
||||||
|
|
||||||
# blit_group(group_game_screen)
|
# blit_group(group_game_screen)
|
||||||
game_screen.blit_g_screen(screen, dominos)
|
game_screen.blit_g_screen(screen, dominos)
|
||||||
blit_group(group_hand_screen)
|
blit_group(group_hand_screen)
|
||||||
|
|
||||||
|
|
||||||
mouse_old_pos = [pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1]]
|
mouse_old_pos = [pygame.mouse.get_pos()[0], pygame.mouse.get_pos()[1]]
|
||||||
|
|
||||||
# print(len(dominos), len(s.DOMINOS))
|
# print(len(dominos), len(s.DOMINOS))
|
||||||
|
@ -168,7 +167,6 @@ while run:
|
||||||
# экран победы
|
# экран победы
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if win:
|
if win:
|
||||||
text = "You win!"
|
text = "You win!"
|
||||||
else:
|
else:
|
||||||
|
@ -193,10 +191,9 @@ while run:
|
||||||
color = (255, 50, 50)
|
color = (255, 50, 50)
|
||||||
surf.fill(color)
|
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(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()
|
pygame.display.flip()
|
||||||
|
|
17
screens.py
17
screens.py
|
@ -3,14 +3,17 @@ import settings as s
|
||||||
from time import time
|
from time import time
|
||||||
from random import choice
|
from random import choice
|
||||||
from json import dumps
|
from json import dumps
|
||||||
|
|
||||||
# from domino import Domino
|
# from domino import Domino
|
||||||
|
|
||||||
|
|
||||||
pygame.font.init()
|
pygame.font.init()
|
||||||
my_font = pygame.font.SysFont('Calibri (Body)', 50)
|
my_font = pygame.font.SysFont('Calibri (Body)', 50)
|
||||||
|
|
||||||
|
|
||||||
class Hand_screen(pygame.sprite.Sprite):
|
class Hand_screen(pygame.sprite.Sprite):
|
||||||
"""рука игрока"""
|
"""рука игрока"""
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.type = "hand_screen"
|
self.type = "hand_screen"
|
||||||
|
@ -33,21 +36,20 @@ class Button(pygame.sprite.Sprite):
|
||||||
self.color = (101, 71, 60)
|
self.color = (101, 71, 60)
|
||||||
self.surf = pygame.Surface((self.w, self.h))
|
self.surf = pygame.Surface((self.w, self.h))
|
||||||
self.surf.fill(self.color)
|
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.rect = self.surf.get_rect(center=(self.pos[0] - self.w / 2, self.pos[1]))
|
||||||
self.text = "take new domino"
|
self.text = "take new domino"
|
||||||
|
|
||||||
|
|
||||||
def blit_button(self, screen):
|
def blit_button(self, screen):
|
||||||
# блит кнопки
|
# блит кнопки
|
||||||
screen.blit(self.surf, self.rect)
|
screen.blit(self.surf, self.rect)
|
||||||
|
|
||||||
text = my_font.render(f"{self.text}", True, (255, 255, 255))
|
text = my_font.render(f"{self.text}", True, (255, 255, 255))
|
||||||
screen.blit(text,
|
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())
|
# 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):
|
def active_button(self, mouse_x, mouse_y, r_click_time, dominos):
|
||||||
# если нажали на кнопку, добавляем домино в руку
|
# если нажали на кнопку, добавляем домино в руку
|
||||||
values = False
|
values = False
|
||||||
|
@ -63,8 +65,10 @@ class Button(pygame.sprite.Sprite):
|
||||||
return time(), values, [x, y]
|
return time(), values, [x, y]
|
||||||
return r_click_time, False, False
|
return r_click_time, False, False
|
||||||
|
|
||||||
|
|
||||||
class Empty_domino(pygame.sprite.Sprite):
|
class Empty_domino(pygame.sprite.Sprite):
|
||||||
"""пустышка"""
|
"""пустышка"""
|
||||||
|
|
||||||
def __init__(self, x, y, pos):
|
def __init__(self, x, y, pos):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.type = "empty domino"
|
self.type = "empty domino"
|
||||||
|
@ -100,8 +104,6 @@ class Game_screen(pygame.sprite.Sprite):
|
||||||
self.group.add(empty_both)
|
self.group.add(empty_both)
|
||||||
self.empty_group.add(empty_both)
|
self.empty_group.add(empty_both)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
self.value_up = None
|
self.value_up = None
|
||||||
self.value_down = None
|
self.value_down = None
|
||||||
|
|
||||||
|
@ -126,6 +128,3 @@ class Game_screen(pygame.sprite.Sprite):
|
||||||
for entity in self.group:
|
for entity in self.group:
|
||||||
entity.rect.x -= mouse_x
|
entity.rect.x -= mouse_x
|
||||||
entity.rect.y -= mouse_y
|
entity.rect.y -= mouse_y
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -21,8 +21,10 @@ for v_up in values:
|
||||||
|
|
||||||
# в каждом по 8
|
# в каждом по 8
|
||||||
str_values = {
|
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"],
|
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",
|
||||||
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)"],
|
"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"],
|
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)"],
|
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)"],
|
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]]
|
DOMINOS[i] = [[DOMINOS[i][0], v_up], [DOMINOS[i][1], v_down]]
|
||||||
|
|
||||||
|
|
||||||
# print(DOMINOS)
|
# print(DOMINOS)
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue