Advertisement
Guest User

Chutes v1 - no Main

a guest
Feb 11th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.25 KB | None | 0 0
  1. # Chutes and Ladders
  2. # Brian Dickman
  3. # Lutheran High School
  4. # Intro to Computer Programming
  5. # February 2016
  6.  
  7. #IMPORTS
  8. import random
  9.  
  10. #DECLARATION
  11. board = []
  12. locations = []
  13. currentPlayer = 1
  14. noWinner = True
  15. numPlayers = 1      # will change based on user input
  16.  
  17. # spin function - returns integer between 1 and 6
  18. def spin():
  19.     return random.randint(1,6)
  20.  
  21. # resetBoard function - defines all board positions and location of chutes and ladders
  22. def resetBoard():
  23.     global board
  24.  
  25.     for spot in range(1,101):
  26.         #print(str(spot))
  27.         board.append(0)
  28.  
  29.     # Add new values for ladders
  30.     board[0] = 38   #if you land on space #1, go to space #38
  31.     board[3] = 14   #if you land on space #4, go to space #14
  32.  
  33.     print("The game board is reset")
  34.  
  35. # resetPlayers function - moves all players
  36. def resetPlayers():
  37.     global locations
  38.     global numPlayers
  39.  
  40.     for player in range(1, numPlayers+1):
  41.         locations.append([player,0])
  42.  
  43.     print("Number of players...")
  44.     print(numPlayers)
  45.  
  46. #
  47. def getNewLocation(landing):
  48.  
  49.     print("Landed on space...")
  50.     print(landing)
  51.     iLanding = landing -1
  52.     if (board[iLanding] > 0):
  53.         if (board[iLanding]>landing):
  54.             print("You climbed a ladder")
  55.         else:
  56.             print("Oh No! You landed on a slide!")
  57.         print ("Your new location...")
  58.         print(board[iLanding])
  59.         return board[iLanding]
  60.     else:
  61.         return landing
  62.  
  63. # movePlayer function -
  64. def movePlayer(thePlayer):
  65.  
  66.     global noWinner
  67.     global locations
  68.     global board
  69.  
  70.     print("Player: ")
  71.     print(thePlayer)
  72.  
  73.     thePlayer = thePlayer - 1
  74.  
  75.     theSpin = spin()
  76.     print ("Spin")
  77.     print(theSpin)
  78.     newLocation = locations[thePlayer][1] + theSpin
  79.     if (newLocation <= 100):
  80.         #user is on board and did not win
  81.         newLocation = getNewLocation(newLocation)
  82.         locations[thePlayer][1] = newLocation
  83.         if (newLocation == 100):
  84.             print ("YOU WIN!")
  85.             noWinner = False
  86.  
  87.     print ("You are now at space ",str(locations[thePlayer][1]))
  88.  
  89.  
  90. def nextPlayer():
  91.     global currentPlayer
  92.     global numPlayers
  93.  
  94.     currentPlayer = currentPlayer + 1
  95.     if (currentPlayer > numPlayers):
  96.         currentPlayer = 1
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement