<commit_before>import pygame
from widgets import Button, TextBox, Board
from constants import WATER_ON_THE_OIL, MAILRAYS, CRUNCH, CREDITS, CHESSSOUND_TITLE


class Screen(object):

    def __init__(self, window):
        self.window = window
        self.running = True

    def put_widget(self, widget, center):
        x, y = center
        x = x - widget.width / 2
        y = y - widget.height / 2
        rect = (x, y, widget.width, widget.height)
        if self.window.mouse_over(rect):
            self.surface.blit(widget.mouse_over, rect)
            self.window.focus = widget
        else:
            self.surface.blit(widget.normal, rect)
            if self.window.focus is widget:
                self.window.focus = None


class Menu(Screen):

    FONT = pygame.font.Font(WATER_ON_THE_OIL, 50)

    def __init__(self, window, background_path, buttons):
        super(Menu, self).__init__(window)
        self.window = window
        self.background = pygame.image.load(background_path)
        self.background = pygame.transform.scale(self.background, window.size)
        self.buttons = buttons
        self.surface = self.background.copy()

    @property
    def frame(self):
        self.surface = self.background.copy()
        for i, button in enumerate(self.buttons):
            x, y = self.window.center
            y = y + 50 * i + 30
            self.put_widget(button, (x, y))
        return self.surface


class MainMenu(Menu):

    def __init__(self, window):
        buttons = [
            Button(_("new game"), self.new_game),
            Button(_("options"), self.options),
            Button(_("credits"), self.credits),
            Button(_("exit"), self.exit),
        ]
        super(MainMenu, self).__init__(window, CHESSSOUND_TITLE, buttons)
        pygame.mixer.music.load(CRUNCH)
        pygame.mixer.music.play()

    def new_game(self):
        lobby = NormalGameLobby(self.window)
        self.window.display(lobby)

    def options(self):
        pass

    def credits(self):
        credits = Credits(self.window)
        self.window.display(credits)

    def exit(self):
        self.window.running = False


class NormalGameLobby(Screen):

    def __init__(self, window):
        super(NormalGameLobby, self).__init__(window)
        self.surface = pygame.Surface(window.size)
        self.back_button = Button(_("back"), self.back)
        self.player_black = TextBox("Player 1")
        self.player_white = TextBox("Player 2")
        self.board = Board(200, 200)
        self.start_button = Button(_("start"), self.start)

    @property
    def frame(self):
        self.surface.fill((100, 100, 255))
        self.put_widget(self.back_button, (120, self.window.center[1]))
        self.put_widget(self.player_black, (self.window.center[0], 25))
        self.put_widget(self.player_white, (self.window.center[0], 285))
        self.put_widget(self.board, (self.window.center[0], 155))
        self.put_widget(self.start_button, (self.window.width - 120, self.window.center[1]))
        return self.surface

    def back(self):
        self.running = False

    def start(self):
        normal_game = NormalGame(self.window)
        self.window.display(normal_game)


class NormalGame(Screen):

    def __init__(self, window):
        super(NormalGame, self).__init__(window)
        self.window = window
        self.surface = pygame.Surface(window.size)
        self.board = Board(window.height - 20, window.height - 20)
        self.board.start(self)
        self.board.x = self.window.width - self.window.height / 2 - 10
        self.board.y = self.window.center[1]

    @property
    def frame(self):
        self.surface.fill((200, 255, 255))
        self.put_widget(self.board, (self.board.x, self.board.y))
        return self.surface


class Credits(Screen):

    FONT = pygame.font.Font(MAILRAYS, 20)
<commit_msg>stop music in start of the game<commit_after>import pygame
from widgets import Button, TextBox, Board
from constants import WATER_ON_THE_OIL, MAILRAYS, CRUNCH, CREDITS, CHESSSOUND_TITLE


class Screen(object):

    def __init__(self, window):
        self.window = window
        self.running = True

    def put_widget(self, widget, center):
        x, y = center
        x = x - widget.width / 2
        y = y - widget.height / 2
        rect = (x, y, widget.width, widget.height)
        if self.window.mouse_over(rect):
            self.surface.blit(widget.mouse_over, rect)
            self.window.focus = widget
        else:
            self.surface.blit(widget.normal, rect)
            if self.window.focus is widget:
                self.window.focus = None


class Menu(Screen):

    FONT = pygame.font.Font(WATER_ON_THE_OIL, 50)

    def __init__(self, window, background_path, buttons):
        super(Menu, self).__init__(window)
        self.window = window
        self.background = pygame.image.load(background_path)
        self.background = pygame.transform.scale(self.background, window.size)
        self.buttons = buttons
        self.surface = self.background.copy()

    @property
    def frame(self):
        self.surface = self.background.copy()
        for i, button in enumerate(self.buttons):
            x, y = self.window.center
            y = y + 50 * i + 30
            self.put_widget(button, (x, y))
        return self.surface


class MainMenu(Menu):

    def __init__(self, window):
        buttons = [
            Button(_("new game"), self.new_game),
            Button(_("options"), self.options),
            Button(_("credits"), self.credits),
            Button(_("exit"), self.exit),
        ]
        super(MainMenu, self).__init__(window, CHESSSOUND_TITLE, buttons)
        pygame.mixer.music.load(CRUNCH)
        pygame.mixer.music.play()

    def new_game(self):
        lobby = NormalGameLobby(self.window)
        self.window.display(lobby)

    def options(self):
        pass

    def credits(self):
        credits = Credits(self.window)
        self.window.display(credits)

    def exit(self):
        self.window.running = False


class NormalGameLobby(Screen):

    def __init__(self, window):
        super(NormalGameLobby, self).__init__(window)
        self.surface = pygame.Surface(window.size)
        self.back_button = Button(_("back"), self.back)
        self.player_black = TextBox("Player 1")
        self.player_white = TextBox("Player 2")
        self.board = Board(200, 200)
        self.start_button = Button(_("start"), self.start)

    @property
    def frame(self):
        self.surface.fill((100, 100, 255))
        self.put_widget(self.back_button, (120, self.window.center[1]))
        self.put_widget(self.player_black, (self.window.center[0], 25))
        self.put_widget(self.player_white, (self.window.center[0], 285))
        self.put_widget(self.board, (self.window.center[0], 155))
        self.put_widget(self.start_button, (self.window.width - 120, self.window.center[1]))
        return self.surface

    def back(self):
        self.running = False

    def start(self):
        pygame.mixer.music.stop()
        normal_game = NormalGame(self.window)
        self.window.display(normal_game)


class NormalGame(Screen):

    def __init__(self, window):
        super(NormalGame, self).__init__(window)
        self.window = window
        self.surface = pygame.Surface(window.size)
        self.board = Board(window.height - 20, window.height - 20)
        self.board.start(self)
        self.board.x = self.window.width - self.window.height / 2 - 10
        self.board.y = self.window.center[1]

    @property
    def frame(self):
        self.surface.fill((200, 255, 255))
        self.put_widget(self.board, (self.board.x, self.board.y))
        return self.surface


class Credits(Screen):

    FONT = pygame.font.Font(MAILRAYS, 20)

{'fraction_non_alphanumeric': 0.12246729930751475, 'fraction_numerical': 0.01615798922800718, 'mean_word_length': 2.416119141480508, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5814013', 'n_tokens_mistral': 2549, 'n_tokens_neox': 2378, 'n_words': 489}