from db import nederlandse_woorden import random import time from db import woorden RED = "\033[31m" GREEN = "\033[32m" BLUE = "\033[34m" RESET = "\033[0m" BOLD = "\033[1m" UNDERLINE = "\033[4m" YELLOW = "\033[33m" MAGENTA = "\033[35m" CYAN = "\033[36m" def start(aantal): print(BOLD + "Typ het woord over:" + RESET) print() woorden = random.sample(nederlandse_woorden, aantal) goed = 0 fout = 0 tijd_start_volledig = time.time() for woord in woorden: print(BOLD + YELLOW + woord + RESET) print() start_tijd = time.time() gegeven = input(" > " + UNDERLINE).strip() print(RESET) eind_tijd = time.time() tijd = round(eind_tijd - start_tijd, 2) if gegeven == woord: print(f"{GREEN}{BOLD}Goed! {RESET}Tijd: {tijd} seconden") print() goed += 1 elif gegeven == "exit": break elif gegeven == "quit": break elif gegeven == "break": break else: fout += 1 print(f"{RED}{BOLD}Fout!{RESET} Het juiste woord was: {woord}") print(f"Tijd: {tijd} seconden") print() tijd_stop_volledig = time.time() totale_tijd = round(tijd_stop_volledig - tijd_start_volledig, 2) gem_tijd = round(totale_tijd / len(woorden), 2) totaal = goed + fout accuracy = round((goed / totaal) * 100, 2) if totaal > 0 else 0 if accuracy >= 55: accuracy_kleur = GREEN else: accuracy_kleur = RED print() print(f"totaal goed: {GREEN}{BOLD}{goed}{RESET}") print(f"totaal fout: {RED}{BOLD}{fout}{RESET}") print(f"totale tijd: {MAGENTA}{BOLD}{totale_tijd}{RESET}") print(f"gemiddelde tijd per woord: {MAGENTA}{BOLD}{gem_tijd}{RESET}") print(f"accuracy: {accuracy_kleur}{BOLD}{accuracy}%{RESET}") def random_zinnen(aantal): gemaaktezinnen = [] for _ in range(aantal): onderwerp = random.choice(woorden["znw"]) werkwoord = random.choice(woorden["ww"]) plaats = random.choice(woorden["vz"]) + " " + random.choice(woorden["znw"]) zin = onderwerp + " " + werkwoord + " " + plaats gemaaktezinnen.append(zin[0].upper() + zin[1:] + ".") return gemaaktezinnen def zinnen(zinnen_lijst): import curses def run(stdscr): curses.curs_set(1) curses.start_color() curses.use_default_colors() curses.init_pair(1, curses.COLOR_WHITE, curses.COLOR_BLACK) # nog niet getypt curses.init_pair(2, curses.COLOR_BLUE, curses.COLOR_BLACK) # correct curses.init_pair(3, curses.COLOR_BLACK, curses.COLOR_RED) # fout curses.init_pair(4, curses.COLOR_GREEN, curses.COLOR_BLACK) # compleet goed for zin in zinnen_lijst: typed = "" while True: stdscr.clear() y, x = 2, 0 done = typed == zin if done: stdscr.addstr(y, x, zin, curses.color_pair(4) | curses.A_BOLD) stdscr.refresh() curses.curs_set(0) curses.napms(700) break for i in range(len(zin)): correct_char = zin[i] if i >= len(typed): ch = correct_char if correct_char != " " else " " stdscr.addstr( y, x + i, ch, curses.color_pair(1) | curses.A_UNDERLINE ) else: user_char = typed[i] if user_char == correct_char: stdscr.addstr(y, x + i, user_char, curses.color_pair(2)) else: display = user_char if user_char != " " else "ยท" stdscr.addstr( y, x + i, display, curses.color_pair(3) | curses.A_BOLD ) stdscr.move(y, x + len(typed)) stdscr.refresh() key = stdscr.get_wch() if isinstance(key, str) and key.isprintable(): typed += key elif key in ("\n", "\r"): if typed == zin: break elif key in (curses.KEY_BACKSPACE, "\b", 127): typed = typed[:-1] curses.wrapper(run) menu = f""" bens typcursus {UNDERLINE}Menu:{RESET} 1. Start 50 woorden 2. Start kies aantal woorden 3. laad eigen woorden (nog niet) 4. zinnen (beta) 5. {BOLD}Afsluiten{RESET} """ while True: print(menu) menu_keuze = input(" > ").strip() if not menu_keuze.isdigit(): print("Voer een nummer in.\n") continue menu_keuze = int(menu_keuze) if menu_keuze > 5 or menu_keuze < 1: print("gekozen optie bestaat niet, probeer opnieuw.\n") elif menu_keuze == 1: start(50) elif menu_keuze == 4: aantal = int(input("hoeveel zinnen? :")) zinnen(random_zinnen(aantal)) # elif menu_keuze == 3: # plek = ("bestand: ") # import plek elif menu_keuze == 2: start(int(input("hoeveel woorden? :"))) elif menu_keuze == 5: break