gpt4 book ai didi

python - 总的Python处女,这段代码有什么问题? “Detect Indentation error.”

转载 作者:行者123 更新时间:2023-12-02 11:07:21 24 4
gpt4 key购买 nike

这段代码是什么问题,在您问我之前,我都是用youtube视频和简短的教程完成的。
如果有人可以帮助我编写代码,将不胜感激,在这种情况下,只需索取我的Skype,然后我将添加您,我需要这样做! :)。

在第253行,它说需要“预期的缩进块”,老实说,我不知道该怎么做。

    import pygame, sys, time, random, Globals
from pygame.locals import *

pygame.init()
pygame.mixer.init(frequency=22050, size=-16, channels=10, buffer=4096)

#Classes

class MenuButton(pygame.sprite.Sprite):
def __init__(self, image, image_dem, x, y):
self.image = pygame.image.load(image[0]).convert_alpha()
self.image_over = pygame.image.load(image[1]).convert_alpha()
self.image_dem = image_dem
self.x = x
self.y = y
self.rect = pygame.Rect(self.x, self.y, self.image_dem[0], self.image_dem[1])
def setXY(x, y):
self.x = x
self.y = y
def setImage(image, dem):
self.image = pygame.image.load(image[0]).convert_alpha()
self.image_over = pygame.image.load(image[1]).convert_alpha()
self.image_dem = dem

class Sprite(pygame.sprite.Sprite):
def __init__(self, image, image_dem, x, y):
self.image = pygame.image.load(image).convert_alpha()
self.image_dem = image_dem
self.x = x
self.y = y
self.rect = pygame.Rect(self.x, self.y, self.image_dem[0], self.image_dem[1])
def setXY(self, x, y):
self.x = x
self.y = y
def setImage(self, image, dem):
self.image = pygame.image.load(image).convert_alpha()
self.image_dem = image_dem

#Variables

GAME_LOOP = True
GAME_STATE = [ [False, 'Main_Menu' ], [False, 'About_Screen'], [False, 'Settings'], [False, 'Game'] ]

GAME_CLOCK = pygame.time.Clock()
DELTA_TIME = 0
FPS = 30

WINDOW_X = 900
WINDOW_Y = 600
WINDOW_CAPTION = 'The Intern'
WINDOW = pygame.display.set_mode([WINDOW_X, WINDOW_Y])

BLACK_BACKGROUND = pygame.image.load('asset/black.png').convert()

MAIN_MENU_BACKGROUND = pygame.image.load('main_menu_assets/background.png').convert_alpha()

MAIN_MENU_INTERN = MenuButton(['main_menu_assets/The_Intern.png', 'main_menu_assets/The_Intern.png'], [150, 50], 200, 60)
MAIN_MENU_START_BTN = MenuButton(['main_menu_assets/Start.png', 'main_menu_assets/Start.png'], [150, 50], 400, 250)
MAIN_MENU_SETTINGS_BTN = MenuButton(['main_menu_assets/Settings.png', 'main_menu_assets/Settings.png'], [150, 31], 400, 300)

SETTINGS_BACKGROUND = pygame.image.load('settings_assets/Background.png').convert()
SETTINGS_BACK_BTN = MenuButton(['settings_assets/Back.png', 'settings_assets/Back.png',], [62, 63], 10, 10)
SETTINGS_MUSIC_BTN = MenuButton(['settings_assets/Music.png', 'settings_assets/Music.png',], [309, 113], 300, 250)

#SOUND = pygame.mixer.Sound('main_menu_assets/tip.ogg')
#CHANNEL = pygame.mixer.Channel(6)


















#GAME LEVELS

LEVEL_1_BACKGROUND = pygame.image.load('game_assets/floor_l1.png').convert_alpha()
PLAYER_SPRITE = Sprite('game_assets/Male.png', [100,97], 400, 500)

LEVEL_1_ARRAY_ENEMIES = []
LEVEL_1_ARRAY_BULLETS = []


GAME_LEVEL_1 = True
GAME_LEVEL_2 = False
GAME_LEVEL_3 = False
GAME_LEVEL_4 = False
GAME_LEVEL_5 = False
GAME_LEVEL_6 = False


def level_1_gen_enemy():
y = random.randint(-50, -100)
x = random.randint(50, 800)
sprite = Sprite('Enemy_l1.png', [253,234], x, y)
LEVEL_1_ARRAY_ENEMIES.append(sprite)
return sprite

def setGameLevel(l):
global GAME_LEVEL_1, GAME_LEVEL_2, GAME_LEVEL_3, GAME_LEVEL_4, GAME_LEVEL_5, GAME_LEVEL_6
if l == 1:
GAME_LEVEL_1 = True
GAME_LEVEL_2 = False
GAME_LEVEL_3 = False
GAME_LEVEL_4 = False
GAME_LEVEL_5 = False
GAME_LEVEL_6 = False
if l == 2:
GAME_LEVEL_1 = False
GAME_LEVEL_2 = True
GAME_LEVEL_3 = False
GAME_LEVEL_4 = False
GAME_LEVEL_5 = False
GAME_LEVEL_6 = False
if l == 3:
GAME_LEVEL_1 = False
GAME_LEVEL_2 = False
GAME_LEVEL_3 = True
GAME_LEVEL_4 = False
GAME_LEVEL_5 = False
GAME_LEVEL_6 = False
if l == 4:
GAME_LEVEL_1 = False
GAME_LEVEL_2 = False
GAME_LEVEL_3 = False
GAME_LEVEL_4 = True
GAME_LEVEL_5 = False
GAME_LEVEL_6 = False
if l == 5:
GAME_LEVEL_1 = False
GAME_LEVEL_2 = False
GAME_LEVEL_3 = False
GAME_LEVEL_4 = False
GAME_LEVEL_5 = True
GAME_LEVEL_6 = False
if l == 6:
GAME_LEVEL_1 = False
GAME_LEVEL_2 = False
GAME_LEVEL_3 = False
GAME_LEVEL_4 = False
GAME_LEVEL_5 = False
GAME_LEVEL_6 = True

#games
#The first level is displayed below
minionCounter_level1 = 0
gameWon = False

def void_game_level_1():
WINDOW.blit(LEVEL_1_BACKGROUND, [0, 0])
if gameWon == False:
WINDOW.blit(PLAYER_SPRITE.image, [PLAYER_SPRITE.x, PLAYER_SPRITE.y])
level_1_gen_enemy()
if (minionCounter_level1 > 15):
gameWon = True
else:



def void_game_level_2():
a = 0

def void_game_level_3():
a = 0

def void_game_level_4():
a = 0

def void_game_level_5():
a = 0

def void_game_level_6():
a = 0

#loops
#These events show what will happen if a key or button is struck.
def void_game_loop_level_1(event):
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_LEFT:
PLAYER_SPRITE.x = PLAYER_SPRITE.x - 5
if event.key == pygame.K_a:
PLAYER_SPRITE.x = PLAYER_SPRITE.x - 5
if event.key == pygame.K_RIGHT:
PLAYER_SPRITE.x = PLAYER_SPRITE.x + 5
if event.key == pygame.K_d:
PLAYER_SPRITE.x = PLAYER_SPRITE.x + 5


def void_game_loop_level_2(event):
a = 0

def void_game_loop_level_3(event):
a = 0

def void_game_loop_level_4(event):
a = 0

def void_game_loop_level_5(event):
a = 0

def void_game_loop_level_6(event):
a = 0




















#Functions

def getGameState(name):
for state in GAME_STATE:
if state[1] == name:
return state
return state[0]

def setGameState(name):
global WINDOW
for state in GAME_STATE:
if state[1] == name:
state[0] = True
else:
state[0] = False

#Initilizers

def main_init():
pygame.display.set_caption(WINDOW_CAPTION)
setGameState('Main_Menu')
pygame.key.set_repeat(50,50)

def main_menu_event(event):
if event.type == MOUSEBUTTONDOWN:
start = MAIN_MENU_START_BTN.rect
settings = MAIN_MENU_SETTINGS_BTN.rect
mouse = event.pos
if start.collidepoint(mouse):
pygame.mixer.music.stop()
setGameState('Game')
if settings.collidepoint(mouse):
setGameState('Settings')

def main_menu_loop():
WINDOW.blit(MAIN_MENU_BACKGROUND, [0,0])
WINDOW.blit(MAIN_MENU_INTERN.image, [MAIN_MENU_INTERN.x, MAIN_MENU_INTERN.y])
WINDOW.blit(MAIN_MENU_START_BTN.image, [MAIN_MENU_START_BTN.x, MAIN_MENU_START_BTN.y])
WINDOW.blit(MAIN_MENU_SETTINGS_BTN.image, [MAIN_MENU_SETTINGS_BTN.x, MAIN_MENU_SETTINGS_BTN.y])

def gaming_event(event):
if(GAME_LEVEL_1 == True):
void_game_loop_level_1(event)
if(GAME_LEVEL_2 == True):
void_game_loop_level_2(event)
if(GAME_LEVEL_3 == True):
void_game_loop_level_3(event)
if(GAME_LEVEL_4 == True):
void_game_loop_level_4(event)
if(GAME_LEVEL_5 == True):
void_game_loop_level_5(event)
if(GAME_LEVEL_6 == True):
void_game_loop_level_6(event)

def gaming_loop():
if(GAME_LEVEL_1 == True):
void_game_level_1()
if(GAME_LEVEL_2 == True):
void_game_level_2()
if(GAME_LEVEL_3 == True):
void_game_level_3()
if(GAME_LEVEL_4 == True):
void_game_level_4()
if(GAME_LEVEL_5 == True):
void_game_level_5()
if(GAME_LEVEL_6 == True):
void_game_level_6()

def settings_event(event):
if event.type == MOUSEBUTTONDOWN:
back = SETTINGS_BACK_BTN.rect
music = SETTINGS_MUSIC_BTN.rect
mouse = event.pos
if back.collidepoint(mouse):
setGameState('Main_Menu')
if music.collidepoint(mouse):
if Globals.MASTER_SOUND == True:
pygame.mixer.music.stop()
Globals.MASTER_SOUND = False
else:
pygame.mixer.music.play()
MASTER_SOUND = True

def settings_loop():
WINDOW.blit(SETTINGS_BACKGROUND, [0,0])
WINDOW.blit(SETTINGS_BACK_BTN.image, [SETTINGS_BACK_BTN.x, SETTINGS_BACK_BTN.y])
WINDOW.blit(SETTINGS_MUSIC_BTN.image, [SETTINGS_MUSIC_BTN.x, SETTINGS_MUSIC_BTN.y])


#Testing Function
def p():
print 'ur'

def game_loop():

#GAME_LEVEL_1.setInit([p()])
#GAME_LEVEL_1.runInit()

about_screen = pygame.image.load('main_menu_assets/AboutScreen.png').convert()
WINDOW.blit(about_screen, [0,0])
pygame.display.flip()
time.sleep(1)
WINDOW.blit(about_screen, [1000,1000])

while GAME_LOOP == True:
DELTA_TIME = GAME_CLOCK.tick(FPS)
for event in pygame.event.get():
if event.type == QUIT:
pygame.quit
sys.exit()
if getGameState('Main_Menu')[0] == True:
main_menu_event(event)
if getGameState('Game')[0] == True:
gaming_event(event)
if getGameState('Settings')[0] == True:
settings_event(event)
if getGameState('Main_Menu')[0] == True:
main_menu_loop()
if getGameState('Game')[0] == True:
gaming_loop()
if getGameState('Settings')[0] == True:
settings_loop()

pygame.display.flip()

#Main

def main():
pygame.mixer.music.load('main_menu_assets/main_menu_song.ogg')
if Globals.MASTER_SOUND:
pygame.mixer.music.play(-1)
main_init()
game_loop()

main()

最佳答案

def void_game_level_1():
WINDOW.blit(LEVEL_1_BACKGROUND, [0, 0])
if gameWon == False:
WINDOW.blit(PLAYER_SPRITE.image, [PLAYER_SPRITE.x, PLAYER_SPRITE.y])
level_1_gen_enemy()
if (minionCounter_level1 > 15):
gameWon = True
else:

您忘记完成此功能。以后,请查看错误消息告诉您的行,然后再查看其上方的行,因为该问题通常发生在较早的行上,并且仅在该错误所指的行上被检测到。另外,发布收到的任何错误消息的全文。

关于python - 总的Python处女,这段代码有什么问题? “Detect Indentation error.”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20509034/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com