Professional Documents
Culture Documents
Code DSA
Code DSA
time_clocks = pygame.time.Clock()
# Initialize
pygame.init()
width_screen = 1366
height_screen = 768
ic = pygame.image.load("resources/icon.png")
pygame.display.set_icon(ic)
pygame.display.update()
# Graphics:
red_color = (200, 0, 0)
blue_red_color = (240, 0, 0)
mother_board = pygame.image.load("resources/Snakes_ladders_big_image.png")
d1 = pygame.image.load("resources/dice_image1.png")
d2 = pygame.image.load("resources/dice_image2.png")
d3 = pygame.image.load("resources/dice_image3.png")
d4 = pygame.image.load("resources/dice_image4.png")
d5 = pygame.image.load("resources/dice_image5.png")
d6 = pygame.image.load("resources/dice_image6.png")
red_c = pygame.image.load("resources/red_c.png")
yellow_c = pygame.image.load("resources/yellow_c.png")
green_c = pygame.image.load("resources/green_c.png")
blue_c = pygame.image.load("resources/blue_c.png")
menu_background = pygame.image.load("resources/menu.jpg")
post = pygame.image.load("resources/game_background.jpg")
initial_background = pygame.image.load("resources/introduction_image.png")
initial_background2 = pygame.image.load("resources/introduction_image2.jpg")
initial_background3 = pygame.image.load("resources/introduction_image3.jpg")
initial_background4 = pygame.image.load("resources/introduction_image4.jpg")
initial_background5 = pygame.image.load("resources/introduction_image5.jpg")
creditations1 = pygame.image.load("resources/owner.jpg")
pygame.mixer.music.load("sound/music.wav")
snake_sound = pygame.mixer.Sound("sound/snake.wav")
win = pygame.mixer.Sound("sound/win.wav")
lose = pygame.mixer.Sound("sound/lose.wav")
ladder = pygame.mixer.Sound("sound/ladder.wav")
# mouse position
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
TextRect.center = (x, y)
game_layout_display.blit(TextSurf, TextRect)
TextRect.center = (x, y)
game_layout_display.blit(TextSurf, TextRect)
def movement(a):
l1 = [[406, 606], [456, 606], [506, 606], [556, 606], [606, 606], [656, 606], [706, 606], [756, 606], [806,
606],
[856, 606], [906, 606], [906, 560], [856, 560], [806, 560], [756, 560], [706, 560], [656, 560], [606,
560],
[556, 560], [506, 560], [456, 560], [456, 506], [506, 506], [556, 506], [606, 506], [656, 506], [706,
506],
[756, 506], [806, 506], [856, 506], [906, 506], [906, 460], [856, 460], [806, 460], [756, 460], [706,
460],
[656, 460], [606, 460], [556, 460], [506, 460], [456, 460], [456, 406], [506, 406], [556, 406], [606,
406],
[656, 406], [706, 406], [756, 406], [806, 406], [856, 406], [906, 406], [906, 360], [856, 360], [806,
360],
[756, 360], [706, 360], [656, 360], [606, 360], [556, 360], [506, 360], [456, 360], [456, 306], [506,
306],
[556, 306], [606, 306], [656, 306], [706, 306], [756, 306], [806, 306], [856, 306], [906, 306], [906,
260],
[856, 260], [806, 260], [756, 260], [706, 260], [656, 260], [606, 260], [556, 260], [506, 260], [456,
260],
[456, 206], [506, 206], [556, 206], [606, 206], [656, 206], [706, 206], [756, 206], [806, 206], [856,
206],
[906, 206], [906, 160], [856, 160], [806, 160], [756, 160], [706, 160], [656, 160], [606, 160], [556,
160],
l2 = l1[a]
x = l2[0] - 25
y = l2[1] - 25
return x, y
# Ladder check
def ladders(x):
if x == 1:
return 38
elif x == 4:
return 14
elif x == 9:
return 31
elif x == 28:
return 84
elif x == 21:
return 42
elif x == 51:
return 67
elif x == 80:
return 99
elif x == 72:
return 91
else:
return x
# Snake Check
def snakes(x):
if x == 17:
return 7
elif x == 54:
return 34
elif x == 62:
return 19
elif x == 64:
return 60
elif x == 87:
return 36
elif x == 93:
return 73
elif x == 95:
return 75
elif x == 98:
return 79
else:
return x
def dice(d):
if d == 1:
d = d1
elif d == 2:
d = d2
elif d == 3:
d = d3
elif d == 4:
d = d4
elif d == 5:
d = d5
elif d == 6:
d = d6
time_clock = pygame.time.get_ticks()
pygame.display.update()
# mouse position
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
return True
else:
# mouse position
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
return True
else:
# Turn
if d == 6:
six = True
else:
six = False
p = dice(d)
sc += d
if sc <= 100:
laddle = ladders(sc) # checking for ladders for player
if laddle != sc:
lefted = True
pygame.mixer.Sound.play(ladder)
time_clock = pygame.time.get_ticks()
sc = laddle
sink = snakes(sc)
section = True
pygame.mixer.Sound.play(snake_sound)
sc = sink
sc -= d
time_clock = pygame.time.get_ticks()
pygame.display.update()
# Quitting:
def Quit():
pygame.quit()
quit()
# Buttons:
def button(t, xm, ym, x, y, wid, hei, int, after, fast, best):
if best == 1:
choice()
elif best == 5:
return 5
elif best == 0:
Quit()
return best
elif best == 7:
choice()
else:
return True
else:
def introduction():
time_clock = pygame.time.get_ticks()
pygame.display.update()
while True:
time_clock = pygame.time.get_ticks()
pygame.display.update()
time_clock = pygame.time.get_ticks()
pygame.display.update()
time_clock = pygame.time.get_ticks()
pygame.display.update()
time_clock = pygame.time.get_ticks()
pygame.display.update()
if event.type == pygame.KEYDOWN:
return
pygame.display.update()
def creditation():
while True:
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
Quit()
# mouse position
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
main_menu()
pygame.display.update()
# Main Menu
def main_menu():
pygame.mixer.music.play(-1)
m = True
while m:
if event.type == pygame.QUIT:
Quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
Quit()
# mouse position
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
blue_green_color, 60, 1)
blue_red_color, 60, 0)
mouse = pygame.mouse.get_pos()
pygame.mixer.music.pause()
if button2("Play Music", mouse[0], mouse[1], 1166, 75, 200, 50, purple_color, blue_purple_color,
25):
pygame.mixer.music.unpause()
if button2("Credits", mouse[0], mouse[1], 1166, 150, 200, 50, purple_color, blue_purple_color, 25):
creditation()
pygame.display.update()
# Options Menu:
def choice():
f = True
while f == True:
if event.type == pygame.QUIT:
Quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
Quit()
# mouse position
mouse = pygame.mouse.get_pos()
click = pygame.mouse.get_pressed()
best1 = button("Single Player", mouse[0], mouse[1], (width_screen / 2 - 150), 250, 300, 50,
green_color,
# 2 player button
best2 = button("2 Players", mouse[0], mouse[1], (width_screen / 2) - 150, 350, 300, 50, green_color,
blue_green_color, 30, 2)
# 3 player
best3 = button("3 Players", mouse[0], mouse[1], (width_screen / 2) - 150, 450, 300, 50, green_color,
blue_green_color, 30, 3)
# 4 player
best4 = button("4 Players", mouse[0], mouse[1], (width_screen / 2) - 150, 550, 300, 50, green_color,
blue_green_color, 30, 4)
# Back button
best5 = button("Back", mouse[0], mouse[1], 0, 650, 200, 50, red_color, blue_red_color, 30, 5)
if best5 == 5:
main_menu()
if best1 == "s":
playing(21)
if best2 == 2:
playing(2)
if best3 == 3:
playing(3)
if best4 == 4:
playing(4)
pygame.display.update()
def playing(best):
best6 = -1
time = 3000
if best6 == 7:
choice()
if best == 21:
gamer2 = "Computer"
gamer2score = 0
gamer2score = 0
gamer3score = 0
gamer4score = 0
tips = 1
play = True
while True:
less = False
set = False
time = 3000
mouse = pygame.mouse.get_pos()
Quit()
if event.type == pygame.KEYDOWN:
if event.key == pygame.K_ESCAPE:
Quit()
if best == 21:
if button1("Player 1", mouse[0], mouse[1], 100, 700, 200, 50, red_color, grey_color, 30):
if tips == 1:
if not six:
tips += 1
if gamer1score == 100:
time = pygame.time.get_ticks()
pygame.mixer.Sound.play(win)
pygame.display.update()
break
button1("Computer", mouse[0], mouse[1], 400, 700, 200, 50, yellow_color, grey_color, 30)
if True:
if tips == 2:
if not six:
tips += 1
tips = 1
if gamer2score == 100:
time_clock = pygame.time.get_ticks()
pygame.mixer.Sound.play(lose)
pygame.display.update()
break
if button1("Player 1", mouse[0], mouse[1], 100, 700, 200, 50, red_color, grey_color, 30):
if tips == 1:
if not six:
tips += 1
if gamer1score == 100:
time_clock = pygame.time.get_ticks()
pygame.mixer.Sound.play(win)
pygame.display.update()
break
if button1("Player 2", mouse[0], mouse[1], 400, 700, 200, 50, yellow_color, grey_color, 30):
if tips == 2:
if not six:
tips += 1
if best < 3:
tips = 1
if gamer2score == 100:
time_clock = pygame.time.get_ticks()
pygame.mixer.Sound.play(win)
pygame.display.update()
break
if button1("Player 3", mouse[0], mouse[1], 700, 700, 200, 50, green_color, grey_color, 30):
if tips == 3:
tips += 1
if best < 4:
tips = 1
if gamer3score == 100:
time_clock = pygame.time.get_ticks()
pygame.mixer.Sound.play(win)
pygame.display.update()
break
if button1("Player 4", mouse[0], mouse[1], 1000, 700, 200, 50, blue_color, grey_color, 30):
if tips == 4:
if not six:
tips += 1
if best < 5:
tips = 1
if gamer4score == 100:
time_clock = pygame.time.get_ticks()
while pygame.time.get_ticks() - time_clock < 2000:
pygame.mixer.Sound.play(win)
pygame.display.update()
break
if less:
time_clock = pygame.time.get_ticks()
pygame.display.update()
if set:
time_clock = pygame.time.get_ticks()
pygame.display.update()
time_clocks.tick(7)
pygame.display.update()
introduction()
main_menu()