def start(current_user):
    global user
    user = current_user
    username = user['brugernavn']
    tui.clear()
    rest.reset_game(username)
    rest.reset_score(username)
    print_hangman()
    while True:
        do_guess()

        if rest.is_game_won(username):
            tui.clear()
            print_hangman()
            tui.print_win()
            if play_again():
                rest.reset_game(username)
                tui.clear()
                print_hangman()
                continue
            break

        if rest.is_game_lost(username):
            tui.clear()
            print_hangman()
            tui.print_loss()
            if play_again():
                rest.reset_score(username)
                rest.reset_game(username)
                tui.clear()
                print_hangman()
                continue
            break
def main():
    tui.clear()
    tui.print_startscreen()
    tui.print_menu(rest.get_current_user_amount(), current_user)
    while True:
        cmd = tui.get_cmd()
        tui.clear()
        tui.print_menu(rest.get_current_user_amount(), current_user)
        exec_cmd(cmd)
def do_exit():
    global current_user

    if current_user == None:
        return

    rest.logout(current_user['brugernavn'])
    current_user = None

    tui.clear()
    tui.print_menu(rest.get_current_user_amount(), current_user)
    tui.print_exit()
    sys.exit()
def do_login():
    global current_user

    tui.print_login_prompt()
    username = tui.get_user_input('Username')
    password = tui.get_user_input('Password')

    if rest.login(username, password):
        current_user = rest.get_logged_in_user(username)
        tui.clear()
        tui.print_menu(rest.get_current_user_amount(), current_user)
        tui.print_login_success()
    else:
        tui.clear()
        tui.print_menu(rest.get_current_user_amount(), current_user)
        tui.print_login_failed()
def do_logout():
    global current_user

    if current_user == None:
        tui.print_logout_not_logged_in()
        return

    if rest.logout(current_user['brugernavn']):
        current_user = None
        tui.clear()
        tui.print_menu(rest.get_current_user_amount(), current_user)
        tui.print_logout_success()
    else:
        current_user = None
        tui.clear()
        tui.print_menu(rest.get_current_user_amount(), current_user)
        tui.print_logout_failed()
def do_guess():
    global user
    username = user['brugernavn']

    while True:
        guess = tui.get_user_guess()
        is_guessed = rest.is_char_guessed(username, guess)
        if is_guessed:
            tui.clear()
            print_hangman()
            tui.print_already_guessed(guess)
            continue
        else:
            break

    if rest.guess(username, guess):
        tui.clear()
        print_hangman()
        tui.print_correct_guess(guess)
        if rest.is_highscore(username, user['adgangskode']):
            current_score = str(rest.get_score(username))
            rest.set_user_highscore(username, current_score)
            tui.print_new_highscore(current_score)
    else:
        tui.clear()
        print_hangman()
        tui.print_wrong_guess(guess)
def do_forgot_password():
    global current_user
    tui.clear()
    tui.print_menu(rest.get_current_user_amount(), current_user)
    tui.print_forgot_password()

    username = tui.get_user_input('Username')

    if rest.send_forgot_password_email(username, ''):
        tui.clear()
        tui.print_menu(rest.get_current_user_amount(), current_user)
        tui.print_forgot_password_success()
    else:
        tui.clear()
        tui.print_menu(rest.get_current_user_amount(), current_user)
        tui.print_forgot_password_failed()
def do_new_password():
    global current_user
    tui.clear()
    tui.print_menu(rest.get_current_user_amount(), current_user)
    tui.print_new_password()

    username = tui.get_user_input('Username')
    old_password = tui.get_user_input('Old Password')
    new_password = tui.get_user_input('New Password')

    if rest.change_user_password(username, old_password, new_password):
        tui.clear()
        tui.print_menu(rest.get_current_user_amount(), current_user)
        tui.print_new_password_success()
    else:
        tui.clear()
        tui.print_menu(rest.get_current_user_amount(), current_user)
        tui.print_new_password_failed()
def do_send_email():
    global current_user
    tui.clear()
    tui.print_menu(rest.get_current_user_amount(), current_user)
    tui.print_send_email_prompt()
    username = tui.get_user_input('Username')
    password = tui.get_user_input('Password')
    subject = tui.get_user_input('Subject')
    message = tui.get_user_input('Message')

    if rest.send_email(username, password, subject, message):
        tui.clear()
        tui.print_menu(rest.get_current_user_amount(), current_user)
        tui.print_send_email_success(username)
    else:
        tui.clear()
        tui.print_menu(rest.get_current_user_amount(), current_user)
        tui.print_send_email_failed(username)
def do_high_scores():
    tui.clear()
    tui.print_menu(rest.get_current_user_amount(), current_user)
    tui.print_high_scores(rest.get_all_users_highscore())
def do_lobby():
    tui.clear()
    tui.print_menu(rest.get_current_user_amount(), current_user)
    tui.print_lobby(rest.get_all_logged_in_users_score())
def do_play():
    global current_user
    game.start(current_user)
    tui.clear()
    tui.print_menu(rest.get_current_user_amount(), current_user)
def do_about():
    tui.clear()
    tui.print_menu(rest.get_current_user_amount(), current_user)
    tui.print_about()
def do_user_information():
    global current_user
    tui.clear()
    tui.print_menu(rest.get_current_user_amount(), current_user)
    tui.print_user_information(current_user)
Beispiel #15
0
        dbFile.close()

    def save(self):
        outFile = open(self.name + ".csv", 'w', encoding="utf-8")
        for word in self.words.values():
            outFile.write(word.question + ';' + word.answer + ';' +
                          str(word.phase) + ';' + str(word.dueDate) + '\n')


phaseToTime = [86400, 259200, 864000, 2592000, 7776000, float("inf")]
db = {}

random.seed()

# Read and parse config file
tui.clear()
print("Reading config file...")
try:
    configFile = open("trainr.conf", 'r', encoding="utf-8")
except FileNotFoundError:
    configFile = open("trainr.conf", "w+", encoding="utf-8")
configRaw = configFile.read().splitlines()
config = {}
for line in configRaw:
    tmpLst = line.split('=', 1)
    for i, v in enumerate(tmpLst):
        tmpLst[i] = v.strip()
    config[tmpLst[0]] = tmpLst[1]
configFile.close()
del configRaw