Cs Project File
Cs Project File
Practical File
For
2024-2025 Examination
As a part of the Computer Science
Submitted by Submitted to
Name Ms. Ambika Gaur
Roll no.
XII
CERTIFICATE
This is to certify that Cadet ____________________
Roll No:____________ has successfully completed the Practical
Work entitled in the subject Computer Science (083) laid down
in the regulations of CBSE for the purpose of Practical
Examination in Class XII
TEACHER’S
S.NO. PROGRAM
SIGN.
1 Certificate
2 Acknowledgement
3 Introduction
5 Flow chart
6 Code input
7 Output
8 Bibliography
ACKNOWLEDGEMENT
Apart from the efforts of me, the success of any project depends largely on the
encouragement and guidelines of many others. I take this opportunity to
express my gratitude to the people who have been instrumental in the
successful completion of this project.
I express deep sense of gratitude to almighty God for giving me strength for
the successful completion of the project.
The guidance and support received from all the members who contributed and
who are contributing to this project, was vital for the success of the project. I
am grateful for their constant support and help.
INTRODUCTION
This Caterpillar Game is a really fun and interactive game made
in Python using the `turtle` graphics library.
The controls are super easy! You can use the arrow keys to move
the caterpillar and hit the spacebar to start a new game.
Gameplay is designed to be easy to understand, but it's full of
random leaf placement and rising challenges that keep things
interesting. You can see your current score and best score right
on the screen, updating as you play.
2. MOBILE PHONE
• SOFTWARE REQUIREMENTS
2. MySQL
3. MySQL-Connector-Python
FLOW-CHART
Code input
import turtle as t
import random as rd
import csv
import os
# Turtle setup
def setup_turtle_screen():
global caterpillar, leaf, text_turtle, score_turtle,
high_score_turtle
t.bgcolor('yellow')
caterpillar = t.Turtle()
caterpillar.shape('square')
caterpillar.color('red')
caterpillar.speed(0)
caterpillar.penup()
caterpillar.hideturtle()
leaf = t.Turtle()
leaf_shape = ((0, 0), (14, 2), (18, 6), (20, 20), (6, 18), (2, 14))
t.register_shape('leaf', leaf_shape)
leaf.shape('leaf')
leaf.color('green')
leaf.penup()
leaf.hideturtle()
leaf.speed(0)
text_turtle = t.Turtle()
text_turtle.write('Press SPACE to start', align='center',
font=('Arial', 16, 'bold'))
text_turtle.hideturtle()
score_turtle = t.Turtle()
score_turtle.hideturtle()
score_turtle.speed(0)
high_score_turtle = t.Turtle()
high_score_turtle.hideturtle()
high_score_turtle.speed(0)
# Get username
username = input("Enter your username: ")
# Initialize CSV
def initialize_csv():
"""Initialize the CSV file and load the high score."""
global high_score
if not os.path.exists(CSV_FILE):
with open(CSV_FILE, mode="w", newline="") as file:
writer = csv.writer(file)
writer.writerow(["Username", "Leaves Eaten"])
else:
with open(CSV_FILE, mode="r") as file:
reader = csv.DictReader(file)
for row in reader:
high_score = max(high_score, int(row["Leaves Eaten"]))
# Display score
def display_score(current_score):
score_turtle.clear()
score_turtle.penup()
x = (t.window_width() / 2) - 50
y = (t.window_height() / 2) - 50
score_turtle.setpos(x, y)
score_turtle.write(str(current_score), align='right', font=('Arial',
40, 'bold'))
# Start game
def start_game():
global game_started
if game_started:
return
game_started = True
score = 0
text_turtle.clear()
caterpillar_speed = 2
caterpillar_length = 3
caterpillar.shapesize(1, caterpillar_length, 1)
caterpillar.showturtle()
display_score(score)
display_high_score()
place_leaf()
while True:
caterpillar.forward(caterpillar_speed)
if caterpillar.distance(leaf) < 20:
place_leaf()
caterpillar_length += 1
caterpillar.shapesize(1, caterpillar_length, 1)
caterpillar_speed += 1
score += 10 # Award 10 points for each leaf eaten
display_score(score)
display_high_score()
if outside_window():
game_over()
save_score(score)
break
# Movement controls
def move_up():
if caterpillar.heading() == 0 or caterpillar.heading() == 180:
caterpillar.setheading(90)
def move_down():
if caterpillar.heading() == 0 or caterpillar.heading() == 180:
caterpillar.setheading(270)
def move_left():
if caterpillar.heading() == 90 or caterpillar.heading() == 270:
caterpillar.setheading(180)
def move_right():
if caterpillar.heading() == 90 or caterpillar.heading() == 270:
caterpillar.setheading(0)
2. GOOGLE
3. BLACKBOX AI
4. WIKIPEDIA
5. PYTHON (www.python.com)
6. MYSQL (www.mysql.com)