Python Programming
(Subject Code: BCC-402)
                         Project on:
              Snake and Ladder Game
A Project Report Submitted in Partial Fulfilment of the Requirements for
                         the Degree of
         BACHELOR OF TECHNOLOGY
                             In
  ELECTRONICS & COMMUNICATION ENGINEERING
                   Under the guidance of:
                   Er. Imran Khan
              (Honorable Faculty Member)
                        Submitted By:
               Ashish Kumar (2200430310017)
             Chitranshu Sharma(2200430310019)
              Kartikey Tyagi (2200430310033)
                    Report Submitted to:
Department of Electronics & Communication Engineering
   BUNDELKHAND INSTITUTE OF ENGINEERING &
          TECHNOLOGY,JHANSI
            ACADEMIC SESSION 2023-2024
           Bundelkhand Institute of Engineering & Technology Jhansi
                            ( U.P. ) India – 284128
                                    Certificate
 We hereby declare the work is presented in this project entitled “Snake and Ladder Game”
 in partial fulfilment of the award of degree of Bachelor of technology in Electronics &
 Communication Engineering submitted in the Department of the Electronics                 &
 Communication Engineering, Bundelkhand institute of Engineering and Technology Jhansi
 Uttar Pradesh, India is our own work carried out under the guidance of Er. Imran Khan Sir.
Name:
Ashish Kumar (2200430310017)
Chitranshu Sharma (2200430310019)
Kartikey Tyagi (2200430310033)
  This to certify that above statement made by the candidate are correct to the best of my
  knowledge.
                                                                               Guided By,
                                                                       Er. Imran Khan
                                       DECLARATION
I hereby certify that the work which is being presented in B. Tech Project Based Learning
Report entitled “Snake and Ladder Game”, as partial fulfillment of the requirement for
the degree of Bachelor of Technology in Electronics & Communication Engineering,
submitted to the Department of Electronics & Communication Engineering of
Bundelkhand Institute of Engineering & Technology Jhansi (UP), is an authentic record
of my own work carried out under the guidance and supervision of Er. Imran Khan .
The matter presented in this project report in full form or part, has not been submitted by me
for the award of any other degree elsewhere and is free from plagiarism.
Member:
Ashish Kumar (2200430310017)
Chitranshu Sharma (2200430310019)
Kartikey Tyagi (2200430310033)
                                   Acknowledgement
The completion of this project could not have been possible without the participation and
assistance of so many people whose names may not all be enumerated. Their contributions are
sincerely appreciated and gratefully acknowledged.
We express our sincere gratitude to Prof. Deependra Singh (Director B.I.E.T. ,Jhansi).
We are sincerely grateful to our head of department Prof. Deepak Nagaria Sir who provided us the
platform to work on our project. He supported us throughout our project journey and enlightened us.
He supervised as well as provided all the necessary information regarding the project and also
supported in completing the project. His constant guidance and willingness to share his vast
knowledge made us understand this project. We would like to show our gratitude towards all Faculty
members who always willingly helped us. We would like to express our gratitude to our parents and
family for their kind cooperation and encouragement which help us in the completion of this project.
                                       Abstract
This project entails the development of a Snake and Ladder game using Python. The classic board
game, traditionally involving dice rolls to navigate a board filled with snakes and ladders, is
brought to the digital realm with this implementation. Utilizing Python's fundamental
programming constructs, including loops, conditionals, and functions, this project provides an
interactive and engaging user experience. The game is designed to support multiple players,
maintaining the simplicity of the original game while incorporating modern enhancements for
improved usability. Key features include a graphical user interface (GUI) for an intuitive user
experience, random dice rolls for unpredictability, and an automated game board to track player
positions. The project serves as an excellent demonstration of applying Python programming skills
to create a functional and enjoyable application, highlighting the use of data structures, event-
driven programming, and object oriented design principles . .
                                 Snake and Ladder Code
      main.py
import pygame, random, sys
pos_data = [(10, 523), (70, 523), (130, 523), (190, 523), (250, 523), (310, 523), (370,
523), (430, 523), (490, 523), (550, 523),
        (550, 466), (490, 466), (430, 466), (370, 466), (310, 466), (250, 466), (190, 466), (130,
466), (70, 466), (10, 466),
        (10, 409), (70, 409), (130, 409), (190, 409), (250, 409), (310, 409), (370, 409), (430,
409), (490, 409), (550, 409),
        (550, 352), (490, 352), (430, 352), (370, 352), (310, 352), (250, 352), (190, 352), (130,
352), (70, 352), (10, 352),
        (10, 295), (70, 295), (130, 295), (190, 295), (250, 295), (310, 295), (370, 295), (430,
295), (490, 295), (550, 295),
        (550, 238), (490, 238), (430, 238), (370, 238), (310, 238), (250, 238), (190, 238), (130,
238), (70, 238), (10, 238),
        (10, 181), (70, 181), (130, 181), (190, 181), (250, 181), (310, 181), (370, 181), (430,
181), (490, 181), (550, 181),
        (550, 124), (490, 124), (430, 124), (370, 124), (310, 124), (250, 124), (190, 124), (130,
124), (70, 124), (10, 124),
        (10, 67), (70, 67), (130, 67), (190, 67), (250, 67), (310, 67), (370, 67), (430, 67),
(490, 67), (550, 67),
        (550, 10), (490, 10), (430, 10), (370, 10), (310, 10), (250, 10), (190, 10), (130, 10),
(70, 10), (10, 10)]
player_1_pos = 0 player_2_pos = 0 pygame.init() BLUE=
(26, 167, 236) GREEN = (27,121,20) clock = pygame.time.Clock() image
= pygame.image.load("./assests/board.png") dices=[] for x
in range(1, 7):
    img = pygame.image.load(f"./assests/dice_{x}.jpge") img = pygame.transform.scale(img, (40, 40))
dices.append(img) image = pygame.transform.scale(image, (600,600)) img_surface = pygame.Surface((600,
560))     window =      pygame.display.set_mode((600,600)) pygame.display.set_caption("Snake Ladder
Ludo") class circle(): def init (self, x, y, height, line_width, color:tuple): self.x = x self.y
= y self.height = height self.line_width = line_width    self.color = color    def draw(self, window,
border=None): if border:           pygame.draw.circle(window,      border, (self.x+(self.height//2),
self.y+(self.height//2)),     self.height//2)               pygame.draw.circle(window,    self.color,
(self.x+(self.height//2),    self.y+(self.height//2)),      (self.height//2)-(self.line_width))   def
draw_game():
    img_surface.blit(image, (0, 0))      window.blit(img_surface,(0, 0))
pygame.draw.rect(window, (121, 126, 246), (0, 560, 600 , 40)) if player_1_pos==0 and
player_2_pos==0: player_1 = circle(70, 560, 40,
5, BLUE) player_2 = circle(10, 560, 40, 5, GREEN) player_1.draw(window, (30, 47,
121)) player_2.draw(window,
(20,91,15))   pygame.display.update() def
change_dice(data_sd):
window.blit(dices[data_sd], (260, 560))       pygame.display.update()
def show_winner(winner):
    font = pygame.font.Font("./assests/fonts/Game_Of_Squids.ttf ", 32)      window.fill((0,180,216))
if winner=="1":           text = font.render("Blue won", True, (0, 0, 0))    elif winner=="2":
        text = font.render("Green won", True, (0, 0, 0))      text_rect
= text.get_rect()      text_rect.topleft = (200, 250) window.blit(text,
text_rect)     pygame.display.update() def check_win():      if
player_1_pos>=100:     show_winner("1")       elif player_2_pos>=100:
       show_winner("2") def go_ladder(pos=0):
    LADDERS={1:38, 4: 14, 9: 31, 21: 42, 28: 84, 51: 67, 72:91, 80:99, 17:7, 54:34, 64:60, 87:36,
93:73, 94:75, 98:79} if pos in
LADDERS.keys():        return LADDERS[pos]
       else:
        return pos
 def update_pos(play_a_pos, play_b_pos):
 img_surface.blit(image, (0, 0))       window.blit(img_surface,(0,
 0))    if play_a_pos!=0 and play_b_pos!=0:
         player_1 = circle(pos_data[play_a_pos-1][0], pos_data[play_a_pos-1][1], 40, 5, BLUE)
 player_2 = circle(pos_data[play_b_pos-1][0], pos_data[play_b_pos-1][1], 40, 5, GREEN)
 player_1.draw(window,   (30,   47,   121))   player_2.draw(window,   (20,91,15))  elif
 play_a_pos==play_b_pos and play_a_pos!=0 and play_b_pos!=0:
        player_1 = circle(pos_data[play_a_pos-1][0], pos_data[play_a_pos-1][1]+10, 40, 5, BLUE)
 player_2 = circle(pos_data[play_b_pos-1][0], pos_data[play_b_pos-1][1]-10, 40, 5, GREEN)
 player_1.draw(window,     (30,    47,     121))    player_2.draw(window,     (20,91,15))
 pygame.display.update()
 def main_game(): loop = True global player global player_1_pos global player_2_pos
 draw_game()      update_pos(player_1_pos,    player_2_pos)      player=1   data_sd   =
 random.randint(0, random.randint(0, 5)) while loop: check_win() clock.tick(60)     for
 events in pygame.event.get():
 if events.type == pygame.QUIT:        loop=False       if events.type == pygame.KEYDOWN:     if
 events.key == pygame.K_SPACE:                 player*=-1 data_sd=random.randint(0,
 random.randint(0, 5))         if player==1: if 100-player_1_pos>6:
                             player_1_pos+=(data_sd+1)                              player_1_pos
 = go_ladder(player_1_pos)     update_pos(player_1_pos, player_2_pos) elif (100player_1_pos)<=6 and
 (data_sd+1)<=(100-player_1_pos):
                             player_1_pos+=(data_sd+1)                               player_1_pos =
 go_ladder(player_1_pos)                             update_pos(player_1_pos, player_2_pos)
 elif player==-1:                         if 100-player_2_pos>6:
                             player_2_pos+=(data_sd+1)                              player_2_pos
 = go_ladder(player_2_pos)                              update_pos(player_1_pos,
 player_2_pos)                         elif (100player_2_pos)<=6 and (data_sd+1)<=(100-
 player_2_pos):
 player_2_pos+=(data_sd+1)                             player_1_pos = go_ladder(player_1_pos)
 update_pos(player_1_pos,
 player_2_pos)                     update_pos(player_1_pos, player_2_pos)                  if
events.key == pygame.K_ESCAPE:                       loop = False         change_dice(data_sd)
 main_game(
 )
Output
                                           Conclusion
The development of the Snake and Ladder game in Python has been an enlightening and rewarding
experience, encompassing various fundamental and advanced programming concepts. This project
highlights the effectiveness of Python as a versatile language suitable for both beginners and
experienced developers.
In summary, the Snake and Ladder game project has been an excellent way to apply and reinforce
 Python programming skills. It combined elements of randomness, user interaction, and OOP
 principles into a coherent and enjoyable application. Moving forward, there are ample opportunities
 to expand and enhance the game, making it an even more engaging and comprehensive project.
                                    REFERENCE
•   https://www.geeksforgeeks.org/design-snake-and-ladder-game-using-python-oops/
•   https://copyassignment.com/snake-and-ladder-game-in-python/
•   https://www.101computing.net/snakes-and-ladders-using-python/
    https://pillow.readthedocs.io/en/stable/