Advertisement
Guest User

Untitled

a guest
Sep 16th, 2019
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.19 KB | None | 0 0
  1. def game(username_one,username_two):
  2. print(username_one + " " + username_two)
  3.  
  4. #Player varibles
  5. playerone_total=0
  6. playertwo_total=0
  7. playerone_score = 0
  8. playertwo_score = 0
  9. dice1_total = 0
  10. dice2_total = 0
  11.  
  12. for i in range(1,6):
  13.  
  14. #Player 1 dice
  15. dice1_one = random.randint(1,6)
  16. dice1_two = random.randint(1,6)
  17.  
  18. #Player 2 dice
  19. dice2_one = random.randint(1,6)
  20. dice2_two = random.randint(1,6)
  21.  
  22. round_num = i
  23. dice1_total=dice1_one+dice1_two
  24. dice2_total=dice2_one+dice2_two
  25.  
  26. print("------\nRound " + str(round_num))
  27.  
  28. #Player 1 Rolls
  29. print("PLAYER ONE TURN")
  30. print("\n" + username_one + " rolls " + str(dice1_one + dice1_two) + " in total")
  31. if dice1_one == dice1_two:
  32. #if rolled a double
  33. print(username_one + " has rolled a double.")
  34. dice1_one = random.randint(1,6)
  35. dice1_two = random.randint(1,6)
  36. print("new total",dice1_one + dice1_two)
  37. print(username_one + " rolls " + str(dice1_total + dice1_one + dice1_two) + " in total")
  38. dice1_total=dice1_total + dice1_one + dice1_two
  39. if (dice1_total)%2==0:
  40. #if total rolled is an Even Number
  41. print("\nEven Number! You get 10 points added to your score!")
  42. playerone_score = (dice1_total + 10)
  43. print(username_one + " Score: " + str(playerone_score))
  44. else:
  45. #If total is not Even Number
  46. print("\nOdd Number! You get 5 points subtracted from your score")
  47. playerone_score = (dice1_total - 5)
  48. if playerone_score <= -1:
  49. playerone_score = 0
  50. print(username_one + " Score: " + str(playerone_score))
  51. else:
  52. print(username_one + " Score: " + str(playerone_score))
  53.  
  54. playerone_total=playerone_total+playerone_score
  55.  
  56. #Player 2 Rolls
  57. print("\nPLAYER TWO TURN")
  58. print("\n" + username_two + " rolls " + str(dice2_one + dice2_two) + " in total")
  59. if dice2_one == dice2_two:
  60. #if rolled a double
  61. print(username_two + " has rolled a double.")
  62. dice2_one = random.randint(1,6)
  63. dice2_two = random.randint(1,6)
  64. print("new total",dice2_one + dice2_two)
  65. print(username_two + " rolls " + str(dice2_total + dice2_one + dice2_two) + " in total")
  66. dice2_total=dice2_total + dice2_one + dice2_two
  67. if (dice2_total)%2==0:
  68. #if total rolled is an Even Number
  69. print("\nEven Number! You get 10 points added to your score!")
  70. playertwo_score = (dice2_total + 10)
  71. print(username_two + " Score: " + str(playertwo_score))
  72. else:
  73. #If total is not Even Number
  74. print("\nOdd Number! You get 5 points subtracted from your score")
  75. playertwo_score = (dice2_total - 5)
  76. if playertwo_score <= -1:
  77. playertwo_score = 0
  78. print(username_two + " Score: " + str(playertwo_score))
  79. else:
  80. print(username_two + " Score: " + str(playertwo_score))
  81.  
  82. playertwo_total=playertwo_total+playertwo_score
  83.  
  84.  
  85. contin=input("\nTo Continue Press Enter.")
  86.  
  87.  
  88.  
  89. #Printing Score after all the Rounds
  90. if playerone_score > playertwo_score:
  91. print("\n"+username_one + " has won with " + str(playerone_total))
  92. print(username_two + " has got " + str(playertwo_total))
  93. elif playerone_score == playertwo_score:
  94. print("\nDraw!")
  95. print(username_one + " has got " + str(playerone_total))
  96. print(username_two + " has got " + str(playertwo_total))
  97. else:
  98. print("\n"+username_two + " has won with " + str(playertwo_total))
  99. print(username_one + " has got " + str(playerone_total))
  100.  
  101. #Storing Player's name and Scores
  102. fo = open("scores.txt","a+")
  103. fo.write(username_one+";"+str(playerone_total)+"\n")
  104. fo.write(username_two+";"+str(playertwo_total)+"\n")
  105. fo.close()
  106. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement