Home > other >  Python pycharm environment compiler error problem - the alien spacecraft war
Python pycharm environment compiler error problem - the alien spacecraft war

Time:11-10

 

The import sys
The import pygame
The from Settings import Settings


Def run_game () :
# to initialize the game and create a screen object
Pygame. The init ()
Ai_settings=Settings
Screen=pygame. Display. Set_mode ((ai_settings. Screen_width, ai_settings. Screen_height))
Pygame. Display. Set_caption (" Alien night ")
# set the background color in
# bg_color=(230230230,)
# start playing the main loop of
While True:
# monitor keyboard and mouse events
For the event in pygame. Event. The get () :
If the event. The type==pygame. QUIT:
Sys. The exit ()
# every loop redrawing the screen
Screen. The fill (ai_settings. Bg_color)
# let recently painted screen visible
Pygame. Display. Flip ()


Run_game ()


The class Settings:
"" "storage "alien invasion" of all the Settings class ", "

Def __init__ (self) :
"" "initialize game Settings "","
# screen Settings
Self. Screen_width=1200
Self. Screen_height=800
Self. Bg_color=(230, 230, 230)



Error:
Screen=pygame. Display. Set_mode ((ai_settings. Screen_width, ai_settings. Screen_height))
AttributeError: type object 'Settings' has no attribute' screen_width '

CodePudding user response:

Def __init__ (self) to def __init__ (self, screen_width and screen_height, bg_color)??

CodePudding user response:

Ai_settings=Settings here should be Settings followed by ()

CodePudding user response:

Ai_settings=Settings
Instead of
Ai_settings=Settings ()

CodePudding user response:

To ai_settings=Settings ()
  • Related