Certainly! Here's an updated version with additional questions for each difficulty level:
import pygame
import random
# Initialize Pygame
pygame.init()
# Colors
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GRAY = (128, 128, 128)
# Screen dimensions
WIDTH = 800
HEIGHT = 600
# Set up the display
screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Quiz Game")
# Font styles
font = pygame.font.Font(None, 30)
question_font = pygame.font.Font(None, 40)
# Game variables
difficulty = None
current_question = 0
score = 0
# Quiz questions
questions = {
"easy": [
{"question": "What is the capital of France?", "answers": ["Paris", "Berlin", "London"], "correct": "Paris"},
{"question": "Which planet is known as the red planet?", "answers": ["Mars", "Venus", "Jupiter"], "correct": "Mars"},
{"question": "What is the symbol for sodium?", "answers": ["Na", "So", "No"], "correct": "Na"},
{"question": "Which animal is known as the 'ship of the desert'?", "answers": ["Camel", "Horse", "Elephant"], "correct": "Camel"},
{"question": "What is the square root of 144?", "answers": ["12", "16", "10"], "correct": "12"},
# Add more easy questions
],
"normal": [
{"question": "What is the largest ocean?", "answers": ["Pacific Ocean", "Indian Ocean", "Atlantic Ocean"], "correct": "Pacific Ocean"},
{"question": "Which country is home to the kangaroo?", "answers": ["Australia", "Brazil", "Mexico"], "correct": "Australia"},
{"question": "What is the atomic number of gold?", "answers": ["79", "80", "81"], "correct": "79"},
{"question": "Which fictional detective lived at 221B Baker Street?", "answers": ["Sherlock Holmes", "Hercule Poirot", "Miss Marple"], "correct": "Sherlock Holmes"},
{"question": "What is the national flower of India?", "answers": ["Lotus", "Rose", "Tulip"], "correct": "Lotus"},
# Add more normal questions
],
"hard": [
{"question": "How many bones are there in the human body?", "answers": ["206", "214", "198"], "correct": "206"},
{"question": "What is the symbol for potassium?", "answers": ["K", "Pt", "P"], "correct": "K"},
{"question": "Who is the author of the novel 'To Kill a Mockingbird'?", "answers": ["Harper Lee", "Jane Austen", "George Orwell"], "correct": "Harper Lee"},
{"question": "Which element has the highest melting point?", "answers": ["Tungsten", "Titanium", "Platinum"], "correct": "Tungsten"},
{"question": "Which scientist formulated the theory of general relativity?", "answers": ["Albert Einstein", "Isaac Newton", "Marie Curie"], "correct": "Albert Einstein"},
# Add more hard questions
]
}
# Main menu
def main_menu():
while True:
screen.fill(BLACK)
title_text = font.render("Quiz Game", True, WHITE)
screen.blit(title_text, ((WIDTH - title_text.get_width()) // 2, 100))
# Difficulty buttons
button_easy = pygame.Rect((WIDTH - 200) // 2, 200, 200, 50)
pygame.draw.rect(screen, GRAY, button_easy)
button_easy_text = font.render("Easy", True, BLACK)
screen.blit(button_easy_text, (button_easy.x + (button_easy.width - button_easy_text.get_width()) // 2, button_easy.y + (button_easy.height - button_easy_text.get_height()) // 2))
button_normal = pygame.Rect((WIDTH - 200) // 2, 300, 200, 50)
pygame.draw.rect(screen, GRAY, button_normal)
button_normal_text = font.render("Normal", True, BLACK)
screen.blit(button_normal_text, (button_normal.x + (button_normal.width - button_normal_text.get_width()) // 2, button_normal.y + (button_normal.height - button_normal_text.get_height()) // 2))
button_hard = pygame.Rect((WIDTH - 200) // 2, 400, 200, 50)
pygame.draw.rect(screen, GRAY, button_hard)
button_hard_text = font.render("Hard", True, BLACK)
screen.blit(button_hard_text, (button_hard.x + (button_hard.width - button_hard_text.get_width()) // 2, button_hard.y + (button_hard.height - button_hard_text.get_height()) // 2))
pygame.display.flip()
# Event handling
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
elif event.type == pygame.MOUSEBUTTONDOWN:
if button_easy.collidepoint(pygame.mouse.get_pos()):
difficulty_selected("easy")
elif button_normal.collidepoint(pygame.mouse.get_pos()):
difficulty_selected("normal")
elif button_hard.collidepoint(pygame.mouse.get_pos()):
difficulty_selected("hard")
# Difficulty selected
def difficulty_selected(difficulty_selected):
global difficulty, current_question, score
difficulty = difficulty_selected
current_question = 0
score = 0
game_loop()
# Display question and answers
def display_question():
screen.fill(BLACK)
question_text = question_font.render(questions[difficulty][current_question]["question"], True, WHITE)
screen.blit(question_text, ((WIDTH - question_text.get_width()) // 2, 100))
choices = questions[difficulty][current_question]["answers"]
random.shuffle(choices)
choice_rects = []
for i, choice in enumerate(choices):
choice_rect = pygame.Rect((WIDTH - 300) // 2, 200 + (i * 60), 300, 50)
pygame.draw.rect(screen, GRAY, choice_rect)
choice_rects.append(choice_rect)
choice_text = font.render(choice, True, BLACK)
screen.blit(choice_text, (choice_rect.x + (choice_rect.width - choice_text.get_width()) // 2, choice_rect.y + (choice_rect.height - choice_text.get_height()) // 2))
pygame.display.flip()
return choice_rects
# Check if answer is correct
def check_answer(rects):
global score
for i, rect in enumerate(rects):
if rect.collidepoint(pygame.mouse.get_pos()):
user_answer = questions[difficulty][current_question]["answers"][i]
if user_answer == questions[difficulty][current_question]["correct"]:
score += 1
return True
else:
return False
# Game loop
def game_loop():
running = True
while running:
rects = display_question()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
quit()
elif event.type == pygame.MOUSEBUTTONDOWN:
if check_answer(rects):
print("Correct!")
else:
print("Incorrect!")
current_question += 1
if current_question >= len(questions[difficulty]):
running = False
print("Score:", score)
pygame.quit()
quit()
# Start the game
main_menu()
Feel free to add more questions to each difficulty level in the questions dictionary. Remember to follow the same format and include the question, a list of answer choices, and the correct answer.