NameError: name 'self' is not defined не знаю в чем причина первый раз сталкиваюсь с такой ошибкой. Помогите

import pygame
import sys
import random
import time

class Game():
def __unit__(self):
    # Размеры
    self.screen_width = (720)
    self.screen_height = (460)

    # Цвета

    self.red = pygame.Color(255, 0, 0)
    self.green = pygame.Color(0, 255, 0)
    self.white = pygame.Color(255, 255, 255)
    self.dark = pygame.Color(0, 0, 0)         
    self.brown = pygame.Color(165, 42, 42)

    # Счетчик FPS
    self.fps_controller = pygame.time.clock()

def init__and_check_for_errors():

    check_errors = pygame.init()

    if check_errors[1] > 0:
        sys.exit()

    else:
        print("Ок, да...")

def set_surface_and_title(self):
    self.play.surface = pygame.display.setmode((
        self.screen_height, screen_height))
    pygame.display.set_caption("Моя сестра")

def evet_loop():
        #Добавляем ивент
    for event in pygame.get():
        #Нажатие на клавиши клавы
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_RIGHT or event.key == ord("d"):
                change_to = "RIGHT"
            elif event.key == pygame.K_LEFT or event.key == ord("a"):
                change_to = "LEFT"
            elif event.key == pygame.K_UP or event.key == ord("w"):
                change_to = "UP"
            elif event.key == pygame.K_DOWN or event.key == ord("s"):
                change_to = "DOWN"

            #Выход из игры(ESP)

            elif event.key == pygame.K_ESCAPE:
                pygame.quit()
                sys.exit()
    return change_to

def refresh_screen(self):
    pygame.display.flip()
    game.fps_controller.tick(23)

def show_score(self, choice=1):
    #Отображение Очков...
    s_font = pygame.font.SysFont('monaco', 24)
    s_surf = s_font.render(
        'Очки: {0}'.format(self.score), True, self.red)

    if choice == 1:
        s_rect.midtop(80, 10)
    self.play_surface.bilt(s_surf, s_rect)

def game_over(self):
    go_font = pygame.font.SysFont('monaco', 72)
    go_surf = go_font.render('Хах, Проебался', True, self.red)
    go_rect = go_surf.get_rect()
    go_rect.midtop(360,15)
    self.play_surface.bilt(go_surf, go_rect)
    self.show_score(0)
    pygame.display.flip()
    time.sleep(3)
    pygame.quit()
    sys.exit()

class Snake(self, snake_color):
#Сама змейка, а точнее голова, тело будет дальше.
self.snake_head_pos = (100, 50)
#Само тело + голова
self.snake_body = [[100, 50], [90, 50], [80, 50]]
self.snake_color = snake_color
#Изначально направление змеи
self.direction = "RIGHT"
#Куда будет менятся направления змеи, при нажатии на клавиши клавы
self.change_to = self.direction

def validate_direction_and_change(self):
    if any((self.change_to == "RIGHT" and not self.direction == "LEFT",
            self.change_to == "LEFT" and not self.direction == "RIGHT",
            self.change_to == "UP" and not self.direction == "DOWN",
            self.change_to == "DOWN" and not self.direction == "UP")):
        self.change_to = self.direction 

def head_snake_pos(self):
    if self.direction == "RIGHT":
        self.snake_head_pos[0]+= 10
    elif self.direction == "LEFT":
        self.snake_head_pos[0]-= 10
    elif self.direction == "UP":
        self.snake_head_pos[1]-= 10
    elif self.direction == "DOWN":
        self.snake_head_pos[1]+= 10

def snake_body_mechanism(self):
    self.insert(0, list(self.snake_head_pos))

    if (self.snake_head_pos[0] == self.food_pos[0] and
            self.snake_head_pos[1] == self.food_pos[1]):

        food_pos = [random.randrange(1, screen_width/10)*10,
                    random.randrange(1, screen_height/10)*10]
        score += 1
    else:
        self.snake_body.pop()
        return score, food_pos

def draw_snake(self, play_surface, surface_color):
    play_surface.fill(surface_color)
    for pos in self.snake_body:
        pygame.draw.rect(
            play_surface, self.snake_color, pygame.Rect(
                pos[0], pos[1], 10, 10))

def check_for_boundaries(self, game_over, screen_width, screen_height):
    if any((
        self.snake_head_pos[0] > screen_width -10
        or self.head_snake_pos[0] < 0,
        self.snake_head_pos[1] > screen_height -10
        or self.head_snake_pos[1] < 0
            )):
        game_over()
    for block in self.snake_body[1:]:
        if(block[0] == self.snake_head_pos[0]
            and block[1] == self.snake_head_pos[1]):
            game_over()

class Food():
def __init__(self, food_color, screen_height, screen_width):
    self.food_color = food_color
    self.food_size_y = 10
    self.food_size_x = 10
    self.food_pos = [random.randrange(1, screen_height/10)*10,
                     random.randrange(1, screen_width/10)*10]

def draw_food(self, play_surface):
    pygame.draw.rect(
    play_surface, self.food_color, pygame.Rect(
        self.food_pos[0], self.food_pos[1],
        self.food_size_y, self.food_size_x))


game = Game()
snake = Snake(game.dark)
Food = Food(game.red, game_screen_widht, game_screen_height)

game.init__and_check_for_errors()
game.set_surface_and_title()

while True:
snake.change_to = game.event_loop(snake.change_to)

snake.validate_direction_and_change()
snake.change_head_position()
game.score, food.food_pos = snake.snake_body_mechanism(
    game.score, food.food_pos, game.screen_width, game.screen_height)
snake.draw_snake(game.play_surface, game.white)

food.draw_food(game.play_surface)

snake.check_for_boundaries(
    game.game_over, game.screen_width, game.screen_height)

game.show_score()
game.refresh_screen()

Ответы (0 шт):