cs project
cs project
NITHEESH.S , CLASS XI
SRIMATHI SUNDARAVALLI MEMORIAL SCHOOL
CHENNAI
S.NO CONTENT PAGE.NO
1 OVERVIEW OF PYTHON
2 ABSTRACT
3 REQUIREMENTS
4 MODULES
5 BUILT IN
6 SOURCE CODE
7 OUTPUT
8 CONCLUSION
9 FUTURE OUTLOOK
10 REFERENCES
OVERVIEW OF PYTHON
Python is a versatile, high-level programming language that is
widely used across various fields due to its simplicity, readability,
and extensive library support. Created by Guido van Rossum and
first released in 1991, Python is designed to be easy to learn and
use, making it an excellent choice for both beginners and
experienced programmers. Below is an overview of its key features,
uses, and strengths
1.KEY FEATURES
Simple Syntax: Python’s syntax is clean and readable, which enhances
developer productivity. Unlike other languages, Python doesn’t use braces to
define code blocks; instead, it relies on indentation, making the code visually
structured.
Interpreted Language: Python code is executed line by line by an interpreter.
This makes debugging easier and allows for rapid development since there is
no need to compile the code.
Dynamic Typing: In Python, variable types are determined at runtime,
meaning you don't have to explicitly declare the type of a variable. This
flexibility makes it easier to write code quickly.
Object-Oriented: Python supports object-oriented programming (OOP)
principles, such as classes, inheritance, and polymorphism, making it suitable
for both small scripts and large software projects.
Cross-Platform: Python can run on multiple platforms, including Windows,
macOS, and Linux. The same Python code can be executed on different
systems with minimal or no modification.
Extensive Standard Library: Python comes with a comprehensive standard
library that provides modules for tasks such as file handling, regular
expressions, networking, and more, which significantly reduces development
time.
Community and Ecosystem: Python has an active, large community that
contributes to a rich ecosystem of third-party libraries and frameworks. The
Python Package Index (PyPI) contains thousands of packages for various use
cases, including web development, data analysis, machine learning, and more.
STRENGTHS OF PYTHON
Rapid Development: Python allows for quick prototyping and iteration. Its
dynamic typing and extensive libraries help developers build applications
faster.
Readable Code: Python emphasizes readability, which not only reduces the
chances of bugs but also makes it easier for teams to collaborate on large
projects.
Large Community and Support: The Python community is one of the largest in
the programming world. This means abundant resources, tutorials,
documentation, and forums are available to help with any programming
challenges.
CONCLUSION
DEVICE SPECIFICATIONS:
WINDOWS SPECIFICATION:
Use: Used for interacting with the Python runtime environment. It's
primarily used in this program to handle system-specific parameters, like
the sys.exit() method for quitting the program and sys.executable to call
the Python executable for installing missing modules.
2. subprocess:
3. importlib.util:
Use: Used to check whether a specific module (in this case pygame) is
available before importing it. It allows checking the presence of modules
dynamically to prevent errors.
4. math:
5. pygame:
Use: The main library used to create the graphical user interface and
handle game mechanics. It provides functions for handling graphics (e.g.,
drawing shapes), event handling (e.g., keyboard inputs), and game
management (e.g., setting up the game screen, managing game loops,
and controlling frame rate).
6. time:
subprocess.check_call(args)
• Runs the command passed as a list (args) and waits for it to complete. In
this case, it’s used to install missing modules by running pip install
<module>.
sys.exit([status])
• Exits the program. status can be passed to indicate the exit status (non-
zero values typically indicate errors).
pygame.init()
pygame.display.set_caption(title)
• Sets the window title. In your program, it sets the title to "Pong Game".
pygame.mouse.set_visible(value)
• Sets whether the mouse cursor is visible or not. In the program, the
cursor visibility is controlled based on the game state.
pygame.time.Clock()
• Creates a clock object to control the frame rate of the game (60 FPS in
this case).
pygame.font.Font(name, size)
• Creates a font object to render text. It’s used throughout the program to
render text like scores, titles, and messages.
pygame.event.get()
• Returns a list of all the events that have occurred. It is used to process
events like quitting the game or keypresses.
pygame.key.get_pressed()
• Draws an ellipse on the surface. It’s used for drawing the ball in the
game.
pygame.mouse.get_pos()
pygame.time.get_ticks()
pygame.init()
pygame.mouse.set_visible(True)
clock = pygame.time.Clock()
left_score, right_score = 0, 0
MODE_SINGLE_PLAYER = 1 MODE_TWO_PLAYER = 2
GAME_STATE_PLAYING = 0 GAME_STATE_PAUSED = 1
GAME_STATE_SETTINGS = 2
# Create buttons
single_player_button = pygame.Rect(WIDTH//2 - BUTTON_WIDTH - 20,
HEIGHT//2, BUTTON_WIDTH, BUTTON_HEIGHT)
two_player_button = pygame.Rect(WIDTH//2 + 20, HEIGHT//2,
BUTTON_WIDTH, BUTTON_HEIGHT)
while home_running:
mouse_pos = pygame.mouse.get_pos()
mouse_clicked = False
if mouse_clicked:
if single_player_hover:
selected_mode = MODE_SINGLE_PLAYER
home_running = False
elif two_player_hover:
selected_mode = MODE_TWO_PLAYER
home_running = False
# Display home screen
screen.fill(BLACK)
title_text = font.render("Welcome to Pong!", True, WHITE)
screen.blit(title_text, (WIDTH // 2 - title_text.get_width() // 2, HEIGHT // 3))
# Draw buttons
pygame.draw.rect(screen, BUTTON_HOVER_COLOR if single_player_hover
else BUTTON_COLOR, single_player_button)
pygame.draw.rect(screen, BUTTON_HOVER_COLOR if two_player_hover else
BUTTON_COLOR, two_player_button)
# Button text
single_text = font.render("Single Player", True, BUTTON_TEXT_COLOR)
two_text = font.render("Two Players", True, BUTTON_TEXT_COLOR)
pygame.display.flip()
while settings_running:
mouse_pos = pygame.mouse.get_pos()
mouse_clicked = False
if mouse_clicked:
if easy_hover:
ai_difficulty = AI_EASY
settings_running = False
pygame.mouse.set_visible(False)
elif medium_hover:
ai_difficulty = AI_MEDIUM
settings_running = False
pygame.mouse.set_visible(False)
elif hard_hover:
ai_difficulty = AI_HARD
settings_running = False
pygame.mouse.set_visible(False)
else:
pygame.mouse.set_visible(False)
pygame.display.flip()
game_mode = home_screen()
if game_state == GAME_STATE_PAUSED:
pause_text = font.render("GAME PAUSED", True, WHITE)
continue_text = font.render("Press P to Continue", True, WHITE)
screen.blit(pause_text, (WIDTH//2 - pause_text.get_width()//2, HEIGHT//2
- 30))
screen.blit(continue_text, (WIDTH//2 - continue_text.get_width()//2,
HEIGHT//2 + 30))
pygame.display.flip()
pygame.mouse.set_visible(True)
continue
if game_state == GAME_STATE_SETTINGS:
settings_screen()
game_state = GAME_STATE_PLAYING
pygame.mouse.set_visible(False)
continue
# Move ball
ball.x += ball_vel_x
ball.y += ball_vel_y
# Power-up logic
if not power_up_active and pygame.time.get_ticks() % 10000 < 50:
power_up.x, power_up.y = WIDTH // 2 - 10, HEIGHT // 2 - 10
power_up_active = True
# Clear screen
screen.fill(BLACK)
# Draw scores
left_text = font.render(str(left_score), True, WHITE)
right_text = font.render(str(right_score), True, WHITE)
screen.blit(left_text, (WIDTH // 4, 20))
screen.blit(right_text, (WIDTH * 3 // 4, 20))
# Draw power-up
if power_up_active:
pygame.draw.rect(screen, RED, power_up)
# Update display
pygame.display.flip()
# Clear screen
screen.fill(BLACK)
# Update display
pygame.display.flip()
pygame.quit() sys.exit()