Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file not shown.
Binary file not shown.
182 changes: 94 additions & 88 deletions pyladder/pyladder/pyladder.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,55 +12,55 @@


# Icon layout and caption
icon = pygame.image.load("../assets/icon.jpg")
icon = pygame.image.load("./pyladder/assets/icon.jpg")
game_layout = pygame.display.set_mode((width, height))
pygame.display.set_caption("Pyladder Game")
pygame.display.set_icon(icon)
pygame.display.update()


Board = pygame.image.load("../assets/Snakes_ladders_big_image.png")
Menu = pygame.image.load("../assets/menu.jpg")
Background = pygame.image.load("../assets/game_background.jpg")
ourrules = pygame.image.load("../assets/rules.png")
Board = pygame.image.load("./pyladder/assets/Snakes_ladders_big_image.png")
Menu = pygame.image.load("./pyladder/assets/menu.jpg")
Background = pygame.image.load("./pyladder/assets/game_background.jpg")
ourrules = pygame.image.load("./pyladder/assets/rules.png")
ourrules = pygame.transform.smoothscale(ourrules, (width, height))
back1 = pygame.image.load("../assets/introduction_image.png")
back2 = pygame.image.load("../assets/introduction_image2.png")
back3 = pygame.image.load("../assets/introduction_image3.png")
back4 = pygame.image.load("../assets/introduction_image4.png")
back5 = pygame.image.load("../assets/introduction_image5.png")
back1 = pygame.image.load("./pyladder/assets/introduction_image.png")
back2 = pygame.image.load("./pyladder/assets/introduction_image2.png")
back3 = pygame.image.load("./pyladder/assets/introduction_image3.png")
back4 = pygame.image.load("./pyladder/assets/introduction_image4.png")
back5 = pygame.image.load("./pyladder/assets/introduction_image5.png")

asac_project = pygame.image.load("../assets/ASAC.png")
asac_project = pygame.image.load("./pyladder/assets/ASAC.png")
asac_project = pygame.transform.smoothscale(asac_project, (width, height))

# All Point
red_token = pygame.image.load("../assets/robot.png")
red_token = pygame.image.load("./pyladder/assets/robot.png")
red_token = pygame.transform.smoothscale(red_token, (55, 53))

blue_token = pygame.image.load("../assets/man.png")
blue_token = pygame.image.load("./pyladder/assets/man.png")
blue_token = pygame.transform.smoothscale(blue_token, (55, 52))

# All Dice
dice1 = pygame.image.load("../assets/dice_image1.png")
dice2 = pygame.image.load("../assets/dice_image2.png")
dice3 = pygame.image.load("../assets/dice_image3.png")
dice4 = pygame.image.load("../assets/dice_image4.png")
dice5 = pygame.image.load("../assets/dice_image5.png")
dice6 = pygame.image.load("../assets/dice_image6.png")
dice1 = pygame.image.load("./pyladder/assets/dice_image1.png")
dice2 = pygame.image.load("./pyladder/assets/dice_image2.png")
dice3 = pygame.image.load("./pyladder/assets/dice_image3.png")
dice4 = pygame.image.load("./pyladder/assets/dice_image4.png")
dice5 = pygame.image.load("./pyladder/assets/dice_image5.png")
dice6 = pygame.image.load("./pyladder/assets/dice_image6.png")

# Sounds
pygame.mixer.music.load("../sound/song1.wav") # And menu first line
snake_sound = pygame.mixer.Sound("../sound/snake2.wav")
ladder_sound = pygame.mixer.Sound("../sound/ladder2.wav")
win_sound = pygame.mixer.Sound("../sound/win1.wav")
lose_sound = pygame.mixer.Sound("../sound/loss3.wav")
dice_sound = pygame.mixer.Sound("../sound/dice1.wav")
pygame.mixer.music.load("./pyladder/sound/song1.wav") # And menu first line
snake_sound = pygame.mixer.Sound("./pyladder/sound/snake2.wav")
ladder_sound = pygame.mixer.Sound("./pyladder/sound/ladder2.wav")
win_sound = pygame.mixer.Sound("./pyladder/sound/win1.wav")
lose_sound = pygame.mixer.Sound("./pyladder/sound/loss3.wav")
dice_sound = pygame.mixer.Sound("./pyladder/sound/dice1.wav")

# img Win & loss
wins_player = pygame.image.load("../assets/wins_player.png")
loss_player = pygame.image.load("../assets/loss_player.png")
wins_computer = pygame.image.load("../assets/wins_computer.png")
loss_computer = pygame.image.load("../assets/loss_computer.png")
wins_player = pygame.image.load("./pyladder/assets/wins_player.png")
loss_player = pygame.image.load("./pyladder/assets/loss_player.png")
wins_computer = pygame.image.load("./pyladder/assets/wins_computer.png")
loss_computer = pygame.image.load("./pyladder/assets/loss_computer.png")

# Position of mouse
mouse = pygame.mouse.get_pos()
Expand Down Expand Up @@ -425,53 +425,59 @@ def playing(btn1):

# print(btn1)
if btn1:
if button("Click to Roll", mouse[0], mouse[1], 50, 138, 350, 50, green_color, light_green_color, 40, btn1):
if rounds == 1:
player1_score, up, down, six = turn(player1_score, up, down,rounds)
# tempx,tempy=player1_x_c, player1_y_c
player1_x_c, player1_y_c = moving(player1_score)
if not six:
rounds += 1
if player1_score == 100:
time = pygame.time.get_ticks()
while pygame.time.get_ticks() - time < 2500:
display_text("Congratulations You WON !", 700, 50, 60)
pygame.mixer.music.pause()
while pygame.time.get_ticks() - time < 50:
game_layout.blit(wins_player, (-5, height / 2 +70))
game_layout.blit(loss_computer, (width - 120, height / 2+70))
if computer_score ==100 or player1_score==100:
if button("Back", mouse[0], mouse[1], width / 2 - 120, 680, 200, 70, (168, 50, 50,1), (168, 55, 50,50), 60, 2):
menu()
else:
if button("Click to Roll", mouse[0], mouse[1], 50, 138, 350, 50, green_color, light_green_color, 40, btn1):
if rounds == 1:
player1_score, up, down, six = turn(player1_score, up, down,rounds)
# tempx,tempy=player1_x_c, player1_y_c
player1_x_c, player1_y_c = moving(player1_score)
if not six:
rounds += 1
if player1_score == 100:
time = pygame.time.get_ticks()
while pygame.time.get_ticks() - time < 2500:
display_text("Congratulations You WON !", 700, 50, 60)
pygame.mixer.music.pause()
while pygame.time.get_ticks() - time < 500:
game_layout.blit(wins_player, (-5, height / 2 +70))
game_layout.blit(loss_computer, (width - 120, height / 2+70))
pygame.display.update()
pygame.mixer.Sound.play(win_sound)
pygame.mixer.music.unpause()
pygame.display.update()
pygame.mixer.Sound.play(win_sound)
pygame.mixer.music.unpause()
pygame.display.update()
break

break
game_layout.blit(red_token, (comp_x_c ,comp_y_c ))
if btn1 == 10:
game_layout.blit(blue_token, (player1_x_c + 2, player1_y_c))

button("Computer", mouse[0], mouse[1], 1050, 138, 220, 50, green_color, light_green_color, 40,btn1)
if rounds == 2:
computer_score, up, down, six = turn(computer_score, up, down,rounds)
comp_x_c, comp_y_c = moving(computer_score)
if not six:
rounds += 1
if btn1 == 10:
rounds = 1
# computer_score == 100
if computer_score == 100:
time_clock = pygame.time.get_ticks()
while pygame.time.get_ticks() - time_clock < 500:
display_text("Computer Won !", 1066, 50, 60)
pygame.mixer.music.pause()
while pygame.time.get_ticks() - time_clock < 2500:
game_layout.blit(wins_computer, (width - 250, height / 2 + 70))
game_layout.blit(loss_player, (-5, height / 2 +70))
if computer_score ==100 or player1_score==100:
if button("Back", mouse[0], mouse[1], width / 2 - 120, 680, 200, 70, (168, 50, 50,1), (168, 55, 50,50), 60, 2):
menu()
else:
button("Computer", mouse[0], mouse[1], 1050, 138, 220, 50, green_color, light_green_color, 40,btn1)
if rounds == 2:
computer_score, up, down, six = turn(computer_score, up, down,rounds)
comp_x_c, comp_y_c = moving(computer_score)
if not six:
rounds += 1
if btn1 == 10:
rounds = 1
if computer_score == 100:
time_clock = pygame.time.get_ticks()
while pygame.time.get_ticks() - time_clock < 500:
display_text("Computer Won !", 1066, 50, 60)
pygame.mixer.music.pause()
while pygame.time.get_ticks() - time_clock < 2500:
game_layout.blit(wins_computer, (width - 250, height / 2 + 70))
game_layout.blit(loss_player, (-5, height / 2 +70))
pygame.display.update()
pygame.mixer.Sound.play(lose_sound)
pygame.mixer.music.unpause()
pygame.display.update()
pygame.mixer.Sound.play(lose_sound)
pygame.mixer.music.unpause()
pygame.display.update()
break
break

clock.tick()
pygame.display.update()

Expand All @@ -482,23 +488,23 @@ def math(rounds):
font = pygame.font.Font(None, 32)
input_box = pygame.Rect(585, 570, 140, 32)

questions = [["../assets/question/q1.jpg", '96'],
["../assets/question/q2.jpg", '111'],
["../assets/question/q3.jpg", '72'],
["../assets/question/q4.png", '225'],
["../assets/question/q5.jpg", '9'],
["../assets/question/q6.png", '86'],
["../assets/question/q7.png", '23'],
["../assets/question/q8.jpg", '6'],
["../assets/question/q9.jpg", '12'],
["../assets/question/q10.jpg", '5'],
["../assets/question/q11.jpg", '25'],
["../assets/question/q12.jpg", '16'],
["../assets/question/q13.jpg", '16'],
["../assets/question/q14.jpg", '45'],
["../assets/question/q15.jpg", '51'],
["../assets/question/q16.jpg", '9'],
["../assets/question/q17.jpg", '7']]
questions = [["./pyladder/assets/question/q1.jpg", '96'],
["./pyladder/assets/question/q2.jpg", '111'],
["./pyladder/assets/question/q3.jpg", '72'],
["./pyladder/assets/question/q4.png", '225'],
["./pyladder/assets/question/q5.jpg", '9'],
["./pyladder/assets/question/q6.png", '86'],
["./pyladder/assets/question/q7.png", '13'],
["./pyladder/assets/question/q8.jpg", '6'],
["./pyladder/assets/question/q9.jpg", '12'],
["./pyladder/assets/question/q10.jpg", '5'],
["./pyladder/assets/question/q11.jpg", '25'],
["./pyladder/assets/question/q12.jpg", '16'],
["./pyladder/assets/question/q13.jpg", '16'],
["./pyladder/assets/question/q14.jpg", '45'],
["./pyladder/assets/question/q15.jpg", '51'],
["./pyladder/assets/question/q16.jpg", '9'],
["./pyladder/assets/question/q17.jpg", '7']]

read_q = randint(0, 16)
get_question = True
Expand Down
Binary file added pyladder/tests/__pycache__/__init__.cpython-39.pyc
Binary file not shown.
Binary file not shown.