I am writing a chutes and ladders game for a class, and it's mostly working but I can't figure out how to make the chutes and ladders work.
Can I please have some hints?
board = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60,
61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80,
81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
for i in range (10):
for j in range (10):
print(board[-(i*10+j)-1], end = ' ')
print()
print('\n\n')
#Ladders: 1-> 33(L1), 19- >75(L2), 69-> 85(L3)
#Snakes: 45 -> 15(S1), 82-> 48(S2), 98-< 78(S3)
board[1-1]='L1'
board[33-1]='L1'
board[19-1]='L2'
board[75-1]='L2'
board[69-1]='L3'
board[85-1]='L3'
board[45-1]='S1'
board[15-1]='S1'
board[82-1]='S2'
board[48-1]='S2'
board[98-1]='S3'
board[78-1]='S3'
for i in range (10):
for j in range(10):
print(board[-(i*10+j)-1], end=' ')
print()
print('\n\n')
current = 0
#Roll dice
import random
while current != 100:
# altered here, use a different name for input
user = input("Press 'r' to roll the dice or 'e' to exit the program: ")
# altered here also from
# if roll == "r":
if user == "r":
# if you read input from the user and stored with the same name, the
# original value will be erased
roll = random.randrange(1,7)
current+= roll
if current >100:
current-=roll
if current == 'S':
snake_search = board[current+1: len(board)]
if board[current][0] > snake_search:
current == snake_search
if current == 'L':
ladder_search = board[current+1:len(board)]
if board[current][0] < ladder_search:
current == ladder_search
last_number = current
board[current-1]= 'X'
print ("You rolled a ", roll, "\n")
for i in range (10):
for j in range(10):
print(board[-(i*10+j)-1], end=' ')
print()
print('\n\n')
board[current-1] = last_number
try:
score = open("score.txt", "a")
score.write(str(current))
score.close()
except:
print('Warning, IOError. No such file exists. ')
# exit
if user == "e":
break
# error
if user != "r" and user != "e":
print(roll)
print("Incorrect input.")
#if roll hits 100, end game with "You Win"
if current == 100:
print("You win!")
score = open("score.txt", "r")
print(score.readline(1))
print(score.readline(2))
print(score.readline(3))
print(score.readline(4))
print(score.readline(5))
score.close()