Recess-CS project
Recess-CS project
PROJECT REPORT
RECESS
Submitted by:
Aimee Vinod, Alwin PA, Amal Jose, Hari Govind
Index
Sl. no Pg no
1. Synopsis
2. Introduction
3. Project configuration
3.1 Hardware requirements
3.2 Software requirements
4. Software description
5. Source code
6. Conclusion
7. Bibliography
1. Synopsis
The “Recess Game” is an interactive application designed to bring the joy and excitement of
childhood play onto our screens. Inspired by our playful spirits as children, the game
features two popular games—football (soccer) and Tic-Tac-Toe—giving users a chance to
relive the carefree moments of their early school days, where a simple recess break could
turn into hours of fun. Built using Python and leveraging the Tkinter and Pygame libraries,
the application offers a clean and intuitive interface, allowing users to easily navigate
between the two games.
By incorporating user interface design, game mechanics, AI for the football game, and sound
integration, this project showcases fundamental aspects of game development, while
keeping the focus on simplicity and fun.
2. Introduction
From KG to high school, recess was the period we eagerly awaited. It wasn’t just a break
from the monotony of lessons, but a chance to break free and play with our friends. Whether
we were running around playing football or challenging each other in games of Tic-Tac-Toe
during a particularly boring class, these moments were an essential part of our childhood.
The desire to relive those carefree times—filled with friendly competition, laughter, and
spontaneous play—served as the inspiration behind our project.
The "Recess Game” brings that sense of joy and nostalgia to life by offering an interactive
platform where users can play two beloved games—football and Tic-Tac-Toe. Built using
Python and the Tkinter and Pygame libraries, the game is designed to be simple, engaging,
and accessible for players of all ages. Our goal was to capture the essence of school recess,
where fun and friendly competition could happen at the touch of a button.
Through this project, we wanted to explore the integration of interactive games with
graphical interfaces and sound effects. By simulating a “recess” period with a countdown
timer, we’ve created an experience that mimics the fun we had during our school days. This
project not only helps us revisit those cherished memories but also provides a practical
learning opportunity in game development, AI interaction, and interface design
3. Project Configuration
Hardware Requirements
Software Requirements
1. Operating System:
Windows 10 or higher
2. Python Version:
Tkinter (built-in with Python) for creating the GUI and handling the Tic-Tac-Toe game
Other tools
1.Assets:
Audio files for sound effects
2.Dependencies Installation:
Use pip to install necessary libraries (e.g., pip install pygame)
4. Software description
•Python
Python is the primary programming language used in this project. It provides the necessary
structure and functionality to implement the game logic, handle user input, and manage
program flow. Python’s simplicity and readability make it an ideal choice for this project.
•Pygame
Pygame is used for handling the game’s graphics and sound. It allows the creation of
interactive 2D elements, such as the game’s interface, animations, and sound effects,
enhancing the overall user experience.
•Tkinter
Tkinter is a built-in Python library used for creating graphical user interfaces (GUIs). It is
utilized in this project to manage the game’s window, display text, and handle button
interactions for starting the game.
•Math
The math module is used for performing mathematical operations in the game. It helps with
random number generation, calculations related to game mechanics, and any mathematical
logic needed during gameplay.
•Subprocess
Subprocess is used to run external commands or scripts from within the Python program. It
helps in managing background processes or interacting with system-level tasks, such as
executing scripts or launching applications if required by the project.
•Random
The random module is used to generate random events in the game, such as determining
the outcome of certain actions. It adds unpredictability to the gameplay, making the
experience more dynamic and engaging
5. SOURCE CODE
# Background image
Bg_label = tk.Label(root, image=bg_image)
Bg_label.place(x=0, y=0, relwidth=1, relheight=1)
# Dialogue
Dialogue = tk.Label(
Root,
Text=”Do you want to play Football or Tic Tac Toe?”,
Font=(“Courier”, 16), # Use Courier for a playful font
Bg=”#ffffff”,
Wraplength=500
)
Dialogue.place(relx=0.5, rely=0.1, anchor=”n”)
# Buttons
Football_button = tk.Button(
Root, text=”Football”, font=(“Courier”, 14), command=start_football
)
Football_button.place(relx=0.3, rely=0.3)
Ttt_button = tk.Button(
Root, text=”Tic Tac Toe”, font=(“Courier”, 14), command=start_ttt
)
Ttt_button.place(relx=0.6, rely=0.3)
Main_menu()
Root.mainloop()
#FOOTBALL CODE import pygame import math import random import sys
# Display settings
WIDTH, HEIGHT = 800, 500 screen = pygame.display.set_mode((WIDTH, HEIGHT))
pygame.display.set_caption("Mini Soccer Game")
# Colors
GREEN = (34, 139, 34)
WHITE = (255, 255, 255)
RED = (255, 0, 0)
BLUE = (0, 0, 255)
YELLOW = (255, 255, 0)
# Game settings
FPS = 60
PLAYER_SPEED = 5
AI_SPEED = 3
BALL_SPEED = 5
GOAL_WIDTH = 100
GOAL_HEIGHT = 150
# Function to draw a hexagon for the ball def draw_hexagon(position, color, radius):
points = [
(position[0] + radius * math.cos(math.radians(angle)), position[1] + radius *
math.sin(math.radians(angle))) for angle in range(0, 360, 60)
]
pygame.draw.polygon(screen, color, points)
# Function to move the ball def move_ball():
global ball_pos, ball_direction, player_score, ai_score
# Ball collision with top and bottom walls if ball_pos[1] <= ball_radius or ball_pos[1] >=
HEIGHT - ball_radius:
ball_direction[1] = -ball_direction[1]
# Ball collision with goals if ball_pos[0] <= ball_radius: # Check if it enters the goal
if HEIGHT // 2 - GOAL_HEIGHT // 2 < ball_pos[1] < HEIGHT // 2 + GOAL_HEIGHT
// 2: player_score += 1 reset_ball() elif ball_pos[0] >= WIDTH - ball_radius:
# Check if it enters the goal if HEIGHT // 2 - GOAL_HEIGHT // 2 <
ball_pos[1] < HEIGHT // 2 + GOAL_HEIGHT // 2:
ai_score += 1 reset_ball()
# Function to check collision between player/AI and ball def check_collision(): global
ball_direction
pygame.quit()
sys.exit()
#TIC-TAC-TOE
# Initialize the board self.board = [' ' for _ in range(9)] # 3x3 board
self.current_player
= 'X' self.game_over = False
# Status label for displaying player turns and results self.status_label = tk.Label(
root, text="Player X's turn", font="Arial 14 bold", bg=self.bg_color,
fg=self.text_color
)
self.status_label.grid(row=4, column=0, columnspan=3, pady=(5, 0))
# Score label to track wins self.score_label = tk.Label(
root, text="Score:
X: 0 | O: 0", font="Arial
14 bold",
bg=self.bg_color, fg=self.text_color
)
self.score_label.grid(row=5, column=0, columnspan=3)
if self.check_winner(self.current_player):
self.end_round(winner=self.current_player)
return elif ' '
not in self.board:
self.end_round(winner=None)
return
# Switch players self.current_player = 'O' if self.current_player
== 'X' else 'X' self.status_label.config(text=f"Player
{self.current_player}'s turn")
def get_best_move(self):
# 70% chance to make an optimal move, 30% chance to make a random move if
random.random() < 0.7:
# Try to win, block, or take a strategic move for i in range(9): if
self.board[i] == ' ':
self.board[i] = 'O' if self.check_winner('O'):
self.board[i] = ' ' # Undo move return i
self.board[i] = ' ' # Undo
move
# Block the player from winning
for i in range(9): if self.board[i]
== ' ': self.board[i] = 'X' if
self.check_winner('X'):
self.board[i] = ' ' # Undo move return i
self.board[i] = ' ' # Undo
move
self.rounds_played += 1 self.update_score()
if self.rounds_played >= 5:
self.declare_winner()
else:
self.root.after(2000, self.reset_game) # Delay reset for 2 seconds
def reset_game(self):
# Reset the board for a new round self.board = [' ' for _ in range(9)] for button
in self.buttons:
button.config(text=" ", bg=self.button_color) self.current_player = 'X'
self.game_over = False
if self.rounds_played < 5:
self.status_label.config(text="Player X's turn")
if __name__ == "__main__":
main()
Output
6. Conclusion
In conclusion, this project has provided valuable insights into the process of game
development using Python. By utilizing libraries such as Tkinter for the graphical interface
and Pygame for interactive elements, we successfully created two engaging games: Tic Tac
Toe and Football. These games were designed to be simple yet enjoyable, focusing on user
interaction and providing a satisfying experience.
Overall, this project has been an excellent learning experience, helping us build both
technical and creative skills that will benefit us in future endeavors.
7. Bibliography
1.Web Resources:
2.Project Assistance:
5.YouTube Tutorials
Tech With Tim. “How to Install Python and Pygame on Windows.” YouTube, 2020.
Python Engineer. “How to Make a Game in Python using Pygame – Full Tutorial.” YouTube,
2021.
FreeCodeCamp.org. “How to Make Your First Game with Python and Pygame.” YouTube,
2021.