Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Chutes and Ladders
- # Brian Dickman
- # Lutheran High School
- # Intro to Computer Programming
- # February 2016
- #IMPORTS
- import random
- #DECLARATION
- board = []
- locations = []
- currentPlayer = 1
- noWinner = True
- numPlayers = 1 # will change based on user input
- # spin function - returns integer between 1 and 6
- def spin():
- return random.randint(1,6)
- # resetBoard function - defines all board positions and location of chutes and ladders
- def resetBoard():
- global board
- for spot in range(1,101):
- #print(str(spot))
- board.append(0)
- # Add new values for ladders
- board[0] = 38 #if you land on space #1, go to space #38
- board[3] = 14 #if you land on space #4, go to space #14
- print("The game board is reset")
- # resetPlayers function - moves all players
- def resetPlayers():
- global locations
- global numPlayers
- for player in range(1, numPlayers+1):
- locations.append([player,0])
- print("Number of players...")
- print(numPlayers)
- #
- def getNewLocation(landing):
- print("Landed on space...")
- print(landing)
- iLanding = landing -1
- if (board[iLanding] > 0):
- if (board[iLanding]>landing):
- print("You climbed a ladder")
- else:
- print("Oh No! You landed on a slide!")
- print ("Your new location...")
- print(board[iLanding])
- return board[iLanding]
- else:
- return landing
- # movePlayer function -
- def movePlayer(thePlayer):
- global noWinner
- global locations
- global board
- print("Player: ")
- print(thePlayer)
- thePlayer = thePlayer - 1
- theSpin = spin()
- print ("Spin")
- print(theSpin)
- newLocation = locations[thePlayer][1] + theSpin
- if (newLocation <= 100):
- #user is on board and did not win
- newLocation = getNewLocation(newLocation)
- locations[thePlayer][1] = newLocation
- if (newLocation == 100):
- print ("YOU WIN!")
- noWinner = False
- print ("You are now at space ",str(locations[thePlayer][1]))
- def nextPlayer():
- global currentPlayer
- global numPlayers
- currentPlayer = currentPlayer + 1
- if (currentPlayer > numPlayers):
- currentPlayer = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement