@PRoGRamm_InG

Return функции attackForm возвращает None, почему?

import pygame

# screen variables

WIDTH = 600
HEIGHT = 400
FPS = 30
BLACK = (0, 0, 0)
YELLOW = (255, 255, 0)
RED = (255, 0, 0)
BLUE = (0, 255, 0)
GREEN = (0, 0, 255)
ORANGE = (255, 127.5, 0)
GRAY = (75, 75, 75)
pygame.init()

letterSize = 20
placeWidth = 75
placeHeight = 57
gameButtonImagesWidth = 233
gameButtonImagesHeight = 69
formSwitchButtonSize = 61

screen = pygame.display.set_mode((WIDTH, HEIGHT))
clock = pygame.time.Clock()

menuBgImg = pygame.image.load('menuBackground.png')
warBackgroundImg = pygame.image.load('warBackground.jpg')
menuButtonImg = pygame.image.load('menuButtonFourPeople.png')
preparationImg = pygame.image.load('preparationButton.png')
attackImg = pygame.image.load('attackButton.png')
yellowPlayerPlaceImg = pygame.image.load('yellowIsland.png')
redPlayerPlaceImg = pygame.image.load('redIsland.png')
greenPlayerPlaceImg = pygame.image.load('greenIsland.png')
bluePlayerPlaceImg = pygame.image.load('blueIsland.png')

menuBgImg = pygame.transform.scale(menuBgImg, (WIDTH, HEIGHT))
warBackgroundImg = pygame.transform.scale(warBackgroundImg, (WIDTH, HEIGHT))
menuButtonImg = pygame.transform.scale(menuButtonImg, (mainMenuButtonFourPeopleImagesWidth, mainMenuButtonFourPeopleImagesHeight))
preparationImg = pygame.transform.scale(preparationImg, (gameButtonImagesWidth, gameButtonImagesHeight))
attackImg = pygame.transform.scale(attackImg, (gameButtonImagesWidth, gameButtonImagesHeight))
yellowPlayerPlaceImg = pygame.transform.scale(yellowPlayerPlaceImg, (placeWidth, placeHeight))
redPlayerPlaceImg = pygame.transform.scale(redPlayerPlaceImg, (placeWidth, placeHeight))
greenPlayerPlaceImg = pygame.transform.scale(greenPlayerPlaceImg, (placeWidth, placeHeight))
bluePlayerPlaceImg = pygame.transform.scale(bluePlayerPlaceImg, (placeWidth, placeHeight))

gameList = [[[yellowPlayerPlaceImg, 6], [redPlayerPlaceImg, 6], [greenPlayerPlaceImg, 6], [bluePlayerPlaceImg, 6]], [[yellowPlayerPlaceImg, 6], [redPlayerPlaceImg, 6], [greenPlayerPlaceImg, 6], [bluePlayerPlaceImg, 6]],[[yellowPlayerPlaceImg, 6], [redPlayerPlaceImg, 6], [greenPlayerPlaceImg, 6], [bluePlayerPlaceImg, 6]],[[yellowPlayerPlaceImg, 6], [redPlayerPlaceImg, 6], [greenPlayerPlaceImg, 6], [bluePlayerPlaceImg, 6]]]
turnForm = 1
remainUnits = {'yellow':0, 'red':0, 'blue':0, 'green':0, }

screenForm = 1

quantity = 0

place0_0 = 5, 5
units0_0 = place0_0[0] + placeWidth / 2 - letterSize / 2, place0_0[1] + placeHeight / 2 - letterSize / 2
place0_1 = 10 + placeWidth, 5
units0_1 = place0_1[0] + placeWidth / 2 - letterSize / 2, place0_1[1] + placeHeight / 2 - letterSize / 2
place0_2 = 5, 10 + placeHeight
units0_2 = place0_2[0] + placeWidth / 2 - letterSize / 2, place0_2[1] + placeHeight / 2 - letterSize / 2
place0_3 = 10 + placeWidth, 10 + placeHeight
units0_3 = place0_3[0] + placeWidth / 2 - letterSize / 2, place0_3[1] + placeHeight / 2 - letterSize / 2

place1_0 = WIDTH - (10 + placeWidth * 2), 5
units1_0 = place1_0[0] + placeWidth / 2 - letterSize / 2, place1_0[1] + placeHeight / 2 - letterSize / 2
place1_1 = WIDTH - (5 + placeWidth), 5
units1_1 = place1_1[0] + placeWidth / 2 - letterSize / 2, place1_1[1] + placeHeight / 2 - letterSize / 2
place1_2 = WIDTH - (10 + placeWidth * 2), 10 + placeHeight
units1_2 = place1_2[0] + placeWidth / 2 - letterSize / 2, place1_2[1] + placeHeight / 2 - letterSize / 2
place1_3 = WIDTH - (5 + placeWidth), 10 + placeHeight
units1_3 = place1_3[0] + placeWidth / 2 - letterSize / 2, place1_3[1] + placeHeight / 2 - letterSize / 2

place2_0 = 5, HEIGHT - (10 + placeHeight * 2)
units2_0 = place2_0[0] + placeWidth / 2 - letterSize / 2, place2_0[1] + placeHeight / 2 - letterSize / 2
place2_1 = 10 + placeWidth, HEIGHT - (10 + placeHeight * 2)
units2_1 = place2_1[0] + placeWidth / 2 - letterSize / 2, place2_1[1] + placeHeight / 2 - letterSize / 2
place2_2 = 5, HEIGHT - (5 + placeHeight)
units2_2 = place2_2[0] + placeWidth / 2 - letterSize / 2, place2_2[1] + placeHeight / 2 - letterSize / 2
place2_3 = (10 + placeWidth), HEIGHT - (5 + placeHeight)
units2_3 = place2_3[0] + placeWidth / 2 - letterSize / 2, place2_3[1] + placeHeight / 2 - letterSize / 2

place3_0 = WIDTH - (10 + placeWidth * 2), HEIGHT - (10 + placeHeight * 2)
units3_0 = place3_0[0] + placeWidth / 2 - letterSize / 2, place3_0[1] + placeHeight / 2 - letterSize / 2
place3_1 = WIDTH - (5 + placeWidth), HEIGHT - (10 + placeHeight * 2)
units3_1 = place3_1[0] + placeWidth / 2 - letterSize / 2, place3_1[1] + placeHeight / 2 - letterSize / 2
place3_2 = WIDTH - (10 + placeWidth * 2), HEIGHT - (5 + placeHeight)
units3_2 = place3_2[0] + placeWidth / 2 - letterSize / 2, place3_2[1] + placeHeight / 2 - letterSize / 2
place3_3 = WIDTH - (5 + placeWidth), HEIGHT - (5 + placeHeight)
units3_3 = place3_3[0] + placeWidth / 2 - letterSize / 2, place3_3[1] + placeHeight / 2 - letterSize / 2

places = [[place0_0,place0_1,place0_2,place0_3], [place1_0,place1_1,place1_2,place1_3], \
[place2_0,place2_1,place2_2,place2_3], [place3_0,place3_1,place3_2,place3_3]]

buttons = WIDTH / 2 - gameButtonImagesWidth / 2, HEIGHT - (gameButtonImagesHeight + 10)

formSwitchButton = buttons[0] + gameButtonImagesWidth - 62, buttons[1] + 5

one = True

arrowX = None
arrowY = None

font = pygame.font.SysFont('arial', letterSize)


# defs

def menu():
    screen.blit(menuBgImg, (0, 0))
    screen.blit(menuButtonImg, (WIDTH / 2 - mainMenuButtonFourPeopleImagesWidth / 2, HEIGHT / 2 - mainMenuButtonFourPeopleImagesHeight / 2))

def draw():
    screen.blit(warBackgroundImg, (0, 0))

    pygame.draw.rect(screen, BLACK,pygame.Rect(formSwitchButton[0], formSwitchButton[1], formSwitchButtonSize, formSwitchButtonSize))

    text0_0 = font.render(str(gameList[0][0][1]), 1, BLACK)
    text0_1 = font.render(str(gameList[0][1][1]), 1, BLACK)
    text0_2 = font.render(str(gameList[0][2][1]), 1, BLACK)
    text0_3 = font.render(str(gameList[0][3][1]), 1, BLACK)

    text1_0 = font.render(str(gameList[1][0][1]), 1, BLACK)
    text1_1 = font.render(str(gameList[1][1][1]), 1, BLACK)
    text1_2 = font.render(str(gameList[1][2][1]), 1, BLACK)
    text1_3 = font.render(str(gameList[1][3][1]), 1, BLACK)

    text2_0 = font.render(str(gameList[2][0][1]), 1, BLACK)
    text2_1 = font.render(str(gameList[2][1][1]), 1, BLACK)
    text2_2 = font.render(str(gameList[2][2][1]), 1, BLACK)
    text2_3 = font.render(str(gameList[2][3][1]), 1, BLACK)

    text3_0 = font.render(str(gameList[3][0][1]), 1, BLACK)
    text3_1 = font.render(str(gameList[3][1][1]), 1, BLACK)
    text3_2 = font.render(str(gameList[3][2][1]), 1, BLACK)
    text3_3 = font.render(str(gameList[3][3][1]), 1, BLACK)

    # blit units in places texts

    screen.blit(gameList[0][0][0], (place0_0))
    screen.blit(text0_0, (units0_0))
    screen.blit(gameList[0][1][0], (place0_1))
    screen.blit(text0_1, (units0_1))
    screen.blit(gameList[0][2][0], (place0_2))
    screen.blit(text0_2, (units0_2))
    screen.blit(gameList[0][3][0], (place0_3))
    screen.blit(text0_3, (units0_3))

    screen.blit(gameList[1][0][0], (place1_0))
    screen.blit(text1_0, (units1_0))
    screen.blit(gameList[1][1][0], (place1_1))
    screen.blit(text1_1, (units1_1))
    screen.blit(gameList[1][2][0], (place1_2))
    screen.blit(text1_2, (units1_2))
    screen.blit(gameList[1][3][0], (place1_3))
    screen.blit(text1_3, (units1_3))

    screen.blit(gameList[2][0][0], (place2_0))
    screen.blit(text2_0, (units2_0))
    screen.blit(gameList[2][1][0], (place2_1))
    screen.blit(text2_1, (units2_1))
    screen.blit(gameList[2][2][0], (place2_2))
    screen.blit(text2_2, (units2_2))
    screen.blit(gameList[2][3][0], (place2_3))
    screen.blit(text2_3, (units2_3))

    screen.blit(gameList[3][0][0], (place3_0))
    screen.blit(text3_0, (units3_0))
    screen.blit(gameList[3][1][0], (place3_1))
    screen.blit(text3_1, (units3_1))
    screen.blit(gameList[3][2][0], (place3_2))
    screen.blit(text3_2, (units3_2))
    screen.blit(gameList[3][3][0], (place3_3))
    screen.blit(text3_3, (units3_3))

    # screen form switching

    if turnForm == 1:
        screen.blit(preparationImg, (buttons))
    if turnForm == 2:
        screen.blit(attackImg, (buttons))

def preparationForm(turnForm):
    events = pygame.event.get()
    for event in events:
        if event.type == pygame.MOUSEBUTTONDOWN:
            if mouseX >= formSwitchButton[0] and mouseX <= formSwitchButton[0] + formSwitchButtonSize and \
            mouseY >= formSwitchButton[1] and mouseY <= formSwitchButton[1] + formSwitchButtonSize:
                turnForm = 2
    return turnForm

# здесь

def attackForm(turnForm, turn):

    events = pygame.event.get()
    for event in events:
        if event.type == pygame.MOUSEBUTTONDOWN:
            if mouseX >= formSwitchButton[0] and mouseX <= formSwitchButton[0] + formSwitchButtonSize and \
            mouseY >= formSwitchButton[1] and mouseY <= formSwitchButton[1] + formSwitchButtonSize:
                turnForm = 1
        return turnForm, turn

running = True
while running:
    clock.tick(FPS)
    # mouse coords

    mouseX = pygame.mouse.get_pos()[0]
    mouseY = pygame.mouse.get_pos()[1]

    elif screenForm == 2:

        # draw everything

        draw()

        # turn forms
        if turnForm == 1:
            turnForm = preparationForm(turnForm)
        elif turnForm == 2:
            # и здесь
            attackReturns = attackForm(turnForm, turn)
            turnForm = attackReturns[0]
            turn = attackReturns[1]

        one = False

    pygame.display.update()
  • Вопрос задан
  • 40 просмотров
Решения вопроса 1
@gimntut
Потому, что есть лишний отступ перед return
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы