Advertisement
Guest User

Sudden death function/loop issue

a guest
Mar 17th, 2015
347
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.00 KB | None | 0 0
  1. import random
  2. import time
  3. import math
  4. import sys
  5.  
  6. strength_mod = 0
  7. skill_mod = 0
  8. counter = 215
  9. #counter set to 215 to make sure code is working and as a build up
  10.  
  11. def delay_print(s):
  12.     for c in s:
  13.         sys.stdout.write( '%s' % c )
  14.         sys.stdout.flush()
  15.         time.sleep(0.02)
  16.  
  17. def str_mod(charone_str,chartwo_str):
  18.     if charone_str > chartwo_str:
  19.         calc = math.floor(((charone_str - chartwo_str)/ 5))
  20.         return calc
  21.     elif chartwo_str > charone_str:
  22.         calc = math.floor(((chartwo_str - charone_str)/ 5))
  23.         return calc
  24.     elif charone_str == chartwo_str:
  25.         calc = math.floor(((charone_str - chartwo_str)/ 5))
  26.         return calc
  27.  
  28. def skl_mod(charone_skl, chartwo_skl):
  29.     if charone_skl > chartwo_skl:
  30.         calc = math.floor(((charone_skl - chartwo_skl)/ 5))
  31.         return calc
  32.     elif chartwo_skl > charone_skl:
  33.         calc = math.floor(((chartwo_skl - charone_skl)/ 5))
  34.         return calc
  35.     elif charone_skl == chartwo_skl:
  36.         calc = math.floor(((charone_skl - chartwo_skl)/ 5))
  37.         return calc
  38.  
  39. def mods():
  40.     global strength_mod
  41.     global skill_mod
  42.     global counter
  43.     strength_mod = str_mod(charone_strength, chartwo_strength)
  44.     skill_mod = skl_mod(charone_skill, chartwo_skill)
  45.     print "\nRound",counter
  46.     print "-------"
  47.     time.sleep(1)
  48.     print "\nFor this round, the strength modifier is:",strength_mod
  49.     time.sleep(0.20)
  50.     print "For this round, the skill modifier is: ",skill_mod
  51.     time.sleep(0.20)
  52.     diceroll(charone, chartwo)
  53.     print "\n"+str(charone)+"'s","dice roll is:",player1
  54.     time.sleep(1)
  55.     print "\n"+str(chartwo)+"'s","dice roll is:",player2
  56.    
  57. def diceroll(charone, chartwo):
  58.     print "\n"+str(charone)+" will roll the 6 sided dice first!"
  59.     time.sleep(0.5)
  60.     global player1
  61.     player1 = random.randint(1,6)
  62.     delay_print("\nRolling dice!")
  63.     global player2
  64.     player2 = random.randint(1,6)
  65.     time.sleep(0.5)
  66.     print "\nNow",chartwo,"will roll the 6 sided dice!"
  67.     time.sleep(0.5)
  68.     delay_print("\nRolling dice!")
  69. # problem function
  70. def suddendeath():
  71.     global charone_strength
  72.     global chartwo_strength
  73.     print "\n============"
  74.     print "SUDDEN DEATH"
  75.     print "============"
  76.     time.sleep(1)
  77.     player1 = random.randint(1,6)
  78.     player2 = random.randint(1,6)
  79.     print "\n"+str(charone)+" has rolled:",player1
  80.     time.sleep(0.5)
  81.     print "\n"+str(chartwo)+" has rolled:",player2
  82.     if player1 == player2:
  83.         print "\nIt's a draw!"
  84.         suddendeath()
  85.     if player1 > player2:
  86.         chartwo_strength = 0
  87.     elif player2 > player1:
  88.         charone_strength = 0
  89.  
  90. def battle(charone_str, chartwo_str, charone_skl, chartwo_skl, str_mod, skl_mod):
  91.     global charone_strength
  92.     global charone_skill
  93.     global chartwo_strength
  94.     global chartwo_skill
  95.     global counter
  96.     if str_mod < 3:
  97.         print "\nStrength modifier is too low, it will be increased by 5"
  98.         str_mod += 5
  99.         time.sleep(0.5)
  100.     if skl_mod < 3:
  101.         print "\nSkill modifier is too low, it will be increased by 5"
  102.         skl_mod += 5
  103.         time.sleep(0.5)
  104.     if player1 == player2:
  105.         print "\nThis round is a draw! No damage done"
  106.         counter += 1
  107.     elif player1 > player2:
  108.         if counter in [20,40,60,80,100,120,140,160,180,200]:
  109.             print "\nDuring this turn, a power up of +50% will be awarded"
  110.             charone_strength = charone_strength + (charone_strength/2)
  111.             time.sleep(0.5)
  112.             print "50% of",str(charone)+"'s strength will be dealt as damage to",chartwo
  113.             chartwo_strength = chartwo_strength - (charone_strength/2)
  114.             time.sleep(0.5)
  115.         else:
  116.             pass
  117.         charone_strength = charone_str + str_mod
  118.         charone_skill = charone_skl + skl_mod
  119.         chartwo_strength = chartwo_skl - str_mod
  120.         chartwo_skill = chartwo_skl - skl_mod
  121.         if charone_skill <= 0:
  122.             charone_skill = 0
  123.         elif chartwo_skill <= 0:
  124.             chartwo_skill = 0
  125.         print "-------------------------"
  126.         print charone+" won this round"
  127.         print "-------------------------"
  128.         print "\n"+"Character 1:",charone
  129.         print "Strength:",charone_strength
  130.         print "Skill:",charone_skill
  131.         time.sleep(1)
  132.         print "\nCharacter 2:",chartwo
  133.         print "Strength:",chartwo_strength
  134.         print "Skill:",chartwo_skill
  135.         print "-------------------"
  136.         counter += 1
  137.     elif player2 > player1:
  138.         if counter in [20,40,60,80,100,120,140,160,180,200]:
  139.             print "\nDuring this turn, a power up of +50% will be awarded"
  140.             chartwo_strength = chartwo_strength + (chartwo_strength/2)
  141.             time.sleep(0.5)
  142.             print "50% of",str(chartwo)+"'s strength will be dealt as damage to",charone
  143.             charone_strength = chartwo_strength - (charone_strength/2)
  144.             time.sleep(0.5)
  145.         else:
  146.             pass
  147.         chartwo_strength = chartwo_str + str_mod
  148.         chartwo_skill = chartwo_skl + skl_mod
  149.         charone_strength = charone_str - str_mod
  150.         charone_skill = charone_skl - skl_mod
  151.         if charone_skill <= 0:
  152.             charone_skill = 0
  153.         elif chartwo_skill <= 0:
  154.             chartwo_skill = 0
  155.         print "-------------------------"
  156.         print chartwo+" won this round"
  157.         print "-------------------------"
  158.         print "Character 1:",charone
  159.         print "Strength:",charone_strength
  160.         print "Skill:",charone_skill
  161.         time.sleep(1)
  162.         print "\nCharacter 2:",chartwo
  163.         print "Strength:",chartwo_strength
  164.         print "Skill:",chartwo_skill
  165.         print "-------------------"
  166.         counter += 1
  167.        
  168. charone = raw_input("\nEnter the name of character one: ")
  169. chartwo = raw_input("Enter the name of character two: ")
  170. time.sleep(1.5)
  171. print "\n",charone,"has encountered",chartwo
  172. delay_print("\nBattle Initiated!")
  173.  
  174. charone_strength = int(raw_input("\nEnter the strength score for "+str(charone)+": "))
  175. while charone_strength < 1 or charone_strength > 100:
  176.     print "Please enter a number from 1-100"
  177.     charone_strength = int(raw_input("\nEnter the strength score for "+str(charone)+": "))
  178.  
  179. charone_skill = int(raw_input("Enter the skill score for "+str(charone)+": "))
  180. while charone_skill < 1 or charone_skill > 100:
  181.     print "Please enter a number from 1-100"
  182.     charone_skill = int(raw_input("\nEnter the skill score for "+str(charone)+": "))
  183. time.sleep(1.0)
  184.  
  185. chartwo_strength = int(raw_input("\nEnter the strength score for "+str(chartwo)+": "))
  186. while chartwo_strength < 1 or chartwo_strength > 100:
  187.     print "Please enter a number from 1-100"
  188.     chartwo_strength = int(raw_input("\nEnter the strength score for "+str(chartwo)+": "))
  189.  
  190. chartwo_skill = int(raw_input("Enter the skill score for "+str(chartwo)+": "))
  191. while chartwo_skill < 1 or chartwo_skill > 100:
  192.     print "Please enter a number from 1-100"
  193.     chartwo_skill = int(raw_input("\nEnter the skill score for "+str(chartwo)+": "))
  194.  
  195. time.sleep(2)
  196. print "\nCharacter 1:",charone
  197. print "Strength:",charone_strength
  198. print "Skill:",charone_skill
  199. time.sleep(1)
  200. print "\nCharacter 2:",chartwo
  201. print "Strength:",chartwo_strength
  202. print "Skill:",chartwo_skill
  203. time.sleep(1)
  204.  
  205. #problem loop
  206. while charone_strength > 0 or chartwo_strength > 0:
  207.     if counter == 220:
  208.         print "\nRound 220 has been reached, Sudden Death Mode active!"
  209.         suddendeath()
  210.     else:
  211.         mods()
  212.         battle(charone_strength, chartwo_strength, charone_skill, chartwo_skill, strength_mod, skill_mod)
  213. else:
  214.     if charone_strength <= 0:
  215.         print "\n"+str(charone)+" has died!",chartwo,"wins!"
  216.         time.sleep(1)
  217.     elif chartwo_strength <= 0:
  218.         print "\n"+str(chartwo)+" has died!",charone,"wins!"
  219.         time.sleep(1)
  220.     play = raw_input("Would you like to play again? y/n: ")
  221.     if play in ["yes","y","Yes","Y"]:
  222.         execfile("gcse.py")
  223.     else:
  224.         print "Goodbye! Thanks for playing!"
  225.         exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement