Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. from random import *
  2.  
  3. global playerHP
  4. playerHP = {}
  5. playerHP[0] = 80
  6. playerHP[1] = 80
  7. global turn
  8. turn = 0
  9. global currentPlayer
  10. currentPlayer = 100
  11.  
  12. def randomEvent(player : int):
  13. event = randint(1,8)
  14. tplayer = str(player)
  15. if event == 1:
  16. print("Player ", tplayer, " is struck by lightning and gets hurt!")
  17. playerHurt(player, randint(10,20))
  18. elif event == 2:
  19. print("Player ", tplayer, " is struck by lightning and energised.")
  20. playerHeal(player, randint(10,40))
  21. elif event == 3:
  22. print("A meteorite hits Player ", tplayer, " and deals massive damage!")
  23. playerHurt(player, randint(30,40))
  24. elif event == 4:
  25. print("Player ", tplayer, " gets hit by a bus while crossing the road.")
  26. playerHurt(player, randint(11,25))
  27. elif event == 5:
  28. print("Player ", tplayer, " narrowly misses getting hit by a bus but is then hit by a speeding car.")
  29. playerHurt(player, randint(11,20))
  30. elif event == 6:
  31. print("Player ", tplayer, " was in the tower at the wrong time.")
  32. playerHurt(player, randint(20,50))
  33. elif event == 7:
  34. print("Player ", tplayer, " buys a sausage roll from Greggs and recovers some health.")
  35. playerHeal(player, randint(10,30))
  36. elif event == 8:
  37. print("Player ", tplayer, " forgot to pay their dealer and gets their legs broken.")
  38. playerHurt(player, randint(20,40))
  39.  
  40.  
  41. def playerHurt(victim : int, damage : int):
  42. global playerHP
  43. print("Player ", str(victim), " takes ", str(damage), " damage.")
  44. playerHP[victim] -= damage
  45. if playerHP[victim] <= 0:
  46. print("Player ", str(victim), " is mortally wounded!")
  47. else:
  48. print("Player ", str(victim), " now has ", str(playerHP[victim]), " health.")
  49.  
  50. def playerHeal(target : int, health : int):
  51. global playerHP
  52. print("Player ", str(target), " gains ", str(health), " HP!")
  53. playerHP[target] += health
  54. print("Player ", str(target), " now has ", str(playerHP[target]), " health.")
  55.  
  56. def playerGo(player : int):
  57. seed()
  58. global currentPlayer
  59. global playerHP
  60. global turn
  61. if ( randint(1,20) == 1 ):
  62. randomEvent(randint(0,1))
  63. currentPlayer = player
  64. global playerHP
  65. if playerHP[0] <= 0 or playerHP[1] <= 0:
  66. return
  67. print("Player ", str(player), "'s turn!")
  68. print("1: Attack")
  69. print("2: Heal")
  70. playerChoice = input("")
  71. if playerChoice == "1":
  72. if player == 0:
  73. print("Player 0 attacks!")
  74. print(" ")
  75. playerHurt(1, randint(5,10))
  76. else:
  77. print("Player 1 attacks!")
  78. print(" ")
  79. playerHurt(0, randint(5,10))
  80. elif playerChoice == "2":
  81. playerHeal(player, randint(3,11))
  82. elif playerChoice == "debugRandomEvent":
  83. randomEvent(randint(0,1))
  84. else:
  85. print("Invalid Choice! Player skips a turn!")
  86. turn += 1
  87.  
  88. while playerHP[0] > 0 and playerHP[1] > 0:
  89. global currentPlayer
  90. print(" ")
  91. if currentPlayer == 100:
  92. playerGo(0)
  93. elif currentPlayer == 0:
  94. playerGo(1)
  95. elif currentPlayer == 1:
  96. playerGo(0)
  97.  
  98. if playerHP[0] > playerHP[1]:
  99. print("Player 0 wins with ", str(playerHP[0]), " HP!")
  100. else:
  101. print("Player 1 wins with ", str(playerHP[1]), " HP!")
  102. print("Victory took ", str(turn), "turns.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement