Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def game(username_one,username_two):
- print(username_one + " " + username_two)
- #Player varibles
- playerone_total=0
- playertwo_total=0
- playerone_score = 0
- playertwo_score = 0
- dice1_total = 0
- dice2_total = 0
- for i in range(1,6):
- #Player 1 dice
- dice1_one = random.randint(1,6)
- dice1_two = random.randint(1,6)
- #Player 2 dice
- dice2_one = random.randint(1,6)
- dice2_two = random.randint(1,6)
- round_num = i
- dice1_total=dice1_one+dice1_two
- dice2_total=dice2_one+dice2_two
- print("------\nRound " + str(round_num))
- #Player 1 Rolls
- print("PLAYER ONE TURN")
- print("\n" + username_one + " rolls " + str(dice1_one + dice1_two) + " in total")
- if dice1_one == dice1_two:
- #if rolled a double
- print(username_one + " has rolled a double.")
- dice1_one = random.randint(1,6)
- dice1_two = random.randint(1,6)
- print("new total",dice1_one + dice1_two)
- print(username_one + " rolls " + str(dice1_total + dice1_one + dice1_two) + " in total")
- dice1_total=dice1_total + dice1_one + dice1_two
- if (dice1_total)%2==0:
- #if total rolled is an Even Number
- print("\nEven Number! You get 10 points added to your score!")
- playerone_score = (dice1_total + 10)
- print(username_one + " Score: " + str(playerone_score))
- else:
- #If total is not Even Number
- print("\nOdd Number! You get 5 points subtracted from your score")
- playerone_score = (dice1_total - 5)
- if playerone_score <= -1:
- playerone_score = 0
- print(username_one + " Score: " + str(playerone_score))
- else:
- print(username_one + " Score: " + str(playerone_score))
- playerone_total=playerone_total+playerone_score
- #Player 2 Rolls
- print("\nPLAYER TWO TURN")
- print("\n" + username_two + " rolls " + str(dice2_one + dice2_two) + " in total")
- if dice2_one == dice2_two:
- #if rolled a double
- print(username_two + " has rolled a double.")
- dice2_one = random.randint(1,6)
- dice2_two = random.randint(1,6)
- print("new total",dice2_one + dice2_two)
- print(username_two + " rolls " + str(dice2_total + dice2_one + dice2_two) + " in total")
- dice2_total=dice2_total + dice2_one + dice2_two
- if (dice2_total)%2==0:
- #if total rolled is an Even Number
- print("\nEven Number! You get 10 points added to your score!")
- playertwo_score = (dice2_total + 10)
- print(username_two + " Score: " + str(playertwo_score))
- else:
- #If total is not Even Number
- print("\nOdd Number! You get 5 points subtracted from your score")
- playertwo_score = (dice2_total - 5)
- if playertwo_score <= -1:
- playertwo_score = 0
- print(username_two + " Score: " + str(playertwo_score))
- else:
- print(username_two + " Score: " + str(playertwo_score))
- playertwo_total=playertwo_total+playertwo_score
- contin=input("\nTo Continue Press Enter.")
- #Printing Score after all the Rounds
- if playerone_score > playertwo_score:
- print("\n"+username_one + " has won with " + str(playerone_total))
- print(username_two + " has got " + str(playertwo_total))
- elif playerone_score == playertwo_score:
- print("\nDraw!")
- print(username_one + " has got " + str(playerone_total))
- print(username_two + " has got " + str(playertwo_total))
- else:
- print("\n"+username_two + " has won with " + str(playertwo_total))
- print(username_one + " has got " + str(playerone_total))
- #Storing Player's name and Scores
- fo = open("scores.txt","a+")
- fo.write(username_one+";"+str(playerone_total)+"\n")
- fo.write(username_two+";"+str(playertwo_total)+"\n")
- fo.close()
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement