Exemplo n.º 1
0
def request(title, inputtext):
    """
    Función que abre una ventana para pedir un nombre de usuario
    :param title: Título de la ventana
    :param inputtext: Mensaje del prompt
    :return: String del nombre
    """
    # Se crea la ventana
    os.environ['SDL_VIDEO_CENTERED'] = '1'
    pygame.display.set_mode(SCREEN_SIZE, pygame.NOFRAME)  # @UnusedVariable
    pygame.display.set_caption(title)
    pygame.display.set_icon(pygame.image.load(getIcons('icon')))
    screen = pygame.display.get_surface()
    nombre = Input(10, inputtext)

    # Reloj del juego
    clock = pygame.time.Clock()

    # Se crea el titulo de la ventana
    window_title_fontsize = 30
    window_title = pygame.font.Font(getFonts('menu'), window_title_fontsize)
    window_title_font = window_title.render(title, 1, COLOR_WHITE)
    window_title_width = window_title_font.get_size()[0]
    window_title_pos = [(0, 0), (SCREEN_SIZE[0], 0),
                        (SCREEN_SIZE[0], int(window_title_fontsize / 2)),
                        (window_title_width + 15,
                         int(window_title_fontsize / 2)),
                        (window_title_width + 5, window_title_fontsize + 7),
                        (0, window_title_fontsize + 7)]

    # Se lanza el programa
    while True:
        clock.tick(60)  # se definen los fps
        time = float(
            clock.get_time()) / 1000.0  # tiempo que tomo el frame en generarse
        screen.fill(COLOR_BLACK)  # se limpia la pantalla

        # Se dibuja el rectangulo rojo del titulo
        pygame.gfxdraw.filled_polygon(screen, window_title_pos, TITLE_BG_COLOR)
        screen.blit(window_title_font, (5, 0))

        # Eventos del programa principal
        events = pygame.event.get()  # se definen los eventos
        for event in events:
            if event.type == QUIT:
                return NO_VALID_NAME
            elif event.type == KEYDOWN:
                if event.key == K_ESCAPE:
                    return NO_VALID_NAME

                    # Se recoge el resultado
        state = nombre.update(events)
        if state != NULLSTATE and validate(state):
            return state

        # Se dibuja el campo en pantalla
        nombre.draw(screen)

        # Se refresca la ventana
        pygame.display.flip()
Exemplo n.º 2
0
def request(title, inputtext):
    """
    Función que abre una ventana para pedir un nombre de usuario
    :param title: Título de la ventana
    :param inputtext: Mensaje del prompt
    :return: String del nombre
    """
    # Se crea la ventana
    os.environ['SDL_VIDEO_CENTERED'] = '1'
    display = pygame.display.set_mode(SCREEN_SIZE, pygame.NOFRAME)  # @UnusedVariable
    pygame.display.set_caption(title)
    pygame.display.set_icon(pygame.image.load(getIcons("icon")))
    screen = pygame.display.get_surface()
    nombre = Input(10, inputtext)

    # Reloj del juego
    clock = pygame.time.Clock()

    # Se crea el titulo de la ventana
    window_title_fontsize = 30
    window_title = pygame.font.Font(getFonts("menu"), window_title_fontsize)
    window_title_font = window_title.render(title, 1, COLOR_WHITE)
    window_title_width = window_title_font.get_size()[0]
    window_title_pos = [(0, 0), (SCREEN_SIZE[0], 0), (SCREEN_SIZE[0], int(window_title_fontsize / 2)),
                        (window_title_width + 15, int(window_title_fontsize / 2)), \
                        (window_title_width + 5, window_title_fontsize + 7), (0, window_title_fontsize + 7)]

    # Se lanza el programa
    while True:
        clock.tick(60)  # se definen los fps
        time = float(clock.get_time()) / 1000.0  # tiempo que tomo el frame en generarse @UnusedVariable
        screen.fill(COLOR_BLACK)  # se limpia la pantalla

        # Se dibuja el rectangulo rojo del titulo
        pygame.gfxdraw.filled_polygon(screen, window_title_pos, TITLE_BG_COLOR)
        screen.blit(window_title_font, (5, 0))

        # Eventos del programa principal
        events = pygame.event.get()  # se definen los eventos
        for event in events:
            if event.type == QUIT:
                return NO_VALID_NAME
            elif event.type == KEYDOWN:
                if event.key == K_ESCAPE: return NO_VALID_NAME

                # Se recoge el resultado
        state = nombre.update(events)
        if state != NULLSTATE and validate(state): return state

        # Se dibuja el campo en pantalla
        nombre.draw(screen)

        # Se refresca la ventana
        pygame.display.flip()
Exemplo n.º 3
0
def main():
    """
    Prepara las ventanas, define modelos, controlador y vista y corre el programa.
    :return: void
    """

    # Se obtiene el checksum del juego
    checksum = [
        path_checksum('lib', VERBOSE),
        '8e1fd1c03d2bfe89d7dbdab8b0c4c69a'.upper(),
        path_checksum('bin', VERBOSE)
    ]

    # Se cargan las configuraciones
    control_config = Configloader(DIR_CONFIG + 'control.ini', verbose=VERBOSE)
    game_config = Configloader(DIR_CONFIG + 'game.ini', verbose=VERBOSE)
    map_config = Configloader(DIR_CONFIG + 'map.ini', verbose=VERBOSE)
    score_config = Configloader(DIR_CONFIG + 'scoreboard.ini', verbose=VERBOSE)
    user_config = Configloader(DIR_CONFIG + 'user.ini', verbose=VERBOSE)
    view_config = Configloader(DIR_CONFIG + 'view.ini', verbose=VERBOSE)
    window_config = Configloader(DIR_CONFIG + 'window.ini', verbose=VERBOSE)
    world_config = Configloader(DIR_CONFIG + 'world.ini', verbose=VERBOSE)

    # Se carga el idioma
    lang = langs.Langloader(game_config.getValue('LANG'))

    # Se carga la información de la pantalla del cliente
    display_info = pygame.display.Info()

    # Se comprueba que el nombre de jugador no sea Player, si no es valido se pide uno nuevo
    if not username.validate(user_config.getValue('NAME')):
        new_name = username.request(lang.get(111), lang.get(112))
        if new_name is not username.NO_VALID_NAME:
            user_config.setParameter('NAME', new_name)
            user_config.export()
        else:
            utils.destroy_process()

    # Creación de ventana
    window = Window(window_config, lang.get(10),
                    pygame.image.load(getIcons('icon')), display_info)
    clock = pygame.time.Clock()  # Reloj
    fps = int(game_config.getValue('FPS'))  # FPS a dibujar

    # Se crea el mundo
    world = World(world_config,
                  map_config,
                  window,
                  checksum,
                  score_config,
                  user_config,
                  lang,
                  game_config,
                  verbose=VERBOSE)
    # world.load_map(1)

    # Se crean los menús de inicio y pause
    menus = Createuimenu(lang, window, world, game_config, user_config,
                         view_config, window_config, world_config, map_config)

    # Se crea la vista
    vista = View(window, clock, world, lang, view_config, menus)
    menus.addView(vista)

    # Se crea el controlador
    control = Controller(world,
                         clock,
                         lang,
                         control_config,
                         window,
                         menus,
                         verbose=VERBOSE)
    menus.addController(control)
    vista.add_controller(control)

    # Se lanza el mainloop
    while True:
        clock.tick(fps)
        vista.draw(control.event_loop())
Exemplo n.º 4
0
def main():
    """
    Prepara las ventanas, define modelos, controlador y vista y corre el programa
    :return: void
    """

    # Se obtiene el checksum del juego
    checksum = [path_checksum('lib', VERBOSE),
                md5file('main.py', VERBOSE).upper(),
                path_checksum('bin', VERBOSE)]

    # Se cargan las configuraciones
    control_config = configLoader(DIR_CONFIG + "control.ini", verbose=VERBOSE)
    game_config = configLoader(DIR_CONFIG + "game.ini", verbose=VERBOSE)
    map_config = configLoader(DIR_CONFIG + "map.ini", verbose=VERBOSE)
    score_config = configLoader(DIR_CONFIG + "scoreboard.ini", verbose=VERBOSE)
    user_config = configLoader(DIR_CONFIG + "user.ini", verbose=VERBOSE)
    view_config = configLoader(DIR_CONFIG + "view.ini", verbose=VERBOSE)
    window_config = configLoader(DIR_CONFIG + "window.ini", verbose=VERBOSE)
    world_config = configLoader(DIR_CONFIG + "world.ini", verbose=VERBOSE)

    # Se carga el idioma
    lang = langs.langLoader(game_config.getValue("LANG"))  # @UndefinedVariable

    # Se carga la información de la pantalla del cliente
    display_info = pygame.display.Info()  # @UndefinedVariable

    # Se comprueba que el nombre de jugador no sea Player, si no es valido se pide uno nuevo
    if not username.validate(
            user_config.getValue("NAME")):  # @UndefinedVariable
        new_name = username.request(lang.get(111),
                                    lang.get(112))  # @UndefinedVariable
        if new_name is not username.NO_VALID_NAME:  # @UndefinedVariable
            user_config.setParameter("NAME", new_name)
            user_config.export()
        else:
            utils.destroyProcess()  # @UndefinedVariable

    # Creación de ventana
    window = Window(window_config, lang.get(10),
                    pygame.image.load(getIcons("icon")),
                    display_info)  # @UndefinedVariable
    clock = pygame.time.Clock()  # reloj @UndefinedVariable
    fps = int(game_config.getValue("FPS"))  # fps a dibujar

    # Se crea el mundo
    world = World(world_config, map_config, window, checksum, score_config,
                  user_config, lang, game_config, verbose=VERBOSE)
    # TEST: world.loadMap(1)

    # Se crean los menús de inicio y pause
    menus = Createuimenu(lang, window, world, game_config, user_config,
                         view_config, window_config, world_config, map_config)

    # Se crea la vista
    vista = View(window, clock, world, lang, view_config, menus)
    menus.addView(vista)

    # Se crea el controlador
    control = Controller(world, clock, lang, control_config, window, menus,
                         verbose=VERBOSE)
    menus.addController(control)
    vista.add_controller(control)

    # Se lanza el mainloop
    while True:
        clock.tick(fps)
        vista.draw(control.event_loop())