cs
cs
Certificate of Completion
This to certify that Ms / Mstr. ______________________
_______________________ has completed his Computer
Science project titled ______________________________
______ successfully under my supervision towards the
award of AISSCE for the session 2024 -2025.
1
INDEX
1 Introduction to project
4 Flow of control
5 Source code
6 Output screenshots
7 Conclusion
11 Bibliography
INTRODUCTION
• Project Title: LearnPython Adventure
Category: Educational Game
Technology: Python (Pygame for graphics and interactivity)
• Overview:
• "LearnPython Adventure" is an interactive and engaging game designed to
help beginners learn Python programming while having fun. The game takes
players on an adventure where they solve coding challenges and puzzles to
progress through different levels. Each level introduces a new Python
concept, from basic syntax to more advanced topics like loops, conditionals,
functions, and object-oriented programming.
• The game uses a role-playing game (RPG) format, where players control a
character navigating through various environments, encountering obstacles
that require coding solutions. By solving these obstacles (in the form of
Python programming tasks), players unlock new areas and gain in-game
rewards, such as power-ups, new skills, or character upgrades.
• Objectives:
1. Interactive Learning: Players will solve coding challenges that are designed
to teach Python concepts in a hands-on, practical way.
2. Problem Solving: The game will encourage critical thinking and logic-
building, which are essential skills in programming.
3. Engagement: Through its RPG-style gameplay, players are motivated to learn
by exploring new concepts and overcoming obstacles in a fun and interactive
environment.
4. Instant Feedback: As players complete coding challenges, the game provides
immediate feedback, guiding them toward the correct solution and
reinforcing learning.
5. Track record. As the player uses its login id all the data of it question
attempted are saved so the player can track his progress
1
SOFTWARE AND
HARDWARE
• Software:
1.Python Programming Language
Purpose: The primary programming language used for
game logic, solving challenges, and managing gameplay.
Python is chosen for its simplicity and ease of learning,
making it ideal for educational games like this.
2.Pygame Library
Purpose: Pygame is a set of Python modules designed
for writing video games. It provides functionality for
handling graphics, sound, and user inputs, making it
ideal for game development.
3.Text Editor: VS CODE
4.Purpose: These tools are used to write, edit, and debug the
Python code for the game.
3
09-01-2025
MODULES AND
FUNCTIONS
• Pygame Module
• The Pygame library is the main module used for
handling graphics, input devices, events, and overall
game flow. Here are some of the key functions and
features of Pygame used in this project:
• pygame.display.set_mode()
• Sys Module
09-01-2025 4
FLOW OF CONTROL
1.The game begins by initializing Pygame and setting up
the display.
2.The intro screen is shown, waiting for the player to
press a key to start the game.
3.In the main game loop, the game presents challenges,
accepts player answers, checks correctness, and handles
level progression.
4.If the player answers all challenges correctly, the game
proceeds to the end screen, congratulates the player, and
exits.
5.Events (like key presses and window closure) are
handled throughout using the pygame.event.get()
function.
This flow allows for a smooth transition between game
stages, providing an interactive experience for the player
to learn Python while playing
5
import pygame
import sys
import csv
pygame.init()
# Constants
SCREEN_WIDTH = 1080
SCREEN_HEIGHT = 600
screen = pygame.display.set_mode((SCREEN_WIDTH, SCREEN_HEIGHT))
pygame.display.set_caption("Code Quest: The Puzzle Land")
•.
WHITE = (255, 255, 255)
BLACK = (0, 0, 0)
GREEN = (0, 255, 0)
RED = (255, 0, 0)
BLUE = (0, 0, 255)
YELLOW = (255, 255, 0)
font = pygame.font.SysFont('Arial', 24)
button_font = pygame.font.SysFont('Arial', 32)
FPS = 60
clock = pygame.time.Clock()
# Background and Player images
background_path = r'D:\Aayush School & Others\python\AI\bg.jpg' # Replace
with your background path
character_path = r'C:\Users\sachi_9ikq2t5\Downloads\pngwing.com.png' #
Replace with your character image path
flag_image_path = r'D:\Aayush School & Others\python\AI\flag.png' #
Replace with your flag image path
background_img = pygame.image.load(background_path)
character_img = pygame.image.load(character_path)
flag_img = pygame.image.load(flag_image_path)
# Scale the flag image
FLAG_WIDTH = 50
FLAG_HEIGHT = 100
flag_img = pygame.transform.scale(flag_img, (FLAG_WIDTH, FLAG_HEIGHT))
Scale the character image to a reasonable size
PLAYER_WIDTH = 150
PLAYER_HEIGHT = 110
character_img = pygame.transform.scale(character_img, (PLAYER_WIDTH,
PLAYER_HEIGHT))
# Player variables
points = 0
player_x = SCREEN_WIDTH // 2
player_y = SCREEN_HEIGHT // 2
player_speed = 5
current_level = 0
7
# Function to draw the player
def draw_player(x, y):
screen.blit(character_img, (x, y))
# Function to draw a button
def draw_button(text, position, width, height, color, font=button_font):
pygame.draw.rect(screen, color, (position[0], position[1], width, height))
draw_text(text, (position[0] + 10, position[1] + 10), BLACK, font)
# Function to check if mouse is inside a rectangle
def is_mouse_over_button(position, width, height):
•.
mouse_x, mouse_y = pygame.mouse.get_pos()
return position[0] <= mouse_x <= position[0] + width and position[1] <= mouse_y <=
position[1] + height
# Function to ask for login and save it to CSV
def ask_for_login():
login_input = ""
while True:
screen.fill(BLACK)
draw_text("Enter your login ID:", (350, 250), WHITE)
draw_text(f"Login: {login_input}", (350, 300), WHITE)
draw_button("Start Game", (400, 350), 200, 50, BLUE)
pygame.display.flip()
for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
elif event.type == pygame.KEYDOWN:
if event.key == pygame.K_RETURN and login_input.strip(): # Enter key to
submit
save_login_to_csv(login_input.strip()) # Save login to CSV
return login_input.strip()
elif event.key == pygame.K_BACKSPACE: # Backspace to delete last
character
login_input = login_input[:-1]
elif event.unicode.isalnum() or event.key == pygame.K_SPACE: #
Alphanumeric or space allowed
login_input += event.unicode
# Save the login and points to a CSV file
def save_login_to_csv(login_id):
with open(r'D:\Aayush School & Others\python\AI\logins.csv', mode='a', newline='') as
file:
writer = csv.writer(file)
writer.writerow([login_id, points])
# Define question areas and levels
question_areas = [
pygame.Rect(100, 100, 200, 100), # Area 1 for Level 1
pygame.Rect(300, 100, 200, 100), # Area 2 for Level 2
pygame.Rect(500, 100, 200, 100), # Area 3 for Level 3
pygame.Rect(100, 300, 200, 100), # Area 4 for Level 4
pygame.Rect(300, 300, 200, 100), # Area 5 for Level 5
pygame.Rect(700, 200, 200, 100), # Area 6 for Level 6
pygame.Rect(700, 400, 200, 100), # Area 7 for Level 7
7
pygame.Rect(50, 400, 200, 100), # Area 8 for Level 8
]
level_puzzles = [
# Level 1
[{"question": "What does the 'print' function do in Python?", "answer":
"Displays output"},
{"question": "How do you start a comment in Python?", "answer": "#"},],
# Level 2
•.
[{"question": "Which keyword is used to define a function in Python?",
"answer": "def"},
{"question": "What does 'len()' function do?", "answer": "Returns length of
an object"},
{"question": "Which operator is used for exponentiation in Python?",
"answer": "**"},],
# Level 3
[{"question": "What is the purpose of the 'if' statement in Python?",
"answer": "Conditional execution"},
{"question": "What is the output of 5 // 2 in Python?", "answer": "2"},
{"question": "How do you create a list in Python?", "answer": "Using square
brackets"},
{"question": "What does 'continue' do in a loop?", "answer": "Skips the
current iteration"},],
# Level 4
[{"question": "What is a tuple in Python?", "answer": "Immutable sequence of
elements"},
{"question": "How do you handle exceptions in Python?", "answer": "Using
try/except"},],
# Level 5
[{"question": "What is a dictionary in Python?", "answer": "Collection of key-
value pairs"},
{"question": "How do you define a class in Python?", "answer": "Using the
'class' keyword"},
{"question": "What is the output of 7 % 3?", "answer": "1"},],
# Level 6
[{"question": "What is the purpose of 'import' in Python?", "answer": "To
include external libraries"},
{"question": "What does 'lambda' function do?", "answer": "Defines an
anonymous function"},},
# Level 7
[{"question": "What does 'self' represent in a Python class?", "answer":
"Instance of the class"},
{"question": "What is a decorator in Python?", "answer": "A function that
modifies another function"},],
# Level 8
[{"question": "What is the purpose of the 'global' keyword?", "answer": "To
declare a variable as global"},
{"question": "What does 'yield' do in Python?", "answer": "Returns a generator
object"},],]
7
# Function to draw flags for the questions
def draw_flag(area):
screen.blit(flag_img, (area.centerx - FLAG_WIDTH // 2,
area.centery - FLAG_HEIGHT // 2)) # Center flag on area
# Game loop
while current_level < len(level_puzzles):
•. for event in pygame.event.get():
if event.type == pygame.QUIT:
pygame.quit()
sys.exit()
pygame.display.flip()
clock.tick(FPS)
# Function to show a question and get the answer
def show_question(puzzle):
global points
answer_text = ""
puzzle_solved = False
incorrect_attempts = 0 # Counter for incorrect attempts
7
while not puzzle_solved:
screen.fill(WHITE)
draw_text(puzzle["question"], (50, 100))
draw_text(f"Answer: {answer_text}", (50, 150))
draw_text("Press ENTER to submit, ESC to cancel", (50, 200))
pygame.display.flip()
if incorrect_attempts >= 2:
draw_text("Too many incorrect attempts. Exiting
game.", (100, 250), color=RED)
pygame.display.flip()
pygame.time.wait(2000)
pygame.quit() # Exit the game after 2 incorrect
attempts
sys.exit()
main()
7
CONCLUSION
The primary objective of this game is to help players learn Python by
playing a fun and engaging game. Through the various levels and
challenges, players are exposed to basic python concepts
Interactive Learning Environment:The game's structure encourages
hands-on learning:Players actively input answers and solve problems
within the game.Immediate feedback helps reinforce concepts by
showing when the player is correct or needs to retry.
In conclusion, the "LearnPython Adventure" game represents an
innovative approach to learning programming. By gamifying the
learning process, the project transforms the sometimes daunting task
of learning Python into an enjoyable and rewarding experience. The
success of this game demonstrates how interactive and educational
games can make complex subjects more accessible, engaging, and
fun.
This project lays a solid foundation for future developments, with the
potential for expansion in content, features, and platforms. As the
game evolves, it can become an even more powerful tool for both
beginners and intermediate learners seeking to improve their Python
skills through play.
12
Bibliography
• Chatgpt
• Bing
• Youtube
13
09-01-2025