Advertisement
Guest User

project 1

a guest
Nov 22nd, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.34 KB | None | 0 0
  1. import random
  2. import time
  3. P_win = 0
  4. C_win = 0
  5. print('''welcome to the battle arena
  6. In this game you will be asked to choose 10 warriors from a selection of 3 classes
  7. you can choose however many of each class you want
  8.  
  9. The rules are relatively simple
  10. footmen beats archer
  11. horsemen beats footmen
  12. archer beats horsemen
  13. its essentially a rock paper scissors triangle with a twist
  14.  
  15. The game is decided with two battles.
  16. the first battle eliminates numbers based on this rock paper scissors triangle.
  17. The second battle focuses on total remaining forces and the player with the most left wins.
  18. if there is a tie in forces for the second battle it comes down to a luck draw. as battles will always have a winner.
  19. have fun''')
  20. time.sleep(5)
  21. while True:
  22. P_footmen = 0
  23. P_horsemen = 0
  24. P_archers = 0
  25. C_footmen = 0
  26. C_horsemen = 0
  27. C_archers = 0
  28. print("choose your warriors")
  29. time.sleep(2)
  30. while True:
  31. p = 10
  32. P_footmen = int(input("Number of footmen? "))
  33. p -= P_footmen
  34. print("you have", p, "men left to pick")
  35. if p == 0:
  36. break
  37. time.sleep(1)
  38. P_horsemen = int(input("Number of horsemen? "))
  39. p -= P_horsemen
  40. print("you have", p, "men left to pick")
  41. if p == 0:
  42. break
  43. time.sleep(1)
  44. P_archers = int(input("number of archers? "))
  45. p -= P_archers
  46. if p < 0:
  47. print("you picked too many warriors. 10 maximum")
  48. elif p == 0:
  49. break
  50. elif p > 0:
  51. ("you didn't choose enough warriors")
  52. time.sleep(1)
  53. print("you choose", P_footmen , "footmen")
  54. time.sleep(1)
  55. print(P_horsemen, "horsemen")
  56. time.sleep(1)
  57. print("and", P_archers , "archers")
  58. while True:
  59. c = 10
  60. v = random.randint(1,3)
  61. #in order to make this part of the code much less predictable I added a choose order variable
  62. #this allows multiple choose orders so the first two choosen aren't the most likely to get more choosen
  63. #this makes the random element more uniformly random.
  64. #as well I origionally planned on doing all 9 possible orentations of choose orders but that would have been dreadfully tedious and boring
  65. if v == 1:
  66. C_footmen = random.randint(0,c)
  67. c -= C_footmen
  68. if c == 0:
  69. break
  70. C_horsemen = random.randint(0,c)
  71. c -= C_horsemen
  72. if c == 0:
  73. break
  74. C_archers = c #the last part of every pick order will always be c. because it is the last to be picked. and must fill the last requirements
  75. c -= C_archers
  76. if c == 0:
  77. break
  78. elif v == 2:
  79. C_archers = random.randint(0,c)
  80. c -= C_archers
  81. if c == 0:
  82. break
  83. C_footmen = random.randint(0,c)
  84. c -= C_footmen
  85. if c == 0:
  86. break
  87. C_horsemen = c
  88. c -= C_horsemen
  89. if c == 0:
  90. break
  91. elif v == 3:
  92. C_horsemen = random.randint(0,c)
  93. c -= C_horsemen
  94. if c == 0:
  95. break
  96. C_archers = random.randint(0,c)
  97. c -= C_archers
  98. if c == 0:
  99. break
  100. C_footmen = c
  101. c -= C_footmen
  102. if c == 0:
  103. break
  104. time.sleep(1)
  105. print("computer is choosing.....")
  106. time.sleep(1)
  107. print("soldiers selected, let the battle begin!")
  108. print(" ")
  109. time.sleep(1)
  110. print("player sends out", P_footmen, "footmen.", P_horsemen, "horsemen, and", P_archers, "archers")
  111. time.sleep(1)
  112. print("against the computer's forces of", C_footmen, "Footmen,", C_horsemen, "horsemen, and", C_archers, "archers")
  113. #These variables stand for hte remaining of each unit on each team
  114. PR_footmen = P_footmen - C_horsemen
  115. PR_horsemen = P_horsemen - C_archers
  116. PR_archers = P_archers - C_footmen
  117. CR_footmen = C_footmen - P_horsemen
  118. CR_horsemen = C_horsemen - P_archers
  119. CR_archers = C_archers - P_footmen
  120. #I don't wish for hte game to display negitive numbers so this setup is to solve that
  121. if PR_footmen < 0:
  122. PR_footmen = 0
  123. if PR_horsemen < 0:
  124. PR_horsemen = 0
  125. if PR_archers < 0:
  126. PR_archers =0
  127. if CR_footmen < 0:
  128. CR_footmen = 0
  129. if CR_horsemen < 0:
  130. CR_horsemen = 0
  131. if CR_archers < 0:
  132. CR_archers =0
  133. time.sleep(3)
  134. print("battle results are...!")
  135. print(" ")
  136. time.sleep(3)
  137. print("the player with", PR_footmen, "footmen", PR_horsemen, "horsemen, and", PR_archers, " archers remaining")
  138. time.sleep(3)
  139. print("and the computer with", CR_footmen, "footmen", CR_horsemen, "horsemen, and", CR_archers, "archers remaining")
  140. print(" ")
  141. time.sleep(3)
  142. while True:
  143. if PR_footmen == 0 and PR_horsemen == 0 and PR_archers == 0:
  144. print("The player has lost before the second battle. Computer wins!")
  145. P_win += 1
  146. break
  147. elif CR_footmen == 0 and CR_horsemen == 0 and CR_archers == 0:
  148. print("the computer has lost before the second battle. Player wins!")
  149. C_win += 1
  150. break
  151.  
  152. print("the second battle begins!!!")
  153. print(" ")
  154. time.sleep(3)
  155. print("the battle results are...!!")
  156. time.sleep(3)
  157. P_total = PR_footmen + PR_horsemen + PR_archers
  158. C_total = CR_footmen + CR_horsemen + CR_archers
  159. if P_total > C_total:
  160. print("player wins with a total force count of", P_total, "versus the computer's", C_total)
  161. P_win += 1
  162. break
  163. elif C_total > P_total:
  164. print("the computer wins with a total force count of", C_total, "versus the player's", P_total)
  165. C_win += 1
  166. break
  167. elif C_total == P_total:
  168. print("the forces left over are equal on each side. the battle comes down to a draw of luck!")
  169. time.sleep(3)
  170. #I am not allowing a tie as this is a battle, and it is very unlikeley that a tie would occur in a battle.
  171. #so it comes down to a bit of extra luck if end forces are infact equal
  172. L = random.randint(1,2)
  173. if L == 1:
  174. print("By a stroke of luck the player is victorious!")
  175. P_win += 1
  176. elif L == 2:
  177. print("By a stroke of luck the computer is victorious!")
  178. C_win += 1
  179. time.sleep(2)
  180. end = input("would you like to play again? y/n")
  181. if end == "n":
  182. break
  183. elif end == "y":
  184. print("player has currently won", P_win, "rounds, and computer", C_win, "rounds")
  185. else:
  186. while True:
  187. end = input("incorrect input. type y or n ")
  188. if end == "y" or end == "n":
  189. break
  190. r = P_win + C_win
  191. print("you've ended the game after", r, "rounds")
  192. time.sleep(2)
  193. print("player won", P_win, "rounds, and the computer has won", C_win, "rounds")
  194. time.sleep(2)
  195. if P_win > C_win:
  196. print("Player is the overal winner!")
  197. elif C_win > P_win:
  198. print("computer is the overal winner!")
  199. elif C_win == P_win:
  200. print("the overal game is a tie!")
  201. print("game over")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement