Example #1
0
def show_deseja_sair(stdscr):
    curses.curs_set(0)

    curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_GREEN)

    textPrint.print_title(stdscr)
    textPrint.print_center(stdscr, 'Tem certeza que deseja sair?')
    botao = ['Sim', 'Não']
    selected_row_idx = 0
    stdscr.refresh()
    menu.horizontal_menu(stdscr, selected_row_idx, botao)

    while True:
        key = stdscr.getch()
        stdscr.refresh()
        if actions.keyboard(key) == 'left' and selected_row_idx > 0:
            selected_row_idx -= 1

        elif actions.keyboard(key) == 'right' and selected_row_idx < 1:
            selected_row_idx += 1

        elif actions.keyboard(key) == 'enter':
            if selected_row_idx == 0:  #SIM
                return True

            elif selected_row_idx == 1:  #NAO
                return False

        stdscr.clear()
        textPrint.print_title(stdscr)
        textPrint.print_center(stdscr, 'Tem certeza que deseja sair?')
        menu.horizontal_menu(stdscr, selected_row_idx, botao)
        stdscr.refresh()
Example #2
0
def show_erase_rules_screen(stdscr, current_row_idx):
    continuar_voltar_menu = ('Continuar', 'Voltar')

    stdscr.clear()

    curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_GREEN)

    stdscr.attron(curses.color_pair(1))

    textPrint.print_title(stdscr)

    linha1 = "Ok! Antes de começar a excluir uma pergunta, leia as regras atentamente"
    linha2 = "Regras: "

    linha3 = "1 - Ao excluir uma pergunta, voce deve informar o numero dela"
    linha4 = "2 - Em seguida, voce ira informar se deseja realmente exclui-la"

    regras_excluir = [linha1, linha2, linha3, linha4]

    #Imprime as regras no centro da tela
    textPrint.print_multi_lines(stdscr, regras_excluir, 4)

    #Menu de continuar / voltar
    menu.horizontal_menu(stdscr, current_row_idx, continuar_voltar_menu)

    stdscr.refresh()
Example #3
0
def show_questions_rules_screen(stdscr, current_row_idx):
    continuar_voltar_menu = ('Continuar', 'Voltar')

    stdscr.clear()

    curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_GREEN)

    stdscr.attron(curses.color_pair(1))

    textPrint.print_title(stdscr)

    linha1 = "Ok! Antes de comecar a adicionar/alterar uma pergunta, leia as regras atentamente!"
    linha2 = "Regras: "

    linha3 = "1 - Ao editar uma pergunta, voce deve informar o numero dela"
    linha4 = "2 - Em seguida, voce ira informar a nova pergunta"
    linha5 = "3 - Apos isso, voce devera informar 4 possiveis respostas"
    linha6 = "4 - Das respostas, somente 1 podera ser a resposta correta"
    linha7 = "5 - Caso voce informe mais de 1 resposta correta, o programa ira recusar"

    regras_para_adicionar = [
        linha1, linha2, linha3, linha4, linha5, linha6, linha7
    ]

    # Imprime as regras no centro da tela
    textPrint.print_multi_lines(stdscr, regras_para_adicionar, 7)

    # Menu de continuar / voltar
    menu.horizontal_menu(stdscr, current_row_idx, continuar_voltar_menu)

    stdscr.refresh()
Example #4
0
def show_end_screen(stdscr, pontuacao, personal_record, global_record):
    curses.curs_set(0)
    stdscr.clear()

    curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
    curses.init_pair(1, curses.COLOR_BLACK, curses.COLOR_GREEN)

    textPrint.print_title(stdscr)
    texto_pontos = "Pontuacao: " + str(pontuacao)

    texto_final = [texto_pontos]

    if global_record != None:
        if global_record == 'First':
            text_global = 1

        elif global_record == 'Second':
            text_global = 2

        elif global_record == 'Third':
            text_global = 3

        elif global_record == 'Fourth':
            text_global = 4

        else:
            text_global = 5

        texto_global_record = "Parabens, voce obteu a " + str(
            text_global) + "ª posicao no scoreboard!"
        texto_final.append(texto_global_record)

    if global_record != "First":
        texto_tentativa = "Que tal tentar mais uma vez? Talvez voce consiga quebrar o recorde atual!"
        texto_final.append(texto_tentativa)

    if personal_record == True:
        texto_recorde_pessoal = "Novo recorde pessoal! Parabens!"

        texto_final.append(texto_recorde_pessoal)

    textPrint.print_multi_lines(stdscr, texto_final, len(texto_final))

    botao = ['Continuar']

    menu.std_btn(stdscr, 0, botao)

    while True:
        key = stdscr.getch()

        if actions.keyboard(key) == 'enter':
            break
Example #5
0
def show_pergunta_apagada(stdscr):
    curses.curs_set(0)

    curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_GREEN)
    textPrint.print_title(stdscr)
    textPrint.print_center(stdscr, 'Pergunta Apagada!')
    botao = ["Continuar"]
    menu.std_btn(stdscr, 0, botao)
    stdscr.refresh()
    key = stdscr.getch()
    while True:
        if actions.keyboard(key) == 'enter':
            break
Example #6
0
def block_screen(stdscr):
    curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
    
    stdscr.attron(curses.color_pair(1))

    for tempo in range(60):
        stdscr.clear()
        
        textPrint.print_title(stdscr)

        tempo_faltando = "Tempo faltando: " + str(60 - tempo) + " segundos"
        
        textPrint.print_center(stdscr,tempo_faltando)

        stdscr.refresh()

        time.sleep(1)
Example #7
0
def show_scoreboard(stdscr):
    curses.curs_set(0)

    curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_GREEN)

    menu_scoreboard = ["Voltar"]

    # Coloca a cor atual como sendo o primeiro par
    stdscr.attron(curses.color_pair(1))

    # Altura e Largura da Tela
    altura_tela, largura_tela = stdscr.getmaxyx()

    textPrint.print_title(stdscr)

    textPrint.print_center(stdscr, "Carregando...")
    stdscr.refresh()

    textPrint.print_title(stdscr)

    textPrint.erase_center(stdscr, "Carregando...")

    scoreboard.print_scoreboard(stdscr)

    menu.std_btn(stdscr, 0, menu_scoreboard)

    textPrint.print_title(stdscr)

    stdscr.refresh()

    while True:
        key = stdscr.getch()
        if actions.keyboard(key) == 'enter':
            break
Example #8
0
def show_editar_perguntas_menu(stdscr, current_user_data, current_user):
    # Menu com as opcoes para o jogo 
    menu_editar_perguntas = ('Apagar Pergunta', 'Alterar Pergunta', 'Voltar')

    # Esconde o cursor
    curses.curs_set(0)

    # Opcao atual do menu
    current_row_idx = 0

    # Esquemas de cores
    curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_GREEN)

    # Mensagem de carregamento
    textPrint.print_center(stdscr, "Carregando...")
    stdscr.refresh()

    # Pega os dados do usuario que esta logado
    current_user_data = getData.get_user_data(current_user)

    current_user_name = current_user_data["Name"] 
    current_user_high_score = current_user_data["Highscore"]

    data_list = [current_user_name, current_user_high_score]

    # Imprime o menu do Jogo
    menu.print_menu(stdscr, current_row_idx, menu_editar_perguntas)

    # Imprime o usuario atual
    textPrint.print_user_data(stdscr, data_list)
    
    # Imprime o titulo do jogo
    textPrint.print_title(stdscr)

    stdscr.refresh()

    while True:
        key = stdscr.getch()

        stdscr.clear()

        if actions.keyboard(key) == 'up' and current_row_idx > 0:
            textPrint.print_center(stdscr, 'up')
            current_row_idx -= 1

        elif actions.keyboard(key) == 'down' and current_row_idx < len(menu_editar_perguntas) - 1:
            textPrint.print_center(stdscr, 'down')
            current_row_idx += 1

        elif actions.keyboard(key) == 'enter':
            stdscr.clear()
            textPrint.print_center(stdscr, 'enter')

			# Opcao Voltar:            
            if current_row_idx == len(menu_editar_perguntas) - 1:
                break

            ### Opcao Apagar Pergunta ##############
            elif current_row_idx == 0:
                current_row_idx = 0

                while True:
                    screen.show_erase_rules_screen(stdscr,current_row_idx)

                    # Entrada do teclado
                    key = stdscr.getch()

                    # Navegar pelo menu
                    if actions.keyboard(key) == 'left' and current_row_idx > 0:
                        current_row_idx -= 1
                    elif actions.keyboard(key) == 'right' and current_row_idx < 1:
                        current_row_idx += 1

                    # Caso selecione uma opcao
                    elif actions.keyboard(key) == 'enter':
                        # Caso selecione continuar
                        if current_row_idx == 0:
                            stdscr.clear()

                            escolha = show_all_questions(stdscr, current_user, "Apagar")

                            if escolha == -1:
                                stdscr.clear()
                                textPrint.print_center(stdscr, "Usuario ainda nao enviou perguntas")

                                stdscr.getch()

                            elif escolha != -2:
                                stdscr.clear()

                                pergunta_text = getData.get_one_question_data(escolha)

                                warning = ["Aperte 's' para confirmar que deseja deletar a seguinte pergunta:", pergunta_text, "Para cancelar, aperte qualquer outra tecla"]

                                textPrint.print_multi_lines(stdscr, warning, len(warning))

                                confirm_key = stdscr.getch()

                                if confirm_key in [83, 115]:
                                    perguntasActions.delete_question(escolha, current_user)

                                    stdscr.clear()

                                    mensagem_sucesso = ['Pergunta deletada com sucesso', 'Aperte qualquer coisa para continuar']
                                    textPrint.print_title(stdscr)
                                    textPrint.print_multi_lines(stdscr,mensagem_sucesso,len(mensagem_sucesso))

                                    stdscr.refresh()
                                    stdscr.getch()
                        else:
                            current_row_idx = 0
                            break

            ### Opcao Alterar Pergunta##############
            elif current_row_idx == 1:
                current_row_idx = 0

                while True:
                    screen.show_questions_rules_screen(stdscr,current_row_idx)

                    # Entrada do teclado
                    key = stdscr.getch()

                    # Navegar pelo menu
                    if actions.keyboard(key) == 'left' and current_row_idx > 0:
                        current_row_idx -= 1
                    elif actions.keyboard(key) == 'right' and current_row_idx < 1:
                        current_row_idx += 1

                    # Caso selecione uma opcao
                    elif actions.keyboard(key) == 'enter':
                        # Caso selecione continuar
                        if current_row_idx == 0:
                            stdscr.clear()

                            escolha = show_all_questions(stdscr, current_user, "Editar")

                            if escolha == -1:
                                stdscr.clear()
                                textPrint.print_center(stdscr, "Usuario ainda nao enviou perguntas")

                                stdscr.getch()

                            elif escolha != -2:
                                stdscr.clear()
                                perguntasActions.escreve_pergunta(stdscr, current_user, current_user_data, "Editar", escolha)



                        # Caso selecione voltar
                        else:
                            break
                
        
        stdscr.refresh()

        # Imprime o titulo do jogo
        menu.print_menu(stdscr, current_row_idx, menu_editar_perguntas)

        # Imprime o usuario atual
        textPrint.print_user_data(stdscr, data_list)        
        
        stdscr.refresh()

        textPrint.print_title(stdscr)
Example #9
0
def show_all_questions(stdscr, current_user_id, mode):
    curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_GREEN)
    stdscr.attron(curses.color_pair(1))
    
    current_page_index = 0

    textPrint.print_center(stdscr, "Carregando...")
    stdscr.refresh()

    questions_data = getData.get_user_questions_data(current_user_id)

    # Caso user nao tenha enviado perguntas
    if len(questions_data) == 1:
        return -1

    questions_ids = perguntasActions.get_questions_ids(questions_data)

    # Caso user nao tenha enviado perguntas
    if len(questions_ids) == 0:
        return -1

    questions = perguntasActions.get_question_list(questions_ids)

    pages_id = perguntasActions.get_questions_pages(questions_ids)
    pages = perguntasActions.get_questions_pages(questions)
    quantidade_paginas = len(pages)

    text = ["Pagina " + str(current_page_index + 1) + " / " + str(quantidade_paginas), "Para passar a pagina digite 'n'", "Para voltar a pagina, digite 'b'", "Para sair, digite 'e'"]

    stdscr.clear()

    while True:
        current_page = pages[current_page_index]
        page_with_numbers = perguntasActions.add_question_number_on_page(current_page)

        textPrint.print_multi_bottom_lines(stdscr, text, len(text))
        textPrint.print_multi_lines(stdscr, page_with_numbers, len(page_with_numbers))
        textPrint.print_title(stdscr)
        stdscr.refresh()

        key = stdscr.getch()

        # Caso user queira sair
        if actions.verify_exit(key) == True:
            return -2

        elif actions.verify_next(key) == True and current_page_index < quantidade_paginas - 1:
            current_page_index += 1
            
            text = ["Pagina " + str(current_page_index + 1) + " / " + str(quantidade_paginas), "Para passar a pagina digite 'n'", "Para voltar a pagina, digite 'b'", "Para sair, digite 'e'"]

            stdscr.clear()

        elif actions.verify_back(key) == True and current_page_index > 0:
            current_page_index -= 1
            
            text = ["Pagina " + str(current_page_index + 1) + " / " + str(quantidade_paginas), "Para passar a pagina digite 'n'", "Para voltar a pagina, digite 'b'", "Para sair, digite 'e'"]
            
            stdscr.clear()

        # Retorna a pergunta selecionada
        elif actions.verify_which_question(key) != -1 and actions.verify_which_question(key) < len(current_page) + 1:
            return pages_id[current_page_index][actions.verify_which_question(key)-1]

        else:
            stdscr.clear()
            text = ["Entrada Invalida", "Pagina " + str(current_page_index + 1) + " / " + str(quantidade_paginas), "Para passar a pagina digite 'n'", "Para voltar a pagina, digite 'b'", "Para sair, digite 'e'"]
            
#def test(stdscr):
#    while True:
#        a = show_all_questions(stdscr, 1, 0)
#        stdscr.clear()
#        textPrint.print_center(stdscr, str(a))
#        stdscr.refresh()
#        stdscr.getch()

#        if a == -1:
#            break

#curses.wrapper(test)
Example #10
0
def show_perguntas_menu(stdscr, current_user, current_user_id):
    # Menu com as opcoes para o jogo 
    menu_perguntas = ('Adicionar Pergunta', 'Editar Pergunta', 'Voltar')

    # Esconde o cursor
    curses.curs_set(0)

    # Opcao atual do menu
    current_row_idx = 0

    # Esquemas de cores
    curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_GREEN)

    # Mensagem de carregamento
    textPrint.print_center(stdscr, "Carregando...")
    stdscr.refresh()

    # Pega os dados do usuario que esta logado
    current_user_data = getData.get_user_data(current_user_id)
    current_user_name = current_user_data["Name"] 
    current_user_high_score = current_user_data["Highscore"]

    data_list = [current_user_name, current_user_high_score]

    # Imprime o menu do Jogo
    menu.print_menu(stdscr, current_row_idx, menu_perguntas)

    # Imprime o usuario atual
    textPrint.print_user_data(stdscr, data_list)
    
    # Imprime o titulo do jogo
    textPrint.print_title(stdscr)

    stdscr.refresh()

    while True:
        key = stdscr.getch()

        stdscr.clear()

        if actions.keyboard(key) == 'up' and current_row_idx > 0:
            textPrint.print_center(stdscr, 'up')
            current_row_idx -= 1

        elif actions.keyboard(key) == 'down' and current_row_idx < len(menu_perguntas) - 1:
            textPrint.print_center(stdscr, 'down')
            current_row_idx += 1

        elif actions.keyboard(key) == 'enter':
            stdscr.clear()
            textPrint.print_center(stdscr, 'enter')


			# Opcao Voltar:            
            if current_row_idx == len(menu_perguntas) - 1:
                break

            # Opcao Adicionar Pergunta
            elif current_row_idx == 0:
            	perguntasActions.adiciona_pergunta(stdscr, current_user_id, current_user_data)
                

            # Opcao Editar Pergunta
            elif current_row_idx == 1:
            	show_editar_perguntas_menu(stdscr, current_user, current_user_id)

            stdscr.refresh()

        # Imprime o titulo do jogo
        menu.print_menu(stdscr, current_row_idx, menu_perguntas)

        # Imprime o usuario atual
        textPrint.print_user_data(stdscr, data_list)        
        
        stdscr.refresh()

        textPrint.print_title(stdscr)
Example #11
0
def start_login(stdscr):
    yes_no_menu = ('Sim', 'Nao')

    # Define as cores que serao utilizadas
    curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_GREEN)

    # Coloca a cor atual como sendo o primeiro par
    stdscr.attron(curses.color_pair(1))

    # Configuracoes do banco de dados
    config = {
        "apiKey": "AIzaSyBrarBhWJSP3FnNJurEAtrbmUb1fG_wZFs",
        "authDomain": "teste-python-67d43.firebaseapp.com",
        "databaseURL": "https://teste-python-67d43.firebaseio.com",
        "projectId": "teste-python-67d43",
        "storageBucket": "",
        "messagingSenderId": "581051665954",
        "appId": "1:581051665954:web:6f131448200a100689447b"
    }

    # Altura e largura da tela
    altura_tela, largura_tela = stdscr.getmaxyx()

    # Faz conexao com Firebase
    firebase = pyrebase.initialize_app(config)

    exitMessage = "Para sair, digite /exit no nome ou senha"

    stop = False

    tentativas_restantes = 8

    while True:
        wrong_pass = False
        wrong_length = False
        exit_user_name = True

        textPrint.print_title(stdscr)
        textPrint.print_bottom(stdscr, exitMessage)

        curses.curs_set(True)

        # Label das areas do nome e da senha
        name_label = "Nome: "
        pass_label = "Senha: "

        # Coordenadas do label do nome
        x_nome = largura_tela // 2 - 15
        y_nome = altura_tela // 2

        # Coordenadas do label da senha
        x_senha = largura_tela // 2 - 15
        y_senha = altura_tela // 2 + 1

        # Imprime o label do nome e da senha na tela
        stdscr.addstr(y_nome, x_nome, name_label)
        stdscr.addstr(y_senha, x_senha, pass_label)

        # Permite o usuario ler o que esta digitando
        curses.echo()

        # Le o nome do teclado
        user_name = stdscr.getstr(y_nome, x_nome + len(name_label), 15)
        user_name = user_name.decode("utf-8")

        if actions.verify_exit(user_name) == True:
            break

        # Esconde o que o usuario esta escrevendo
        curses.echo(False)

        # Le a senha do teclado
        user_password = stdscr.getstr(y_senha, x_senha + len(pass_label), 15)
        user_password = user_password.decode("utf-8")

        if actions.verify_exit(user_password) == True:
            break

        # Conexao com o banco de dados
        db_quantidade_users = firebase.database()
        # Pega o valor da quantidade de usuarios
        quantidade_users = db_quantidade_users.child(
            "Quantidade_Users").get().val()

        # Variavel de controle
        logged_in = False

        # Converte o que foi lido de bytes para string

        stdscr.clear()

        textPrint.print_title(stdscr)
        textPrint.print_center(stdscr, "Aguarde...")
        stdscr.refresh()

        if len(user_name) <= 3 or len(user_name) > 20 or len(
                user_password) <= 3 or len(user_password) > 20:
            wrong_length = True

        else:
            # Loop que verifica se o user existe e se a senha e correta
            for user_id in range(1, quantidade_users + 1):
                # Conexao com o banco de dados
                db_user_name = firebase.database()
                db_user_pass = firebase.database()

                # Pega o usuario e senha atual no banco de dados
                current_user_name = db_user_name.child("Users").child(
                    user_id).child("Name").get().val()
                current_user_pass = db_user_pass.child("Users").child(
                    user_id).child("Pass").get().val()

                # Converte os dados para string
                current_user_name = str(current_user_name)
                current_user_pass = str(current_user_pass)

                # Caso o user exista e a senha esteja correta
                if current_user_name == user_name and current_user_pass == user_password:
                    # Muda o estado para True
                    logged_in = True

                    break

                elif current_user_name == user_name:
                    wrong_pass = True
                    break

                elif user_id == quantidade_users:
                    exit_user_name = False

        # Limpa a tela
        stdscr.clear()

        textPrint.print_title(stdscr)

        curses.curs_set(0)

        # Caso esteja logado
        if logged_in == True:
            tentativas_restantes = 8

            text_sucesso = [
                "Bem vindo " + user_name,
                "Aperte qualquer coisa para continuar"
            ]

            textPrint.print_multi_lines(stdscr, text_sucesso, 2)

            stdscr.refresh()

            stdscr.getch()
            stdscr.clear()
            game.show_game_menu(stdscr, user_id)

            break

        # Caso falhe em logar
        else:
            tentativas_restantes -= 1

            current_row_idx = 0

            text_tentativas = "Tentativas Restantes: " + str(
                tentativas_restantes)

            tentar_novamente = "Deseja tentar novamente?"

            if (tentativas_restantes == 0):
                text_error = [
                    "ERRO AO EFETUAR LOGIN",
                    "A tela ira bloquear por 1 minuto", tentar_novamente
                ]
            else:
                text_error = [
                    "ERRO AO EFETUAR LOGIN", text_tentativas, tentar_novamente
                ]

            if wrong_length == True:
                text_wrong_length = "ERRO AO EFETUAR LOGIN: Nome de usuario e senha tem que ter entre 4 a 20 caracteres"
                text_error[0] = text_wrong_length

            if wrong_pass == True:
                text_wrong_pass = "******"
                text_error[0] = text_wrong_pass

            if exit_user_name == False:
                text_exist_user = "******"
                text_error[0] = text_exist_user

            while True:
                textPrint.print_title(stdscr)

                menu.horizontal_menu(stdscr, current_row_idx, yes_no_menu)

                textPrint.print_multi_lines(stdscr, text_error,
                                            len(text_error))

                stdscr.refresh()

                key = stdscr.getch()

                if actions.keyboard(key) == 'left' and current_row_idx > 0:
                    current_row_idx -= 1

                elif actions.keyboard(key) == 'right' and current_row_idx < 1:
                    current_row_idx += 1

                elif actions.keyboard(key) == 'enter':
                    if tentativas_restantes == 0:
                        timer.block_screen(stdscr)
                        stdscr.clear()

                    if current_row_idx == 0:
                        stop = False
                        break
                    else:
                        stop = True
                        break

                stdscr.clear()

        stdscr.clear()

        if stop == True:
            break
Example #12
0
def start_registrar(stdscr):
    curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_GREEN)

    stdscr.attron(curses.color_pair(1))

    config = {
        "apiKey": "AIzaSyBrarBhWJSP3FnNJurEAtrbmUb1fG_wZFs",
        "authDomain": "teste-python-67d43.firebaseapp.com",
        "databaseURL": "https://teste-python-67d43.firebaseio.com",
        "projectId": "teste-python-67d43",
        "storageBucket": "",
        "messagingSenderId": "581051665954",
        "appId": "1:581051665954:web:6f131448200a100689447b"
    }

    altura_tela, largura_tela = stdscr.getmaxyx()

    # Faz conexao com Firebase
    firebase = pyrebase.initialize_app(config)

    db_quantidade_users = firebase.database()

    quantidade_users = db_quantidade_users.child(
        "Quantidade_Users").get().val()

    exitRegister = False

    exitMessage = "Para sair, digite /exit no nome ou senha"

    yes_no_menu = ('Sim', 'Nao')

    while True:
        wrong_length = False

        textPrint.print_bottom(stdscr, exitMessage)
        textPrint.print_title(stdscr)

        curses.curs_set(True)

        name_label = "Nome: "
        pass_label = "Senha: "
        confirm_pass_label = "Confirmar senha: "

        x_nome = largura_tela // 2 - 15
        y_nome = altura_tela // 2

        x_senha = largura_tela // 2 - 15
        y_senha = altura_tela // 2 + 1

        x_confirm = largura_tela // 2 - 15
        y_confirm = altura_tela // 2 + 2

        stdscr.addstr(y_nome, x_nome, name_label)
        stdscr.addstr(y_senha, x_senha, pass_label)
        stdscr.addstr(y_confirm, x_confirm, confirm_pass_label)

        curses.echo()
        user_name = stdscr.getstr(y_nome, x_nome + len(name_label), 15)

        user_name = user_name.decode("utf-8")

        if actions.verify_exit(user_name) == True:
            exitRegister = True
            break

        curses.echo(False)
        user_password = stdscr.getstr(y_senha, x_senha + len(pass_label), 15)
        user_password = user_password.decode("utf-8")

        if actions.verify_exit(user_password) == True:
            exitRegister = True
            break

        user_confirm_password = stdscr.getstr(
            y_confirm, x_confirm + len(confirm_pass_label), 15)
        user_confirm_password = user_confirm_password.decode("utf-8")

        if actions.verify_exit(user_confirm_password) == True:
            exitRegister = True
            break

        isUnique = True

        db_all_users = firebase.database()

        stdscr.clear()

        textPrint.print_title(stdscr)
        textPrint.print_center(stdscr, "Aguarde...")

        stdscr.refresh()

        for user in range(quantidade_users):
            this_user = db_all_users.child("Users").child(user + 1).child(
                "Name").get().val()

            if user_name == this_user:
                isUnique = False
                break

        if isUnique == True and user_password == user_confirm_password and len(
                user_name) > 3 and len(user_name) <= 20 and len(
                    user_password) > 3 and len(user_password) <= 20:
            stdscr.clear()

            textPrint.print_title(stdscr)
            sucess_message = [
                "Usuario " + str(user_name) + " registrado!",
                "Pressione qualquer tecla para continuar"
            ]
            textPrint.print_multi_lines(stdscr, sucess_message, 2)

            stdscr.refresh()
            stdscr.getch()
            stdscr.clear()
            break

        else:
            stdscr.clear()

            error_message = []

            if len(user_name) <= 3 or len(user_name) > 20 or len(
                    user_password) <= 3 or len(user_password) > 20:
                wrong_length = True

            if user_password != user_confirm_password:
                isDifferent = True

            if isUnique == False:
                warning_unique = "ERRO AO CRIAR USUARIO: Nome de Usuario ja existe!"
                error_message.apeend(warning_unique)

            if wrong_length == True:
                warning_length = "ERRO AO CRIAR USUARIO: Usuario e Senha tem que ter entre 4 e 20 caracteres!"
                error_message.append(warning_length)

            if isDifferent == True:
                warning_different = "ERRO AO CRIAR USUARIO: Senha e Confirmacao devem ser iguais!"
                error_message.append(warning_different)

            tentar_novamente = "Deseja tentar novamente?"

            error_message.append(tentar_novamente)

            current_row_idx = 0

            while True:
                textPrint.print_title(stdscr)
                textPrint.print_multi_lines(stdscr, error_message,
                                            len(error_message))
                menu.horizontal_menu(stdscr, current_row_idx, yes_no_menu)

                stdscr.refresh()

                key = stdscr.getch()

                if actions.keyboard(key) == 'left' and current_row_idx > 0:
                    current_row_idx -= 1

                elif actions.keyboard(key) == 'right' and current_row_idx < 1:
                    current_row_idx += 1

                elif actions.keyboard(key) == 'enter':
                    if current_row_idx == 0:
                        exitRegister = False
                        break
                    else:
                        exitRegister = True
                        break

        stdscr.clear()

        if exitRegister == True:
            break

    if exitRegister == False:
        new_user_id = quantidade_users + 1
        db_new_user = firebase.database()
        new_user = db_new_user.child("Users").child(new_user_id)

        new_user = {
            "Name": user_name,
            "Pass": user_password,
            "Highscore": 0,
            "Questions": {
                "Quantidade_enviadas": 0
            }
        }

        db_qtd_user = firebase.database()

        qtd_user = {"Quantidade_Users": new_user_id}

        db_new_user.update(new_user)
        db_qtd_user.update(qtd_user)

        stdscr.refresh()
Example #13
0
def escreve_pergunta(stdscr, current_user_id, current_user_data, mode, question_id):
    curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_GREEN)

    stdscr.attron(curses.color_pair(1))

    # Conexao com o banco de dados
    config = {
        "apiKey": "AIzaSyBrarBhWJSP3FnNJurEAtrbmUb1fG_wZFs",
        "authDomain": "teste-python-67d43.firebaseapp.com",
        "databaseURL": "https://teste-python-67d43.firebaseio.com",
        "projectId": "teste-python-67d43",
        "storageBucket": "",
        "messagingSenderId": "581051665954",
        "appId": "1:581051665954:web:6f131448200a100689447b"
    }

    # Dimensoes da tela
    altura_tela, largura_tela = stdscr.getmaxyx()

    # Faz conexao com Firebase
    firebase = pyrebase.initialize_app(config)

    # Pega a quantidade de perguntas que existem no jogo
    db_quantidade_perguntas = firebase.database()
    quantidade_perguntas = db_quantidade_perguntas.child("Quantidade_Perguntas").get().val()

    # Variavel de controle
    exitRegister = False

    exitMessage = "Para sair, digite /exit"

    yes_no_menu = ('Sim', 'Nao')

    while True:
        # Imprime mensagem para sair da tela
        textPrint.print_bottom(stdscr, exitMessage)
        # Imprime o titulo do jogo
        textPrint.print_title(stdscr)

        # Habilita visualizacao do cursor
        curses.curs_set(True)

        if mode == "Editar":
            question_text = getData.get_one_question_data(question_id)
            pergunta_atual_label = ["Pergunta atual: " + question_text, ""]
            textPrint.print_multi_lines(stdscr,pergunta_atual_label, 2)
            pergunta_label = "Pergunta editada: "

        else:
            pergunta_label = "Informe a pergunta: "

        # Coordenadas da area para escrever a pergunta
        x_pergunta = largura_tela//2 - 50 - len(pergunta_label)//2
        y_pergunta = altura_tela//2

        # Imprime a pergunta na tela
        stdscr.addstr(y_pergunta, x_pergunta, pergunta_label)

        # Habilita para o usuarop escrever na tela
        curses.echo()

        user_pergunta = stdscr.getstr(y_pergunta, x_pergunta + len(pergunta_label),100)
        user_pergunta = user_pergunta.decode("utf-8")
        # Verifica se usuario digitou /exit

        if actions.verify_exit(user_pergunta) == True:
            # variavel que indica que o user saiu
            exitRegister = True
            break

        # Desabilita a visualização do cursor 
        curses.echo(False)
        
        # Variavel que verifica se pergunta e unica
        isUnique = True

        # Dados de todas as perguntas
        db_all_perguntas = firebase.database()
        stdscr.clear()

        textPrint.print_title(stdscr)
        textPrint.print_center(stdscr, "Aguarde...")

        stdscr.refresh()

        # Loop para verificar se pergunta e unica
        for pergunta in range (quantidade_perguntas):
            # Dados da pergunta atual
            this_pergunta = db_all_perguntas.child("Perguntas").child(pergunta + 1).child("Pergunta").get().val()

            if user_pergunta == this_pergunta:
                isUnique = False
                break
        
        # Caso a pergunta seja unica
        if isUnique == True and len(user_pergunta) > 3 and len(user_pergunta) <= 100:
            stdscr.clear()
            desistencia_da_resposta = 0

            # Chama funcao que pergunta sobre as respostas
            desistencia_da_resposta = escreve_respostas(stdscr, question_id, mode)

            break
        
        # Caso de errado    
        else:
            stdscr.clear()

            tentar_novamente = "Deseja tentar novamente?"
            error_message = ["ERRO AO ADICIONAR PERGUNTA", tentar_novamente]

            current_row_idx = 0

            # Tela de erro
            while True:
                textPrint.print_title(stdscr)
                textPrint.print_multi_lines(stdscr, error_message, 2)
                menu.horizontal_menu(stdscr, current_row_idx, yes_no_menu)
            
                stdscr.refresh()

                key = stdscr.getch()

                if actions.keyboard(key) == 'left' and current_row_idx > 0:
                    current_row_idx -= 1

                elif actions.keyboard(key) == 'right' and current_row_idx < 1:
                    current_row_idx += 1

                elif actions.keyboard(key) == 'enter':
                    if current_row_idx == 0:
                        exitRegister = False
                        break
                    else:
                        exitRegister = True
                        break

        stdscr.clear()

        # Caso o user queira sair
        if exitRegister == True:
            break
    
    # Escreve os dados obtidos no banco de dados
    if exitRegister == False and desistencia_da_resposta != False:
        if mode == "Adicionar":
            new_pergunta_id = quantidade_perguntas + 1
        else:
            new_pergunta_id = question_id

        db_new_pergunta = firebase.database()
        new_pergunta = db_new_pergunta.child("Perguntas").child(new_pergunta_id)

        new_pergunta = {
            "Pergunta": user_pergunta
        }

        db_new_pergunta.update(new_pergunta)

        if mode == "Adicionar":
            db_qtd_pergunta = firebase.database()

            qtd_pergunta = {
                "Quantidade_Perguntas": new_pergunta_id
            }

            # Pega o valor de quantas perguntas o user ja enviou
            db_user_qtd_perguntas = firebase.database()
            user_qtd_perguntas = db_user_qtd_perguntas.child("Users").child(current_user_id).child("Questions").child("Quantidade_enviadas").get().val()

            # Cria o id pra pergunta que o user vai enviar
            new_user_pergunta_id = int(user_qtd_perguntas) + 1

            # Faz conexao com banco de dados
            db_write_user = firebase.database()
            new_user_pergunta = db_write_user.child("Users").child(current_user_id).child("Questions")

            new_user_pergunta = {
                new_user_pergunta_id:new_pergunta_id,
                "Quantidade_enviadas":new_user_pergunta_id
            }

            db_qtd_pergunta.update(qtd_pergunta)
            db_write_user.update(new_user_pergunta)

        stdscr.clear()
        stdscr.refresh()
Example #14
0
def escreve_respostas(stdscr, question_id, mode):
    curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_GREEN)

    stdscr.attron(curses.color_pair(1))

    config = {
        "apiKey": "AIzaSyBrarBhWJSP3FnNJurEAtrbmUb1fG_wZFs",
        "authDomain": "teste-python-67d43.firebaseapp.com",
        "databaseURL": "https://teste-python-67d43.firebaseio.com",
        "projectId": "teste-python-67d43",
        "storageBucket": "",
        "messagingSenderId": "581051665954",
        "appId": "1:581051665954:web:6f131448200a100689447b"
    }

    altura_tela, largura_tela = stdscr.getmaxyx()

    # Faz conexao com Firebase
    firebase = pyrebase.initialize_app(config)

    db_quantidade_resposta = firebase.database()

    quantidade_resposta = db_quantidade_resposta.child("Quantidade_Perguntas").get().val()
    
    exitRegister = False

    exitMessage = "Para sair, digite /exit em qualquer item"

    yes_no_menu = ('Sim', 'Nao')


    while True:
        textPrint.print_bottom(stdscr, exitMessage)
        textPrint.print_title(stdscr)

        curses.curs_set(True)

        resposta_labelA = "Informe a resposta item a): "
        resposta_labelB = "Informe a resposta item b): "
        resposta_labelC = "Informe a resposta item c): "
        resposta_labelD = "Informe a resposta item d): "
        
        trueFalseA_label = "Insira 1 caso seja verdadeiro e 0 caso seja falso: "
        trueFalseB_label = "Insira 1 caso seja verdadeiro e 0 caso seja falso: "
        trueFalseC_label = "Insira 1 caso seja verdadeiro e 0 caso seja falso: "
        trueFalseD_label = "Insira 1 caso seja verdadeiro e 0 caso seja falso: "
        

        x_respostaA = largura_tela//2 - 50
        y_respostaA = altura_tela//2

        x_respostaB = largura_tela//2 - 50
        y_respostaB = altura_tela//2 + 2

        x_respostaC = largura_tela//2 - 50
        y_respostaC = altura_tela//2 + 4

        x_respostaD = largura_tela//2 - 50
        y_respostaD = altura_tela//2 + 6

        x_trueFalseA = largura_tela//2 - 50
        y_trueFalseA = altura_tela//2 + 1

        x_trueFalseB = largura_tela//2 - 50
        y_trueFalseB = altura_tela//2 + 3

        x_trueFalseC = largura_tela//2 - 50
        y_trueFalseC = altura_tela//2 + 5

        x_trueFalseD = largura_tela//2 - 50
        y_trueFalseD = altura_tela//2 + 7

        stdscr.addstr(y_respostaA, x_respostaA, resposta_labelA)
        stdscr.addstr(y_trueFalseA, x_trueFalseA, trueFalseA_label)
        
        stdscr.addstr(y_respostaB, x_respostaB, resposta_labelB)
        stdscr.addstr(y_trueFalseB, x_trueFalseB, trueFalseB_label)
        
        stdscr.addstr(y_respostaC, x_respostaC, resposta_labelC)
        stdscr.addstr(y_trueFalseC, x_trueFalseC, trueFalseC_label)

        stdscr.addstr(y_respostaD, x_respostaD, resposta_labelD)
        stdscr.addstr(y_trueFalseD, x_trueFalseD, trueFalseD_label)

        curses.echo()

        user_respostaA = stdscr.getstr(y_respostaA, x_respostaA + len(resposta_labelA),50)
        user_respostaA = user_respostaA.decode("utf-8")

        if actions.verify_exit(user_respostaA) == True:
            exitRegister = True
            break

        #curses.echo(False)
    
        user_trueFalseA = stdscr.getstr(y_trueFalseA, x_trueFalseA + len(trueFalseA_label),50)
        user_trueFalseA = user_trueFalseA.decode("utf-8")
        
        if actions.verify_exit(user_trueFalseA) == True:
            exitRegister = True
            break

        user_trueFalseA = actions.verify_0_ou_1(user_trueFalseA)

        user_respostaB = stdscr.getstr(y_respostaB, x_respostaB + len(resposta_labelB),50)
        user_respostaB = user_respostaB.decode("utf-8")

        if actions.verify_exit(user_respostaB) == True:
            exitRegister = True
            break

        user_trueFalseB = stdscr.getstr(y_trueFalseB, x_trueFalseB + len(trueFalseB_label),50)
        user_trueFalseB = user_trueFalseB.decode("utf-8")
        
        if actions.verify_exit(user_trueFalseB) == True:
            exitRegister = True
            break

        user_trueFalseB = actions.verify_0_ou_1(user_trueFalseB)

        user_respostaC = stdscr.getstr(y_respostaC, x_respostaC + len(resposta_labelC),50)
        user_respostaC = user_respostaC.decode("utf-8")

        if actions.verify_exit(user_respostaC) == True:
            exitRegister = True
            break

        user_trueFalseC = stdscr.getstr(y_trueFalseC, x_trueFalseC + len(trueFalseC_label),50)
        user_trueFalseC = user_trueFalseC.decode("utf-8")

        if actions.verify_exit(user_trueFalseC) == True:
            exitRegister = True
            break

        user_trueFalseC = actions.verify_0_ou_1(user_trueFalseC)

        user_respostaD = stdscr.getstr(y_respostaD, x_respostaD + len(resposta_labelD),50)
        user_respostaD = user_respostaD.decode("utf-8")


        if actions.verify_exit(user_respostaD) == True:
            exitRegister = True
            break
        
        user_trueFalseD = stdscr.getstr(y_trueFalseD, x_trueFalseD + len(trueFalseD_label),50)
        user_trueFalseD = user_trueFalseD.decode("utf-8")

        if actions.verify_exit(user_trueFalseD) == True:
            exitRegister = True
            break
        user_trueFalseD = actions.verify_0_ou_1(user_trueFalseD)

        curses.echo(False)
        
        isUnique = True

        db_all_resposta = firebase.database()

        stdscr.clear()

        textPrint.print_title(stdscr)
        textPrint.print_center(stdscr, "Aguarde...")

        stdscr.refresh()
        if isUnique == True and (user_trueFalseA == True or user_trueFalseA == False) and (user_trueFalseB == True or user_trueFalseB == False) and (user_trueFalseC == True or user_trueFalseC == False) and (user_trueFalseD == True or user_trueFalseD == False) and ((user_trueFalseA == True and user_trueFalseB == False and user_trueFalseC == False and user_trueFalseD == False) or (user_trueFalseA == False and user_trueFalseB == True and user_trueFalseC == False and user_trueFalseD == False) or (user_trueFalseA == False and user_trueFalseB == False and user_trueFalseC == True and user_trueFalseD == False) or (user_trueFalseA == False and user_trueFalseB == False and user_trueFalseC == False and user_trueFalseD == True)): 

            stdscr.clear()

            textPrint.print_title(stdscr)

            if mode == "Adicionar":
                sucess_message = ["Pergunta adicionada com sucesso", "Pressione qualquer tecla para continuar"]
            
            else:
                sucess_message = ["Pergunta editada com sucesso", "Pressione qualquer tecla para continuar"]
            textPrint.print_multi_lines(stdscr,sucess_message, 2)
            
            stdscr.refresh()
            stdscr.getch()
            stdscr.clear()
            break

        else:
            stdscr.clear()

            tentar_novamente = "Deseja tentar novamente?"
            error_message = ["ERRO AO CADASTRAR RESPOSTA", tentar_novamente]

            current_row_idx = 0

            while True:
                textPrint.print_title(stdscr)
                textPrint.print_multi_lines(stdscr, error_message, 2)
                menu.horizontal_menu(stdscr, current_row_idx, yes_no_menu)
            
                stdscr.refresh()

                key = stdscr.getch()

                if actions.keyboard(key) == 'left' and current_row_idx > 0:
                    current_row_idx -= 1

                elif actions.keyboard(key) == 'right' and current_row_idx < 1:
                    current_row_idx += 1

                elif actions.keyboard(key) == 'enter':
                    if current_row_idx == 0:
                        exitRegister = False
                        break
                    else:
                        exitRegister = True
                        break
        stdscr.clear()

        if exitRegister == True:
            break
    
    if exitRegister == False:   
        if mode == "Editar":
            new_resposta_id = question_id
            
        else:        
            new_resposta_id = quantidade_resposta + 1
            
        db_new_resposta = firebase.database()
        new_resposta = db_new_resposta.child("Respostas").child(new_resposta_id)

        new_resposta = {
        "a": {"isCorrect": user_trueFalseA, "valor": user_respostaA },
        "b": {"isCorrect": user_trueFalseB, "valor": user_respostaB },
        "c": {"isCorrect": user_trueFalseC, "valor": user_respostaC },
        "d": {"isCorrect": user_trueFalseD, "valor": user_respostaD }
        }

        db_new_resposta.update(new_resposta)

        if mode == "Adicionar":
            db_qtd_resposta = firebase.database()

            qtd_resposta = {
                "Quantidade_Perguntas": new_resposta_id 
            }

            db_qtd_resposta.update(qtd_resposta)
        
        stdscr.refresh()

    else:
        return False
Example #15
0
def main(stdscr):
    # Menu com as opcoes de login
    menu_login = ('Login', 'Registrar', 'Scoreboard', 'Sair')

    # Esconde o cursor
    curses.curs_set(0)

    # tela inicial do jogo

    screen.show_title_screen(stdscr)

    # Opcao atual do menu
    current_row_idx = 0

    # Esquemas de cores
    curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_GREEN)

    # Imprime o menu de login na tela
    menu.print_menu(stdscr, current_row_idx, menu_login)

    textPrint.print_title(stdscr)

    selected_row_idx = 0

    while True:
        # Recebe a entrada do teclado
        key = stdscr.getch()
        stdscr.clear()

        # Mover para cima no menu
        if actions.keyboard(key) == 'up' and current_row_idx > 0:
            current_row_idx -= 1

        # Mover para baixo no menu
        elif actions.keyboard(
                key) == 'down' and current_row_idx < len(menu_login) - 1:
            current_row_idx += 1

        # Seleciona uma opcao do menu
        elif actions.keyboard(key) == 'enter':
            stdscr.clear()

            # Caso selecione a opcao de sair
            if current_row_idx == len(menu_login) - 1:

                # Confirmar se deseja mesmo sair
                saiu = screen.show_deseja_sair(stdscr)

                stdscr.clear()
                textPrint.print_title(stdscr)

                if saiu == True:
                    # Mensagem de agradecimento por ter entrado no jogo
                    message = "Obrigado por jogar. Aperte qualquer coisa para sair"
                    textPrint.print_center(stdscr, message)
                    textPrint.print_title(stdscr)
                    stdscr.refresh()
                    stdscr.getch()
                    break

            # Caso selecione a opcao de login
            elif current_row_idx == 0:
                curses.curs_set(True)
                login.start_login(stdscr)
                curses.curs_set(False)

            # Caso selecione a opcao de registrar
            elif current_row_idx == 1:
                curses.curs_set(True)
                registrar.start_registrar(stdscr)
                curses.curs_set(False)

            # Caso selecione a opcao de scoreboard
            elif current_row_idx == 2:
                screen.show_scoreboard(stdscr)

            # Mensagem quando user escolhe alguma opcao
            else:
                stdscr.addstr(
                    0, 0,
                    "Voce escolheu: {}".format(menu_login[current_row_idx]))
                stdscr.getch()

            stdscr.refresh()

        # Atualiza o menu
        menu.print_menu(stdscr, current_row_idx, menu_login)
        stdscr.refresh()
        textPrint.print_title(stdscr)
Example #16
0
def show_game_menu(stdscr, current_user):
    # Menu com as opcoes para o jogo 
    menu_jogo = ('Jogar', 'Perguntas', 'Scoreboard', 'Logout')

    # Esconde o cursor
    curses.curs_set(0)

    # Opcao atual do menu
    current_row_idx = 0

    # Esquemas de cores
    curses.init_pair(1, curses.COLOR_GREEN, curses.COLOR_BLACK)
    curses.init_pair(2, curses.COLOR_BLACK, curses.COLOR_GREEN)

    # Mensagem de carregamento
    textPrint.print_center(stdscr, "Carregando...")
    stdscr.refresh()

    # Pega os dados do usuario que esta logado
    current_user_data = getData.get_user_data(current_user)
    current_user_name = current_user_data["Name"] 
    current_user_high_score = current_user_data["Highscore"]

    data_list = [current_user_name, current_user_high_score]

    # Imprime o menu do Jogo
    menu.print_menu(stdscr, current_row_idx, menu_jogo)

    # Imprime o usuario atual
    textPrint.print_user_data(stdscr, data_list)
    
    # Imprime o titulo do jogo
    textPrint.print_title(stdscr)

    stdscr.refresh()

    while True:
        key = stdscr.getch()

        stdscr.clear()

        if actions.keyboard(key) == 'up' and current_row_idx > 0:
            textPrint.print_center(stdscr, 'up')
            current_row_idx -= 1

        elif actions.keyboard(key) == 'down' and current_row_idx < len(menu_jogo) - 1:
            textPrint.print_center(stdscr, 'down')
            current_row_idx += 1

        elif actions.keyboard(key) == 'enter':
            stdscr.clear()
            textPrint.print_center(stdscr, 'enter')

            if current_row_idx == len(menu_jogo) - 1:
                # Confirmar se deseja mesmo sair     
                saiu = screen.show_deseja_sair(stdscr)      
                
                if saiu == True:
                    # Voltar para primeiro menu
                    stdscr.clear()
                    menu.print_menu
                    stdscr.refresh()
                    break

            elif current_row_idx == 0:
                stdscr.clear()
                current_user_high_score = play.final_game(stdscr, current_user_name, current_user, current_user_high_score)
                data_list[1] = current_user_high_score

            elif current_row_idx == 1:
                 menuPerguntas.show_perguntas_menu(stdscr, current_user_data, current_user)

            elif current_row_idx == 2:
                screen.show_scoreboard(stdscr)

            stdscr.refresh()

        # Imprime o titulo do jogo
        menu.print_menu(stdscr, current_row_idx, menu_jogo)

        # Imprime o usuario atual
        textPrint.print_user_data(stdscr, data_list)        
        
        stdscr.refresh()

        textPrint.print_title(stdscr)
Example #17
0
def final_game(stdscr, current_user_name, current_user_id,
               current_user_high_score):
    # A, B, C, D, G, a, b, c, d, g
    caracteres_permitidos = [65, 66, 67, 68, 71, 97, 98, 99, 100, 103]

    # Imprime titulo do jogo
    textPrint.print_title(stdscr)

    # Imprimir mensagem de 'Bem Vindos'
    screen.show_welcome_screen(stdscr)
    stdscr.clear()

    # Imprimir Titulo do jogo
    textPrint.print_title(stdscr)

    # Imprime regras do jogo
    screen.show_rules_screen(stdscr)
    stdscr.clear()

    # Imprime titulo do jogo
    textPrint.print_title(stdscr)
    # Tela de carregamento
    textPrint.print_center(stdscr, "Carregando...")
    stdscr.refresh()

    # Lista com as perguntas do Jogo
    lista_perguntas = getData.get_questions_data()
    stdscr.clear()

    hasGivenUp = False
    hasLost = False
    hasWon = False

    pontos = 0

    for pergunta in range(len(lista_perguntas)):
        pergunta_atual = "Pergunta " + str(
            pergunta + 1) + ": " + lista_perguntas[pergunta]["Pergunta"]
        id_atual = lista_perguntas[pergunta]["Id"]

        dict_respostas = getData.get_answer(id_atual)
        right_answer = getData.get_right_answer(dict_respostas)

        resposta_a = 'a)' + str(dict_respostas['a']['valor'])
        resposta_b = 'b)' + str(dict_respostas['b']['valor'])
        resposta_c = 'c)' + str(dict_respostas['c']['valor'])
        resposta_d = 'd)' + str(dict_respostas['d']['valor'])

        text_list = [
            pergunta_atual, resposta_a, resposta_b, resposta_c, resposta_d
        ]

        textPrint.print_multi_lines(stdscr, text_list, len(text_list))
        textPrint.print_title(stdscr)

        desistir = [71, 103]

        while True:
            key = stdscr.getch()

            stdscr.clear()
            stdscr.refresh()

            if key not in caracteres_permitidos:
                textPrint.print_bottom(stdscr, "Entrada Invalida!")
                textPrint.print_title(stdscr)

            else:
                if actions.verify_giveup(key) == True:
                    textPrint.print_bottom(
                        stdscr,
                        "Para confirmar desistencia, aperte s, caso contrario aperte outra tecla"
                    )
                    textPrint.print_multi_lines(stdscr, text_list,
                                                len(text_list))
                    textPrint.print_title(stdscr)

                    confirm_key = stdscr.getch()

                    if confirm_key in [83, 115]:
                        hasGivenUp = True
                        break

                    else:
                        stdscr.clear()
                        textPrint.print_multi_lines(stdscr, text_list,
                                                    len(text_list))
                        textPrint.print_title(stdscr)
                        stdscr.refresh()

                elif key in right_answer:
                    pontos += 1
                    mensagem = [
                        'Correto!', 'Aperte qualquer tecla para continuar'
                    ]
                    textPrint.print_multi_lines(stdscr, mensagem, 2)
                    textPrint.print_title(stdscr)
                    stdscr.getch()
                    stdscr.clear()

                    break

                else:
                    pontos = 0
                    mensagem = [
                        'Errado!', 'Aperte qualquer tecla para continuar'
                    ]
                    textPrint.print_multi_lines(stdscr, mensagem, 2)
                    textPrint.print_title(stdscr)
                    hasLost = True
                    stdscr.getch()
                    stdscr.clear()
                    break

            textPrint.print_multi_lines(stdscr, text_list, len(text_list))
            textPrint.print_title(stdscr)
            stdscr.refresh()

        if hasGivenUp == True or hasLost == True:
            break

    stdscr.clear()
    textPrint.print_title(stdscr)
    textPrint.print_center(stdscr, "Carregando...")
    stdscr.refresh()

    # Alterar scoreboard e recorde pessoal
    top_5_list = scoreboard.get_top_5_high_score()

    globalRecord = scoreboard.update_scoreboard(top_5_list, pontos,
                                                current_user_name)
    personalRecord = scoreboard.set_user_high_score(pontos,
                                                    current_user_high_score,
                                                    current_user_id)

    screen.show_end_screen(stdscr, pontos, personalRecord, globalRecord)

    if personalRecord == True:
        return pontos
    return current_user_high_score