鱼C论坛

 找回密码
 立即注册
查看: 2142|回复: 2

望大神解答!!!

[复制链接]
发表于 2018-11-4 20:50:57 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能^_^

您需要 登录 才可以下载或查看,没有账号?立即注册

x
game.py
import sys
import pygame
from settings import Settings
def run_game():
    #初始化游戏并创建一个游戏对象
    pygame.init()
    #初始化pygame、设置和屏幕对象
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width,ai_settings.screen_height))
    pygame.display.set_caption("Alien Invasion")
    #开始游戏的循环
    while True:
        #监视键盘和鼠标事件
        for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    sys.exit()
        #每次循环都重绘屏幕
        screen.fill(ai_settings.bg_color)
        #让最近绘制的屏幕可见
        pygame.display.flip()
run_game()

setting.py
class Settings():
    """存储《外星人入侵》的所有设置的类"""
    def __int__(self):
        """初始化游戏的设置"""
        #屏幕设置
        self.screen_width = 1200
        self.screen_height = 700
        self.bg_color = (230,230,230)
game.py中调用setting.py中的Settings类时出现以下错误:
screen = pygame.display.set_mode((ai_settings.screen_width,ai_settings.screen_height))
AttributeError: 'Settings' object has no attribute 'screen_width'

实在不懂为什么?
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复

使用道具 举报

发表于 2018-11-5 16:15:45 | 显示全部楼层
def __init__(self):
你写成了__int__
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

 楼主| 发表于 2018-11-5 20:44:16 | 显示全部楼层
fish_游鱼 发表于 2018-11-5 16:15
def __init__(self):
你写成了__int__

问题已解决,谢谢!
想知道小甲鱼最近在做啥?请访问 -> ilovefishc.com
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

小黑屋|手机版|Archiver|鱼C工作室 ( 粤ICP备18085999号-1 | 粤公网安备 44051102000585号)

GMT+8, 2024-10-6 13:15

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表