Hi I dont really sure what I did wrong but it no working. I am making Snakes and Ladders game with out using list
import random
separator = '-' * 20
spaces = [None] * 90
c_l_spaces = {r'slid down a chute ': [[14, 3], [20, 15], [39, 33],[66, 53],[69, 58], [79, 67], [84, 71], [88,36]],'climbed up a ladder |=|': [[6, 17],[24, 26], [30, 44],[49, 62], [82, 86]]}
class Player:
def __init__(self, number):
self.number = number
self.space = 0
def move(self, roll):
global spaces
if (self.space + roll) > 90:
return (1, 'Your roll would move you off the game board.You remain at space {0}.'.format(self.space))
elif (self.space + roll) == 90:
return (0, 'You moved to the last space. You won the game!')
else:
self.space += roll
try:
space_type = spaces[self.space - 1][0]
self.space = spaces[self.space - 1][1]
except TypeError:
return (1, 'You moved to space {0}.'.format(self.space))
else:
return (1, 'You {0} to space {1}!'.format(space_type,self.space))
def roll_die():
roll = random.randint(1, 6)
print('You rolled {0}.'.format(roll))
return roll
def populate_game_board():
global spaces
for key, values in c_l_spaces.items():
for space in values:
spaces[space[0] - 1] = [key, space[1]]
def initialize_players():
while True:
try:
num_players = int(input('Enter the number of players (0 to exit): '))
except ValueError:
print('You have entered an invalid response.n')
else:
if num_players == 0:
print('You have quit the game.')
return
elif 1 <= num_players <= 4:
break
elif (num_players < 0) or (num_players > 4):
print('You have entered an invalid number of players.n')
players = []
for num in range(num_players):
players.append(Player(num + 1))
return players
def start_game(players):
game = 1
while game:
for player in players:
print('n***Player {0}***'.format(player.number))
print('You are currently on space {0}.'.format(player.space))
game_update = player.move(roll_die())
print(game_update[1])
print(separator, end='')
if game_update[0] == 0:
game = 0
break
if game:
input('nPress Enter for the next turn.')
def initialize_game():
global game_information
print(game_information)
players = initialize_players()
if players:
populate_game_board()
start_game(players)
if __name__ == '__main__':
initialize_game()