Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import time
- i = 0
- Player1Points = 0
- Player2Points = 0
- Player1Tiebreaker = 0
- Player2Tiebreaker = 0
- Winner_Points = 0
- print("------------------------------------------------Welcome to the 2 player dice game---------------------------------------------")
- ###### LOGIN CODE ######
- Player1Username = input("Create username for player 1 : ")
- print("Your username is" , Player1Username)
- Player1Password = input("Create a password : ")
- print("Your password is", Player1Password)
- ###### LOGIN CODE PLAYER 2 ######
- Player2Username = input("Create username for player 2: ")
- print("Your username is" , Player2Username)
- Player2Password = input("Create a password : ")
- print("Your password is", Player2Password)
- ###### DEFINING ROLL ######
- ### Makes the dice roll for the player and works out the total for that roll ###
- def roll():
- dice1 = random.randint(1,6)
- dice2 = random.randint(1,6)
- print("Player1Username, "has been rolled", dice1, "and", dice2)
- dietotal = dice1 + dice2
- points = points + dietotal
- if dietotal % 2 == 0:
- points = points + 10
- print("you got even, so here is 10 more points")
- else:
- points = points - 5
- if dice1 == dice2:
- die3 = random.randint(1,6)
- points = points +dice3
- ###### DICE ROLL ######
- ### 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 ###
- for i in range(1,6):
- Player1Points += roll()
- print(Player1Username, "has been rolled", dice1, "and", dice2)
- print("Now you have: ", Player1Points, "points")
- time.sleep(3.2)
- Player2Points += roll()
- print(Player2Username, "has been rolled", dice1, "and", dice2)
- print("Now you have: ", Player2Points, "points")
- time.sleep(3.2)
- if Player1Points == Player2Points:
- while Player1Tiebreaker == Player2Tiebreaker:
- Player1Tiebreaker = random.randint(1,6)
- Player2Tiebreaker = random.randint(1,6)
- if Player1Tiebreaker > Player2Tiebreaker:
- Player2Points = 0
- elif Player2Tiebreaker > Player1Tiebreaker:
- Player1Points = 0
- ###### WORKING OUT THE WINNER ######
- ### This checks which score is bigger, then creates a tuple for my leaderboard code ( Gotton of stack overflow ) ###
- if Player1Points>Player2Points:
- Winner_Points = Player1Points
- winner_User = Player1Username
- winner = (Winner_Points, Player1Username)
- elif Player2Points>Player1Points:
- Winner_Points = Player2Points
- winner = (Winner_Points, Player2Username)
- winner_User = Player2Username
- print('Well done, ', winner_User,' you won with ',Winner_Points,' Points')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement