Форум сайта python.su
Не запускается программа помогите пожалуйста
Основная программа
import sys import pygame from settings import Settings from ship import Ship def run_game(): pygame.init() ai_settings=Settings() screen=pygame.display.set_mode( (ai_settings.screen_width,ai_settings.screen_height))# открывает графическое окно pygame.display.set_caption('Alien Invasion') ship = Ship(ai_settings) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() screen.fill(ai_settings.bg_color) ship.blitme() pygame.display.flip() run_game()
import pygame class Ship(): def __init__(self,screen): self.screen=screen self.image=pygame.image.load_basic('images/ship.bmp') self.rect=self.image.get_rect() self.screen_rect=screen.get_rect() self.rect.centerx=self.screen_rect.centrex self.rect.bottom=self.screen_rect.bottom def blitme(self): self.screen.blit(self.image,self.rect)
class Settings(): def __init__(self): self.screen_width=1200 self.screen_height=600 self.bg_color=(255,0,0)
Traceback (most recent call last): File "D:/програмирование/pyton/alien_invasion/aloen_invasion.py", line 18, in <module> run_game() File "D:/програмирование/pyton/alien_invasion/aloen_invasion.py", line 11, in run_game ship = Ship(ai_settings) File "D:\програмирование\pyton\alien_invasion\ship.py", line 7, in __init__ self.screen_rect=screen.get_rect() AttributeError: 'Settings' object has no attribute 'get_rect'
Отредактировано matvey21 (Март 6, 2018 20:43:06)
Офлайн
код нужно постить в специальных тегах code, иначе теряется оформление (вы же сами это видите) и программа становится не читаемой - а значит вам вероятнее всего никто не поможет
Офлайн