<filename>src/game_components/game.py
__author__ = "<NAME>"
__copyright__ = "Copyright 2021, <NAME>"
__version__ = "0.0.1"
__maintainer__ = "<NAME>"
__email__ = "<EMAIL> "
__status__ = "Production"

"""
    This is the class where all the game loop is controlled, and where all the action are
    controlled. And also all the cubes generated by the Cube class are controlled by here.
"""

import pygame
from src.support.font import Game_fonts as fonts
from src.support.colors import Game_color as color
from src.support.auxiliar_functions import write_to_file, get_screen_text
from src.support.buttons import horizontalButtonDisplay
from src.support.input_boxes import draw_input_boxes, verify_input

class Game_loop:
    
    game_events: pygame.event        # Hold the current games events
    mouse_position: tuple            # To store and refresh the mouse position
    
    def __init__(self, game_obj: object) -> None:
        self.game_obj = game_obj
        self.quit_confirmation_buttons = {"win_game": "Win", "lose_game": "Lose"}
        self.input_boxes = {"name": ["", False]}
        self.button_clicked = ""
        self.box_dim = {
            "x":120,
            "y":40
        }
        self.button_start_position = {
            "x":int((self.game_obj.screen_size[0] / 2) - (self.box_dim["x"] * 2 + 20) / 2),
            "y":int((self.game_obj.screen_size[1] / 2) - (self.box_dim["y"] * 2) / 2) + 150
        }

    def input_boxes_control(self) -> None:
        """
            Method to draw the imput box on the screen.
        """
        self.input_boxes = draw_input_boxes(
            screen = self.game_obj.screen, 
            input_boxes = self.input_boxes,
            input_limit = 15, 
            events = self.game_obj.game_events,
            mouse_pos = self.mouse_position,
            y_start = 300,
            x_start = int(self.game_obj.screen_size[0]/2 - 175),
            boxes_dim = (350,40),
            space_between_box = 70
        )
    
    def page_tittles(self) -> None:
        """
            To show the header tittles.
        """
        font_size = pygame.font.Font.size(fonts.montserrat_size_40.value, get_screen_text("game_tittle"))
        line = fonts.montserrat_size_40.value.render(get_screen_text("game_tittle"), True, color.green.value)
        self.game_obj.screen.blit(line, (self.game_obj.screen_size[0]/2-(font_size[0]/2), 160))

        font_size = pygame.font.Font.size(fonts.montserrat_size_16.value, "for more info read de README.md file")
        line = fonts.montserrat_size_16.value.render("for more info read de README.md file", True, color.white.value)
        self.game_obj.screen.blit(line, (self.game_obj.screen_size[0]/2-(font_size[0]/2), 230))

    def game_over(self) -> None:
        """
            Method that handle the game over event before passing to the game over page.
        """
        game_winned, name = False, self.input_boxes["name"][0]
        if self.button_clicked == "Win":
            game_winned = True

        write_to_file("./data/end_game_values.txt", "w", f"{name} {int(game_winned)}")
        self.game_obj.current_link = "game_over"

    def simple_game_introduction(self) -> None:
        """
            Method to draw vertical buttons on the screen.
        """
        self.button_clicked = horizontalButtonDisplay(
            screen = self.game_obj.screen,
            buttons = self.quit_confirmation_buttons.values(),
            start_position = {
                "x": self.button_start_position["x"],
                "y": self.button_start_position["y"]
            },
            box_dim = self.box_dim,
            mouse_pos = self.mouse_position,
            font = fonts.montserrat_size_16.value,
            button_clicked = self.button_clicked
        )

    def run_link(self) -> None:
        """
            Main loop of this game page.
        """
        change_page_by_action = change_page_by_event = False

        while True:
            self.game_obj.screen_fill_bg()

            self.mouse_position = pygame.mouse.get_pos()

            # self.game_over(self.ttt.verificaGanhador())
            self.simple_game_introduction()
            self.page_tittles()

            change_page_by_event = self.game_obj.game_events_handler()

            self.input_boxes_control()

            if (self.button_clicked != "" and verify_input(self.input_boxes)):
                for value in self.quit_confirmation_buttons.values():
                    if(self.button_clicked == value):
                        self.game_over()
                        change_page_by_action = True
                        break

            self.button_clicked = ""

            if change_page_by_action or change_page_by_event:
                break

            pygame.display.update()

<filename>src/game_components/game.py
__author__ = "<NAME>"
__copyright__ = "Copyright 2021, <NAME>"
__version__ = "0.0.1"
__maintainer__ = "<NAME>"
__email__ = "<EMAIL> "
__status__ = "Production"

"""
    This is the class where all the game loop is controlled, and where all the action are
    controlled. And also all the cubes generated by the Cube class are controlled by here.
"""

import pygame
from src.support.font import Game_fonts as fonts
from src.support.colors import Game_color as color
from src.support.auxiliar_functions import write_to_file, get_screen_text
from src.support.buttons import horizontalButtonDisplay
from src.support.input_boxes import draw_input_boxes, verify_input

class Game_loop:
    
    game_events: pygame.event        # Hold the current games events
    mouse_position: tuple            # To store and refresh the mouse position
    
    def __init__(self, game_obj: object) -> None:
        self.game_obj = game_obj
        self.quit_confirmation_buttons = {"win_game": "Win", "lose_game": "Lose"}
        self.input_boxes = {"name": ["", False]}
        self.button_clicked = ""
        self.box_dim = {
            "x":120,
            "y":40
        }
        self.button_start_position = {
            "x":int((self.game_obj.screen_size[0] / 2) - (self.box_dim["x"] * 2 + 20) / 2),
            "y":int((self.game_obj.screen_size[1] / 2) - (self.box_dim["y"] * 2) / 2) + 150
        }

    def input_boxes_control(self) -> None:
        """
            Method to draw the imput box on the screen.
        """
        self.input_boxes = draw_input_boxes(
            screen = self.game_obj.screen, 
            input_boxes = self.input_boxes,
            input_limit = 15, 
            events = self.game_obj.game_events,
            mouse_pos = self.mouse_position,
            y_start = 300,
            x_start = int(self.game_obj.screen_size[0]/2 - 175),
            boxes_dim = (350,40),
            space_between_box = 70
        )
    
    def page_tittles(self) -> None:
        """
            To show the header tittles.
        """
        font_size = pygame.font.Font.size(fonts.montserrat_size_40.value, get_screen_text("game_tittle"))
        line = fonts.montserrat_size_40.value.render(get_screen_text("game_tittle"), True, color.green.value)
        self.game_obj.screen.blit(line, (self.game_obj.screen_size[0]/2-(font_size[0]/2), 160))

        font_size = pygame.font.Font.size(fonts.montserrat_size_16.value, "for more info read de README.md file")
        line = fonts.montserrat_size_16.value.render("for more info read de README.md file", True, color.white.value)
        self.game_obj.screen.blit(line, (self.game_obj.screen_size[0]/2-(font_size[0]/2), 230))

    def game_over(self) -> None:
        """
            Method that handle the game over event before passing to the game over page.
        """
        game_winned, name = False, self.input_boxes["name"][0]
        if self.button_clicked == "Win":
            game_winned = True

        write_to_file("./data/end_game_values.txt", "w", f"{name} {int(game_winned)}")
        self.game_obj.current_link = "game_over"

    def simple_game_introduction(self) -> None:
        """
            Method to draw vertical buttons on the screen.
        """
        self.button_clicked = horizontalButtonDisplay(
            screen = self.game_obj.screen,
            buttons = self.quit_confirmation_buttons.values(),
            start_position = {
                "x": self.button_start_position["x"],
                "y": self.button_start_position["y"]
            },
            box_dim = self.box_dim,
            mouse_pos = self.mouse_position,
            font = fonts.montserrat_size_16.value,
            button_clicked = self.button_clicked
        )

    def run_link(self) -> None:
        """
            Main loop of this game page.
        """
        change_page_by_action = change_page_by_event = False

        while True:
            self.game_obj.screen_fill_bg()

            self.mouse_position = pygame.mouse.get_pos()

            # self.game_over(self.ttt.verificaGanhador())
            self.simple_game_introduction()
            self.page_tittles()

            change_page_by_event = self.game_obj.game_events_handler()

            self.input_boxes_control()

            if (self.button_clicked != "" and verify_input(self.input_boxes)):
                for value in self.quit_confirmation_buttons.values():
                    if(self.button_clicked == value):
                        self.game_over()
                        change_page_by_action = True
                        break

            self.button_clicked = ""

            if change_page_by_action or change_page_by_event:
                break

            pygame.display.update()

This is the class where all the game loop is controlled, and where all the action are     controlled. And also all the cubes generated by the Cube class are controlled by here. # Hold the current games events # To store and refresh the mouse position Method to draw the imput box on the screen. To show the header tittles. Method that handle the game over event before passing to the game over page. Method to draw vertical buttons on the screen. Main loop of this game page. # self.game_over(self.ttt.verificaGanhador())