Advertisement
Guest User

Untitled

a guest
Oct 18th, 2019
130
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.73 KB | None | 0 0
  1. import random
  2. import time
  3.  
  4. i = 0
  5. Player1Points = 0
  6. Player2Points = 0
  7. Player1Tiebreaker = 0
  8. Player2Tiebreaker = 0
  9. Winner_Points = 0
  10.  
  11. print("------------------------------------------------Welcome to the 2 player dice game---------------------------------------------")
  12.  
  13.  
  14. ###### LOGIN CODE ######
  15. Player1Username = input("Create username for player 1 : ")
  16. print("Your username is" , Player1Username)
  17. Player1Password = input("Create a password : ")
  18. print("Your password is", Player1Password)
  19.  
  20.  
  21.  
  22.  
  23.  
  24. ###### LOGIN CODE PLAYER 2 ######
  25. Player2Username = input("Create username for player 2: ")
  26. print("Your username is" , Player2Username)
  27. Player2Password = input("Create a password : ")
  28. print("Your password is", Player2Password)
  29.  
  30.  
  31.  
  32.  
  33. ###### DEFINING ROLL ######
  34.  
  35. ### Makes the dice roll for the player and works out the total for that roll ###
  36.  
  37.  
  38. def roll():
  39.  
  40.  
  41. dice1 = random.randint(1,6)
  42.  
  43. dice2 = random.randint(1,6)
  44.  
  45. print("Player1Username, "has been rolled", dice1, "and", dice2)
  46.  
  47. dietotal = dice1 + dice2
  48.  
  49. points = points + dietotal
  50.  
  51. if dietotal % 2 == 0:
  52. points = points + 10
  53. print("you got even, so here is 10 more points")
  54.  
  55. else:
  56. points = points - 5
  57.  
  58. if dice1 == dice2:
  59. die3 = random.randint(1,6)
  60. points = points +dice3
  61. ###### DICE ROLL ######
  62.  
  63. ### This rolls the dice 5 times for the players, and then adds up the total. If the scores are equal, it starts a tie breaker and determines the winner off that ###
  64.  
  65. for i in range(1,6):
  66. Player1Points += roll()
  67. print(Player1Username, "has been rolled", dice1, "and", dice2)
  68. print("Now you have: ", Player1Points, "points")
  69. time.sleep(3.2)
  70. Player2Points += roll()
  71. print(Player2Username, "has been rolled", dice1, "and", dice2)
  72. print("Now you have: ", Player2Points, "points")
  73. time.sleep(3.2)
  74. if Player1Points == Player2Points:
  75. while Player1Tiebreaker == Player2Tiebreaker:
  76.  
  77.  
  78. Player1Tiebreaker = random.randint(1,6)
  79. Player2Tiebreaker = random.randint(1,6)
  80.  
  81. if Player1Tiebreaker > Player2Tiebreaker:
  82. Player2Points = 0
  83. elif Player2Tiebreaker > Player1Tiebreaker:
  84. Player1Points = 0
  85.  
  86. ###### WORKING OUT THE WINNER ######
  87.  
  88. ### This checks which score is bigger, then creates a tuple for my leaderboard code ( Gotton of stack overflow ) ###
  89.  
  90. if Player1Points>Player2Points:
  91. Winner_Points = Player1Points
  92. winner_User = Player1Username
  93. winner = (Winner_Points, Player1Username)
  94. elif Player2Points>Player1Points:
  95. Winner_Points = Player2Points
  96. winner = (Winner_Points, Player2Username)
  97. winner_User = Player2Username
  98.  
  99. print('Well done, ', winner_User,' you won with ',Winner_Points,' Points')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement