Update benstypcurses.py
This commit is contained in:
+96
-9
@@ -1,6 +1,7 @@
|
|||||||
from db import nederlandse_woorden
|
from db import nederlandse_woorden
|
||||||
import random
|
import random
|
||||||
import time
|
import time
|
||||||
|
from db import woorden
|
||||||
|
|
||||||
RED = "\033[31m"
|
RED = "\033[31m"
|
||||||
GREEN = "\033[32m"
|
GREEN = "\033[32m"
|
||||||
@@ -69,15 +70,99 @@ def start(aantal):
|
|||||||
print(f"gemiddelde tijd per woord: {MAGENTA}{BOLD}{gem_tijd}{RESET}")
|
print(f"gemiddelde tijd per woord: {MAGENTA}{BOLD}{gem_tijd}{RESET}")
|
||||||
print(f"accuracy: {accuracy_kleur}{BOLD}{accuracy}%{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"""
|
menu = f"""
|
||||||
bens typcurses
|
bens typcurses
|
||||||
|
|
||||||
{UNDERLINE}Menu:{RESET}
|
{UNDERLINE}Menu:{RESET}
|
||||||
1. Start 100 woorden
|
1. Start 50 woorden
|
||||||
2. Start 200 woorden
|
2. Start kies aantal woorden
|
||||||
3. Start alle woorden
|
3. laad eigen woorden (nog niet)
|
||||||
4. Start kies aantal woorden
|
4. zinnen (beta)
|
||||||
5. {BOLD}Afsluiten{RESET}
|
5. {BOLD}Afsluiten{RESET}
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@@ -95,12 +180,14 @@ while True:
|
|||||||
if menu_keuze > 5 or menu_keuze < 1:
|
if menu_keuze > 5 or menu_keuze < 1:
|
||||||
print("gekozen optie bestaat niet, probeer opnieuw.\n")
|
print("gekozen optie bestaat niet, probeer opnieuw.\n")
|
||||||
elif menu_keuze == 1:
|
elif menu_keuze == 1:
|
||||||
start(100)
|
start(50)
|
||||||
elif menu_keuze == 2:
|
|
||||||
start(200)
|
|
||||||
elif menu_keuze == 3:
|
|
||||||
start(len(nederlandse_woorden))
|
|
||||||
elif menu_keuze == 4:
|
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? :")))
|
start(int(input("hoeveel woorden? :")))
|
||||||
elif menu_keuze == 5:
|
elif menu_keuze == 5:
|
||||||
break
|
break
|
||||||
|
|||||||
Reference in New Issue
Block a user