Project Overview
OverviewNan is a modular command-line application hosting multiple mini-games (such as Hangman and Number Guesser). The system includes a robust authentication and account creation module using JSON files for persistent data storage.
Skills Learned
Core ConceptsDuring this first-year project at Hogeschool Utrecht, I mastered the fundamentals of Python programming. I learned structured code design, handling external JSON file operations, and building complex CLI game loops.
User Management
AuthenticationThe core of the platform is the account management system. It validates user credentials and automatically registers new accounts if a username is not found in the database.
import json
def user_login_create_json(user_name, user_password):
file_path = 'account.json'
>>>>>>> 638effd4c78ec481bd4308ff95157772d0e6cd95
User Management & Scoring
Het systeem bevat een uitgebreid account-beheer dat niet alleen inlogs valideert, maar ook high-scores bijhoudt voor de verschillende games.
def user_account_handler(user_name, user_password):
file_path = "account.json"
with open(file_path, 'r+') as json_file:
data = json.load(json_file)
accounts = data["accountDetails"]
for user_account in accounts:
if user_account["username"] == user_name and user_account["password"] == user_password:
print(f"User found logging in, Welcome {user_name}")
return True
print("User not found creating account")
new_entry = {"username": user_name, "password": user_password}
accounts.append(new_entry)
json_file.seek(0)
json.dump(data, json_file, indent=2)
json_file.truncate()
Hangman (Galgje)
In Galgje wordt de voortgang visueel bijgehouden en kunnen gebruikers de woordenlijst dynamisch aanpassen door woorden toe te voegen of te verwijderen.
def show_progress(word, guessed_letters):
display = []
for letter in word:
if letter in guessed_letters:
display.append(letter.upper())
else:
display.append("_")
return " ".join(display)
=======
Number Guesser Game
Game Algorithm
The Guesser game incorporates dynamic difficulty levels, adaptive scoring algorithms, and automated player performance feedback.
guesser_game.py
Python
def calculate_score(difficulty_level, user_tries):
score = (user_max_tries(difficulty_level) - user_tries) * difficulty_level
print("Your score is: " + str(score))
>>>>>>> 638effd4c78ec481bd4308ff95157772d0e6cd95
def calculate_score(lives_left, difficulty):
return lives_left * difficulty
<<<<<<< HEAD
API Integration
Voor de Animal Facts quiz wordt de requests library gebruikt om vragen op te halen van een externe API. Dit introduceerde concepten zoals JSON parsing en HTTP status codes.
import requests
def start_api_animal(user_name):
response = requests.get("https://opentdb.com/api.php?amount=10&category=27&type=boolean")
data = response.json()
questions = data.get("results", [])
for item in questions:
question_text = html.unescape(item["question"])
correct_answer = item["correct_answer"]
user_answer = input(f"{question_text} (True/False): ")
# ... logic to check answer and update score
=======
if user_score < low_score:
return print("Try a lower difficulty")
elif low_score <= user_score <= normal_score:
return print("Keep this difficulty")
else:
return print("Advice: you can handle a higher difficulty level!")
>>>>>>> 638effd4c78ec481bd4308ff95157772d0e6cd95