Finished the two main gamemodes and added a menu system

This commit is contained in:
Lyx committed 2025-03-21 17:01:20 +01:00
1 parent 767d49b6be
commit a69b711289
6 files changed
+189 -32

No files matched your search

+2 -1
View File
@@ -1,2 +1,3 @@
__pychace__ __pychace__
*.pyc *.pyc
.venv
+12 -1
View File
@@ -1,7 +1,6 @@
from alphabet import alphabet from alphabet import alphabet
from os import system, name from os import system, name
def binarian(word): def binarian(word):
wordBin = "" wordBin = ""
word = word.lower() word = word.lower()
@@ -14,6 +13,18 @@ def binarian(word):
wordBin += letter wordBin += letter
return wordBin return wordBin
import re
def unbinarian(encoded_text):
from alphabet import alphabet
reverse_alphabet = {v: k for k, v in alphabet.items()}
decoded = re.sub(r"\(\d{5}\)", lambda m: reverse_alphabet.get(m.group(), m.group()), encoded_text)
return decoded
def clear(): def clear():
# for windows # for windows
+17 -6
View File
@@ -5,10 +5,7 @@ from functions import binarian
from functions import clear from functions import clear
def norToBin(level): def norToBin(level):
wordsInLevel = [] wordsInLevel = words[level].copy()
for word, word_level in words.items():
if word_level == level:
wordsInLevel.append(word)
word = random.choice(wordsInLevel) word = random.choice(wordsInLevel)
correctTranslation = binarian(word) correctTranslation = binarian(word)
@@ -18,6 +15,20 @@ def norToBin(level):
if userIn == correctTranslation: if userIn == correctTranslation:
print(f'Yes the word {word} does translate to {userIn}!') print(f'Yes the word {word} does translate to {userIn}!')
else: else:
print(f'No, the word {word} translates to {correctTranslation}. Better study some more!') print(f'No, the word {word} translates to {correctTranslation}, not {userIn}. Better study some more!')
input("Hit ENTER to continue")
norToBin(2) def binToNor(level):
wordsInLevel = words[level].copy()
word = random.choice(wordsInLevel)
correctTranslation = word
word = binarian(word)
print(f'Translate {word} into english!')
userIn = input("Write anwser\n>")
clear()
if userIn == correctTranslation:
print(f'Yes the word {word} does translate to {userIn}!')
else:
print(f'No, the word {word} translates to {correctTranslation}, not {userIn}. Better study some more!')
input("Hit ENTER to continue")
+38 -2
View File
@@ -1,4 +1,40 @@
from functions import binarian from functions import binarian
from alphabet import alphabet from functions import unbinarian
from submenus import entoBin
from submenus import binToEn
from functions import clear
import readchar
print(binarian("I am making duolingo for binary")) def main_menu():
options = ["Translate from English to Binarian", "Translate from Binarian to English", "Exit"]
selected = 0
while True:
clear()
print("Use arrow keys to navigate and Enter to select:\n")
for i, option in enumerate(options):
prefix = "> " if i == selected else " "
print(f"{prefix}{option}")
key = readchar.readkey()
if key == readchar.key.UP and selected > 0:
selected -= 1
elif key == readchar.key.DOWN and selected < len(options) - 1:
selected += 1
elif key == readchar.key.ENTER:
if options[selected] == "Exit":
print("Exiting...")
clear()
break
elif options[selected] == "Translate from English to Binarian":
entoBin()
elif option[selected == "Translate from Binarian to English"]:
binToEn()
else:
print(f"Selected: {options[selected]}")
input("Press Enter to return to menu...")
if __name__ == "__main__":
main_menu()
+85
View File
@@ -0,0 +1,85 @@
import readchar
from gamemodes import norToBin
from gamemodes import binToNor
from functions import clear
def entoBin():
options = ["Level 1", "Level 2", "Level 3","Level 4", "Level 5" , "Back to main menu"]
selected = 0
while True:
clear()
print("Select a level to start translating!")
print("Use arrow keys to navigate and Enter to select:\n")
for i, option in enumerate(options):
prefix = "> " if i == selected else " "
print(f"{prefix}{option}")
key = readchar.readkey()
if key == readchar.key.UP and selected > 0:
selected -= 1
elif key == readchar.key.DOWN and selected < len(options) - 1:
selected += 1
elif key == readchar.key.ENTER:
if options[selected] == "Level 1":
clear()
norToBin(1)
elif options[selected] == "Level 2":
clear()
norToBin(2)
elif options[selected] == "Level 3":
clear()
norToBin(3)
elif options[selected] == "Level 4":
clear()
norToBin(4)
elif options[selected] == "Level 5":
clear()
norToBin(5)
elif options[selected] == "Back to main menu":
print("Exiting...")
break
else:
print(f"Selected: {options[selected]}")
def binToEn():
options = ["Level 1", "Level 2", "Level 3","Level 4", "Level 5" , "Back to main menu"]
selected = 0
while True:
clear()
print("Select a level to start translating!")
print("Use arrow keys to navigate and Enter to select:\n")
for i, option in enumerate(options):
prefix = "> " if i == selected else " "
print(f"{prefix}{option}")
key = readchar.readkey()
if key == readchar.key.UP and selected > 0:
selected -= 1
elif key == readchar.key.DOWN and selected < len(options) - 1:
selected += 1
elif key == readchar.key.ENTER:
if options[selected] == "Level 1":
clear()
binToNor(1)
elif options[selected] == "Level 2":
clear()
binToNor(2)
elif options[selected] == "Level 3":
clear()
binToNor(3)
elif options[selected] == "Level 4":
clear()
binToNor(4)
elif options[selected] == "Level 5":
clear()
binToNor(5)
elif options[selected] == "Back to main menu":
print("Exiting...")
break
else:
print(f"Selected: {options[selected]}")
+35 -22
View File
@@ -1,24 +1,37 @@
words = { words = {
"cat": 1, 1: [
"dog": 1, "aa", "add", "all", "ass", "bell", "book", "boss", "call", "cell", "cool",
"fish": 1, "deed", "door", "doll", "egg", "fall", "feed", "fool", "good", "hall", "hill",
"apple": 1, "jazz", "kiss", "lass", "look", "mall", "mess", "mood", "moon", "pass", "pool",
"ball": 1, "quiz", "reed", "root", "seed", "sell", "soon", "tall", "tool", "wall", "wood",
"house": 2, "yell", "zoom", "beer", "boil", "bull", "cull", "dull", "fell", "gull", "will"
"school": 2, ],
"tree": 2, 2: [
"friend": 2, "apple", "badge", "beast", "brass", "bread", "bribe", "broom", "cabin", "camel", "candy",
"computer": 3, "cello", "chalk", "charm", "chess", "clerk", "cloak", "clown", "crash", "demon", "drain",
"programming": 3, "drink", "dwarf", "eagle", "earth", "fable", "flame", "frost", "glove", "grand", "grape",
"language": 3, "haunt", "hotel", "hover", "image", "jelly", "juice", "latch", "lemon", "magic", "mango",
"chicken": 3, "merry", "music", "ocean", "onion", "penny", "plaza", "rider", "robot", "shadow", "spine"
"celebrate": 4, ],
"dinosaur": 4, 3: [
"philosophy": 4, "ankle", "arise", "arrow", "baker", "basil", "beech", "bison", "blaze", "bloom", "brittle",
"challenge": 4, "bubble", "cactus", "canvas", "carrot", "cedar", "cherry", "circle", "coral", "cotton", "dancer",
"understanding": 5, "detour", "donkey", "dragon", "drawer", "eclair", "elixir", "fencer", "fiddle", "frozen", "guitar",
"universe": 5, "hazard", "helmet", "insect", "island", "jigsaw", "ladder", "lawyer", "legend", "marble", "mirror",
"consciousness": 5, "needle", "nickel", "orchid", "pencil", "pirate", "planet", "prince", "puzzle", "rescue", "rocket"
"mathematics": 5, ],
"microprocessor": 5 4: [
"abstract", "alchemy", "bachelor", "blueprint", "brisket", "cascade", "chopper", "clarity", "compass", "complex",
"cosmos", "crystal", "dolphin", "emerald", "fathom", "feather", "flamingo", "furnace", "gazelle", "gorilla",
"harpoon", "horizon", "iceberg", "incisor", "jasmine", "juggler", "kangaroo", "lantern", "lobster", "luminous",
"meadow", "midnight", "nebula", "nomadic", "obelisk", "octagon", "paradox", "parrot", "phoenix", "pioneer",
"porcupine", "quasar", "radiant", "rhapsody", "sapphire", "satchel", "sheriff", "spectrum", "tempest", "vortex"
],
5: [
"abundance", "adventure", "arithmetic", "blacksmith", "butterfly", "catastrophe", "chandelier", "chromatic", "conductor", "constellation",
"delirious", "dynamism", "elaborate", "electricity", "ephemeral", "excursion", "firebrand", "fossilized", "geography", "handcrafted",
"illuminate", "inevitable", "jeopardize", "journalist", "labyrinth", "magnificent", "metaphor", "momentous", "nightshade", "noteworthy",
"opportunity", "philosophy", "quintuplet", "resilience", "silhouette", "sophisticated", "subterranean", "symmetry", "tapestries", "thunderbolt",
"trapezoidal", "translucent", "ubiquitous", "vulnerability", "wanderlust", "whimsical", "wilderness", "xylophone", "zephyr", "zoological"
]
} }