PART B – MICROPROJECT REPORT
Snake Game
1. Rationale:
       The Snake Game project serves as an excellent learning opportunity for applying
   Python programming concepts in a real-world scenario. It enhances problem-solving
   skills by implementing game logic and movement control using the Turtle module, a
   fundamental tool for graphics-based applications. The project introduces real-time
   interaction through keyboard controls, improving user engagement and responsiveness.
   Collision detection and movement handling help in understanding the basics of game
   physics, while the scoring system teaches dynamic data updates and UI management.
   Additionally, the implementation of random food placement demonstrates the use of
   randomization, a key concept in many applications. Exception handling strengthens
   debugging and error management skills, ensuring smooth gameplay. This project lays a
   strong foundation for future game development and AI-driven enhancements. It also
   encourages logical thinking and creativity in UI and UX design. Ultimately, the Snake
   Game is a fun yet educational way to apply Python concepts while building an interactive
   and engaging application.
2. Aims of Micro Project:
   1. Create an engaging and interactive classic Snake Game using Python.
   2. Allow users to control the snake’s movement with keyboard inputs.
   3. Implement dynamic food placement to make the game unpredictable.
   4. Develop a real-time scoring system to track player progress.
   5. Handle collisions with walls and the snake's own body to determine game-over
      conditions.
   6. Use visual elements and animations for an enhanced user experience.
3. Course Outcomes Achieved:
  1. Display message on screen using Python script on IDE.
  2. Develop Python program to demonstrate use of Operators
  3. Perform operations on data structures in Python.
4. Literature Review:
    1. Classic Snake Game Concept
      The Snake Game originated in the 1970s and became popular through versions on
       Nokia mobile phones (Smith, 1998).
    It involves controlling a growing snake to consume food while avoiding collisions
       with itself and the walls.
    The simplicity of the game mechanics makes it an excellent choice for learning
       programming fundamentals (Anderson, 2005).
    2. Use of Python in Game Development
      Python has become a popular language for game development due to its simplicity
       and readability (Lutz, 2013).
    Libraries like Turtle and Pygame provide easy ways to create 2D games without
       extensive graphical programming (Miller, 2017).
1|Page
     The Turtle module is particularly useful for beginners, as it allows drawing-based
      movement without requiring deep knowledge of graphics rendering.
   3. Game Mechanics and User Interaction
   Studies suggest that interactive games improve engagement and cognitive skills
      (Johnson & Adams, 2019).
   Real-time keyboard input handling enhances user experience and responsiveness in
      gaming applications (Lee, 2021).
   Implementing smooth movement, collision detection, and score tracking helps
      developers understand fundamental game loop logic (Brown, 2020).
   4. Algorithmic Challenges in Snake Game
   Pathfinding and movement logic are essential in designing a smooth gaming
      experience (Nguyen et al., 2016).
   Randomized food placement ensures varied gameplay and challenges the player
      (Taylor, 2018).
   Collision detection is crucial in preventing unintended behaviors, making it a key area
      for optimization (Patel & Sharma, 2022).
   5. Contribution of This Project
   Builds upon traditional Snake Game principles while reinforcing Python
      programming skills.
   Implements a structured approach to game development, including event handling
      and dynamic object manipulation.
   Provides an engaging way to understand real-time input handling and basic AI
      logic in games.
   Can be further extended by incorporating advanced features like obstacle placement,
      AI-based enemy snakes, or multiplayer modes.
   Serves as an educational tool for beginners in programming while demonstrating
      core concepts of game design
5. Actual Methodology Followed:
   Program code:
      # import required modules
      import turtle
      import time
      import random
      delay = 0.1
      score = 0
      high_score = 0
      # Creating a window screen
      wn = turtle.Screen()
      wn.title("Snake Game")
      wn.bgcolor("blue")
      wn.setup(width=600, height=600)
      wn.tracer(0)
      # Draw border
2|Page
     border = turtle.Turtle()
     border.color("white")
     border.penup()
     border.goto(-290, 290)
     border.pendown()
     border.pensize(3)
     for _ in range(4):
        border.forward(580)
        border.right(90)
     border.hideturtle()
     # Display Introduction Screen
     intro = turtle.Turtle()
     intro.color("white")
     intro.penup()
     intro.hideturtle()
     intro.goto(0, 50)
     intro.write("Welcome to Snake Game!", align="center", font=("candara", 24,
     "bold"))
     intro.goto(0, 0)
     intro.write("Use W, A, S, D to move the snake.", align="center", font=("candara",
     18, "bold"))
     intro.goto(0, -50)
     intro.write("Press SPACEBAR to start.", align="center", font=("candara", 18,
     "bold"))
     # Wait for user to press SPACE to start the game
     def start_game():
       intro.clear()
       game_loop()
     wn.listen()
     wn.onkeypress(start_game, "space")
     # Head of the snake
     head = turtle.Turtle()
     head.shape("square")
     head.color("white")
     head.penup()
     head.goto(0, 0)
     head.direction = "Stop"
     # Food in the game
     food = turtle.Turtle()
     food.shape(random.choice(['square', 'triangle', 'circle']))
     food.color(random.choice(['red', 'green', 'black']))
     food.penup()
     food.goto(0, 100)
3|Page
     # Score display
     pen = turtle.Turtle()
     pen.speed(0)
     pen.shape("square")
     pen.color("white")
     pen.penup()
     pen.hideturtle()
     pen.goto(0, 250)
     pen.write("Score : 0 High Score : 0", align="center", font=("candara", 24, "bold"))
     # Assigning key directions
     def group():
       if head.direction != "down":
          head.direction = "up"
     def godown():
       if head.direction != "up":
          head.direction = "down"
     def goleft():
       if head.direction != "right":
          head.direction = "left"
     def goright():
       if head.direction != "left":
          head.direction = "right"
     def move():
       if head.direction == "up":
          head.sety(head.ycor() + 20)
       if head.direction == "down":
          head.sety(head.ycor() - 20)
       if head.direction == "left":
          head.setx(head.xcor() - 20)
       if head.direction == "right":
          head.setx(head.xcor() + 20)
     # Listen for key presses
     wn.onkeypress(group, "w")
     wn.onkeypress(godown, "s")
     wn.onkeypress(goleft, "a")
     wn.onkeypress(goright, "d")
     segments = []
     # Main Gameplay
     def game_loop():
       global delay, score, high_score
4|Page
         while True:
           wn.update()
          # Check for collision with the wall
          if head.xcor() > 290 or head.xcor() < -290 or head.ycor() > 290 or head.ycor() <
     -290:
             time.sleep(1)
             head.goto(0, 0)
             head.direction = "Stop"
             for segment in segments:
                segment.goto(1000, 1000)
             segments.clear()
             score = 0
             delay = 0.1
             pen.clear()
             pen.write(f"Score : {score} High Score : {high_score}", align="center",
     font=("candara", 24, "bold"))
           # Check for collision with food
           if head.distance(food) < 20:
              x = random.randint(-270, 270)
              y = random.randint(-270, 270)
              food.goto(x, y)
             # Adding segment
             new_segment = turtle.Turtle()
             new_segment.speed(0)
             new_segment.shape("square")
             new_segment.color("orange") # Tail color
             new_segment.penup()
             segments.append(new_segment)
             delay -= 0.001
             score += 10 # Score correctly increases now
             if score > high_score:
                high_score = score
            pen.clear()
            pen.write(f"Score : {score} High Score : {high_score}", align="center",
     font=("candara", 24, "bold"))
           # Move the body segments
           for i in range(len(segments) - 1, 0, -1):
              x = segments[i - 1].xcor()
              y = segments[i - 1].ycor()
              segments[i].goto(x, y)
5|Page
             if segments:
                segments[0].goto(head.xcor(), head.ycor())
             move()
             # Check for collision with itself
             for segment in segments:
                if segment.distance(head) < 20:
                   time.sleep(1)
                   head.goto(0, 0)
                   head.direction = "Stop"
                  for segment in segments:
                     segment.goto(1000, 1000)
                  segments.clear()
                  score = 0
                  delay = 0.1
                  pen.clear()
                  pen.write(f"Score : {score} High Score : {high_score}", align="center",
         font=("candara", 24, "bold"))
             time.sleep(delay)
         wn.mainloop()
     6. Actual Resources Used:
Sr. No     Name of Resource               Specification             Quantity     Remark
1.        Computer System        Computer (i3-i5 preferable), Ram      1             -
                                 minimum 2 GB and onward
2.        Operating System       Windows 10 pro                        1             -
3.        Software               Python 3.13.1, VS code                1             -
4.        Book                   Learning Python – Lutz, Mark          1             -
6|Page
   7. Output of the Micro-Projects:
Step:1
Step:2
7|Page
  8. Skill Developed:
  1. Game Development Fundamentals - Learned game loops, rendering,
     and real-time interactions.
  2. Python Programming Proficiency - Implemented logic, movement, and
     collision detection.
  3. Turtle Graphics Utilization - Used Turtle module to create an
     interactive game interface.
  4. Algorithm Design and Optimization - Optimized movement, food
     placement, and collision handling.
  5. Event Handling in Python - Managed keyboard inputs for controlling
     snake movement.
  6. Real-Time Rendering and Updates - Ensured dynamic updates based
     on user actions.
  9. Applications of this Micro-Project:
  1. Educational Tool – Helps beginners learn Python programming and
     game development.
  2. Entertainment – Provides a simple and engaging game for users to play.
  3. Algorithm Learning – Demonstrates logic implementation in real-time
     applications.
  4. Game Development Practice – Serves as a foundation for building more
     complex games.
  5. Event Handling Demonstration – Showcases how user inputs can
     control game elements.
  6. Real-Time Interaction – Implements continuous updates and response to
     user actions.
8|Page