Код выдает ошибку - AttributeError: 'Group' object has no attribute 'show_score'

WyRiX

Новичок
Пользователь
Фев 10, 2022
13
1
3
Python:
import pygame, sys
from bullet import Bullet
from ino import Ino
import time

def events(screen, gun, bullets):
    """обработка событий"""
    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            sys.exit()
        elif event.type == pygame.KEYDOWN:
            #вправо
            if event.key == pygame.K_d:
                gun.mright = True
            elif event.key == pygame.K_a:
                gun.mleft = True
            elif event.key == pygame.K_SPACE:
                new_bullet = Bullet(screen, gun)
                bullets.add(new_bullet)
        elif event.type == pygame.KEYUP:
            if event.key == pygame.K_d:
                gun.mright = False
            elif event.key == pygame.K_a:
                gun.mleft = False

def update(bg_color, screen, sc, stats, gun, inos, bullets,):
    """Обновление экрана"""
    screen.fill(bg_color)
    sc.show_score()
    for bullet in bullets.sprites():
        bullet.draw_bullet()
    gun.output()
    inos.draw(screen)
    pygame.display.flip()

def update_bullets(screen, inos, bullets):
    """обновление позиции пуль"""
    bullets.update()
    for bullet in bullets.copy():
        if bullet.rect.bottom <= 0:
            bullets.remove(bullet)
    collections = pygame.sprite.groupcollide(bullets, inos, True, True)
    if len(inos) == 0:
        bullets.empty()
        create_army(screen, inos)

def gun_kill(stats, screen, inos, bullets, gun):
    """столкновение пушки и армии"""
    if stats.guns_left > 0:
        stats.guns_left -= 1
        inos.empty()
        bullets.empty()
        create_army(screen, inos)
        gun.create_gun()
        time.sleep(1)
    else:
        stats.run_game = False
        sys.exit()

def update_inos(inos, bullets, screen, stats, gun):
    """обновляет позицию инопланетян"""
    inos.update()
    if pygame.sprite.spritecollideany(gun, inos):
        gun_kill(stats, screen, inos, bullets, gun)
    inos_check(stats, screen, gun, inos, bullets)

def inos_check(stats, screen, gun, inos, bullets):
    """Проверка пришельцев до края экрана"""
    screen_rect = screen.get_rect()
    for ino in inos.sprites():
        if ino.rect.bottom >= screen_rect.bottom:
            gun_kill(stats, screen, inos, bullets, gun)
            break

def create_army(screen, inos):
    """создание армии пришкльцев"""
    ino = Ino(screen)
    ino_width = ino.rect.width
    number_ino_x = int((700 - 2 * ino_width) / ino_width)
    ino_height = ino.rect.height
    number_ino_y = int((800 - 100 - 2 * ino_height) / ino_height)

    for row_number in range(number_ino_x - 3):
        for ino_number in range(number_ino_x):
            ino = Ino(screen)
            ino.x = ino_width + (ino_width * ino_number)
            ino.y = ino_height + (ino_height * row_number)
            ino.rect.x = ino.x
            ino.rect.y = ino.rect.height + ino.rect.height * row_number
            inos.add(ino)

после выдает ошибку -
File "C:\Users\Матвей Захарченко\PycharmProjects\PythonProjects\controles.py", line 29, in update
sc.show_score()
AttributeError: 'Group' object has no attribute 'show_score'

Работаю на 10 винде
Питон стоит 3.9.10
 

Domohod45

Новичок
Пользователь
Дек 7, 2021
68
3
8
Измените порядок аргументов с
def update(bg_color, screen, sc, stats, gun, inos, bullets,):
на
def update(bg_color, screen, stats, sc, gun, inos, bullets):
 

WyRiX

Новичок
Пользователь
Фев 10, 2022
13
1
3
Измените порядок аргументов с
def update(bg_color, screen, sc, stats, gun, inos, bullets,):
на
def update(bg_color, screen, stats, sc, gun, inos, bullets):
спасибо, но
потом выдает
File "C:\Users\Матвей Захарченко\PycharmProjects\PythonProjects\controles.py", line 29, in update
sc.show_score()
AttributeError: 'Scores' object has no attribute 'show_score'
 

Domohod45

Новичок
Пользователь
Дек 7, 2021
68
3
8
спасибо, но
потом выдает
File "C:\Users\Матвей Захарченко\PycharmProjects\PythonProjects\controles.py", line 29, in update
sc.show_score()
AttributeError: 'Scores' object has no attribute 'show_score'
Скиньте, пожалуйста, всё описание ошибки.
 

Форум IT Специалистов