|
|
|
|
Python
|
82 lines
|
78 sloc
|
3.209 kB
  1. from random import randint 
  2. player1 = input("Enter player 1's name: ") 
  3. player2 = input("Enter player 2's name: ") 
  4. print("") 
  5. print("") 
  6. def menu(): 
  7.     print("Welcome to this dice game.") 
  8.     print("What would you like to do first?") 
  9.     print("") 
  10.     print("A: Play!") 
  11.     print("B: Display rules") 
  12.     print("C: Quit :c") 
  13.     print("") 
  14.     valid = False 
  15.     while valid is False: 
  16.         choice = input("> ") 
  17.         choice = choice.lower() 
  18.         if choice == "a": 
  19.             valid = True 
  20.             game() 
  21.         elif choice == "b": 
  22.             valid = True 
  23.             rules() 
  24.         elif choice == "c": 
  25.             print("Cya") 
  26.             valid = True 
  27.             exit 
  28.         else: 
  29.             print("Enter valid response.") 
  30.             valid = False 
  31.  
  32. def rules(): 
  33.     print("These are the rules of the game. You must obey them!") 
  34.     print("Players take turns to throw two dice . If the throw is a double, i.e. two 2s, two 3s, etc., the player's score reverts to zero and their turn ends. If the throw is not a double, the total shown on the two dice is added to the players score. A player may have as many throws as they like in any turn until they either throw a double or pass the dice. The first player to reach a score of 50, wins the game.") 
  35.     print() 
  36.     menu() 
  37.  
  38. def game(): 
  39.     print("Welcome to the actual game! The fun begins now...") 
  40.     print("The first person to role will be " + str(player1) + ".") 
  41.     print() 
  42.     player1Count = 0 
  43.     player2Count = 0 
  44.     while player1Count < 50 and player2Count < 50: 
  45.         player1Go = True 
  46.         player2Go = False 
  47.         print("Press enter to role the dice. Or, type skip to turn the dice over to the over player.") 
  48.         print() 
  49.         while player1Go is True: 
  50.             print("Player: " + str(player1) + " Score: " + str(player1Count)) 
  51.             x = input() 
  52.             x = x.lower() 
  53.             dice1 = randint(1,6) 
  54.             dice2 = randint(1,6) 
  55.             if x == "skip": 
  56.                 player1Go = False 
  57.                 player2Go = True 
  58.             elif dice1 != dice2: 
  59.                 print("You rolled " + str(dice1) + " and " + str(dice2) + ".") 
  60.                 player1Count = player1Count + (dice1 + dice2) 
  61.             elif dice1 == dice2: 
  62.                 print("Unlucky! You got doubles, your score is now 0 and it is the other players go.") 
  63.                 player1Go = False 
  64.                 player2Go = True 
  65.         while player2Go is True: 
  66.             print("Player: " + str(player1) + " Score: " + str(player1Count)) 
  67.             x = input() 
  68.             dice1 = randint(1,6) 
  69.             dice2 = randint(1,6) 
  70.             if x == "skip": 
  71.                 player2Go = False 
  72.                 player1Go = True 
  73.             elif dice1 != dice2: 
  74.                 print("You rolled " + str(dice1) + " and " + str(dice2) + ".") 
  75.                 player2Count = player2Count + (dice1 + dice2) 
  76.             elif dice1 == dice2: 
  77.                 print("Unlucky! You got doubles, your score is now 0 and it is the other players go.") 
  78.                 player2Go = False 
  79.                 player1Go = True 
  80.                                            
  81.      
  82. menu()