Project Overview
Overview
Nan is a modular command-line application hosting multiple mini-games. The system includes an automated authentication and account creation module using JSON files for persistent data storage.
Skills Learned
Core ConceptsDuring this first-year project at Hogeschool Utrecht, I deepened my fundamentals of Python programming. I mastered structured modular code design across multiple modules, external API integration (such as OpenWeather and OpenTDB), and handling persistent JSON data structures.
User Management & Scoring
AuthenticationThe core of the platform is the account management system. It validates user credentials, tracks high scores across mini-games, and automatically registers new accounts if a username is not found in the database.
import json
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()
Number Guesser Game
Game AlgorithmThe Guesser game incorporates dynamic difficulty levels, adaptive scoring algorithms, and automated player performance feedback based on attempt counts.
def calculate_score(difficulty_level, user_tries):
score = (user_max_tries(difficulty_level) - user_tries) * difficulty_level
print("Your score is: " + str(score))
def calculate_difficulty(user_score):
low_score = 5
normal_score = 12
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!")
Hangman (Galgje)
Game LogicIn Hangman, player progress is tracked visually as letters are guessed. Users can dynamically customize the active word list by adding or removing vocabulary.
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)
def calculate_score(lives_left, difficulty):
return lives_left * difficulty
API Integration
REST API
The Animal Facts quiz uses the Python requests library to fetch dynamic trivia questions from the OpenTDB REST API, exploring asynchronous network requests and JSON response parsing.
import requests
import html
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