From eb504bc7f10b30515bea2e1d625bb7f3bf625904 Mon Sep 17 00:00:00 2001 From: IljaP Date: Fri, 26 Apr 2024 08:59:21 +0300 Subject: [PATCH] lives update --- domino.py | 11 +++++++++++ main.py | 4 ++++ screens.py | 2 ++ settings.py | 30 +++++++++++++++--------------- 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/domino.py b/domino.py index a068f73..f13a969 100644 --- a/domino.py +++ b/domino.py @@ -20,6 +20,7 @@ class Domino(pygame.sprite.Sprite): self.surf.fill(self.color) self.rect = self.surf.get_rect(center=(x, y)) self.index = index + self.lives = 3 self.type_pos = "hand" @@ -27,6 +28,8 @@ class Domino(pygame.sprite.Sprite): self.values = values + self.damage = True + def blit_domino(self, screen, dominos): movement = self.w + 10 @@ -121,6 +124,9 @@ class Domino(pygame.sprite.Sprite): elif empty.pos == "both": move = True + + + # ставим домино на место пустышки, и добавляем в группу объектов игрового стола if move: self.surf.fill(self.color) @@ -154,6 +160,11 @@ class Domino(pygame.sprite.Sprite): empty.kill() + else: + if self.damage: + game.lives -= 1 + self.damage = False + # если домино не за пределами руки - возвращаем её на место diff --git a/main.py b/main.py index 44b97cd..9b83ffe 100644 --- a/main.py +++ b/main.py @@ -158,6 +158,10 @@ while run: if len(dominos) <= 0 and len(s.DOMINOS) <= 0: win = True break + elif game_screen.lives <= 0: + break + + print(game_screen.lives) pygame.display.flip() diff --git a/screens.py b/screens.py index 9a88b23..c1dbe2b 100644 --- a/screens.py +++ b/screens.py @@ -108,6 +108,8 @@ class Game_screen(pygame.sprite.Sprite): self.empty_up = empty_both self.empty_down = empty_both + self.lives = 3 + def blit_g_screen(self, screen, dominos): # add_empty() diff --git a/settings.py b/settings.py index d902db3..3a80e10 100644 --- a/settings.py +++ b/settings.py @@ -8,14 +8,14 @@ DOMINO_H = 200 DOMINOS = [] -# values = range(7) -# for v_up in values: -# for v_down in values: -# if not [v_up, v_down] in DOMINOS and not [v_down, v_up] in DOMINOS: -# DOMINOS.append([v_up, v_down]) +values = range(7) +for v_up in values: + for v_down in values: + if not [v_up, v_down] in DOMINOS and not [v_down, v_up] in DOMINOS: + DOMINOS.append([v_up, v_down]) -for _ in range(10): - DOMINOS.append([[1, '1'], [1, '1']]) +# for _ in range(10): +# DOMINOS.append([[1, '1'], [1, '1']]) # print(DOMINOS) @@ -29,14 +29,14 @@ str_values = { 5: ["10/2", "25^0.5", "2*5/2", "4!-19", "True*10/2", "3+2", "100/20", "4*1.25", "int(5.839)", "5+5-5+5-5", "2.5*2"], 6: ["3!", "2+2*2", "round(pi)*2", "(if 6>1)*6", "10-4", "24/4", "sqrt(12*3)", "3^2-3", "2*(4-1)", "{1,3,6}[2]"] } -# -# for i in range(len(DOMINOS)): -# v_up = choice(str_values[DOMINOS[i][0]]) -# str_values[DOMINOS[i][0]].remove(v_up) -# v_down = choice(str_values[DOMINOS[i][1]]) -# str_values[DOMINOS[i][1]].remove(v_down) -# -# DOMINOS[i] = [[DOMINOS[i][0], v_up], [DOMINOS[i][1], v_down]] + +for i in range(len(DOMINOS)): + v_up = choice(str_values[DOMINOS[i][0]]) + str_values[DOMINOS[i][0]].remove(v_up) + v_down = choice(str_values[DOMINOS[i][1]]) + str_values[DOMINOS[i][1]].remove(v_down) + + DOMINOS[i] = [[DOMINOS[i][0], v_up], [DOMINOS[i][1], v_down]] # print(DOMINOS)