Advertisement
Guest User

BATTLE

a guest
Jan 3rd, 2013
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 9.40 KB | None | 0 0
  1. from random import randint
  2.  
  3. #define basic info need for other classes
  4.  
  5. game_mode = "main menu"
  6.  
  7. class stats():
  8.    
  9.     strength = 5
  10.     constitution = 5
  11.     agility = 5
  12.     intelligence = 5
  13.  
  14. class monster():
  15.    
  16.     name = "Monster"
  17.     level = 0
  18.    
  19.     hp = 1
  20.     maxhp = 1
  21.     mp = 1
  22.     atk = 1
  23.     dfn = 1
  24.     crit = 0
  25.     dodge = 0
  26.  
  27.     actions = 1
  28.  
  29.     def action_1(self):
  30.         print "TEST"
  31.  
  32.     def action_2(self):
  33.         print "TEST"
  34.  
  35.     def action_2(self):
  36.         print "TEST"
  37.  
  38.     def action_2(self):
  39.         print "TEST"
  40.        
  41. class player():
  42.  
  43.     name = "Player"
  44.    
  45.     hp = 1
  46.     mp = 1
  47.     atk = 1
  48.     dfn = 1
  49.     crit = 0
  50.     dodge = 0
  51.  
  52. def playerchance():
  53.  
  54.     a = player.crit
  55.     b = monster.dodge
  56.    
  57.     chance = randint(1,100)
  58.  
  59.     if chance > 100 - ( 100 * a ):
  60.         return 1
  61.        
  62.     elif chance < 100 * b:
  63.         return -1
  64.    
  65.     else:
  66.         return 0
  67.  
  68. def monsterchance():
  69.  
  70.     a = monster.crit
  71.     b = player.dodge
  72.    
  73.     chance = randint(1,100)
  74.  
  75.     if chance > 100 - ( 100 * a ):
  76.         return 1
  77.        
  78.     elif chance < 100 * b:
  79.         return -1
  80.    
  81.     else:
  82.         return 0
  83.    
  84. #define player classes
  85. class hero():
  86.  
  87.     hp = stats.constitution * 4
  88.     mp = stats.intelligence * 2
  89.     atk = int(stats.strength / 2)
  90.     dfn = int(stats.constitution / 4)
  91.     crit = (stats.agility * 2) / float(100)
  92.     dodge = (stats.agility * 2) / float(100)
  93.    
  94.     action_name_1 = "Slash"
  95.     action_name_2 = "Battle Cry"
  96.     action_name_3 = "Heal"
  97.     action_name_4 = "Scan"
  98.  
  99.     def action_1(self):
  100.         #Slash
  101.  
  102.         x = playerchance()
  103.  
  104.         if x == 1:
  105.            
  106.             print "\nYou land a CRITICAL SLASH on " + monster.name + "."
  107.             print "Hitting for " + `player.atk` + " true damage!"
  108.             print "\nThe " + monster.name + " loses " + `player.atk` + "hp.."
  109.  
  110.             monster.hp = monster.hp - player.atk
  111.  
  112.         elif x == 0:
  113.            
  114.             damage = player.atk - monster.dfn
  115.            
  116.             print "\nYou slash at the " + monster.name + " for " + `player.atk` + " damage"
  117.             print "and it blocks " + `monster.dfn` + " of it."
  118.  
  119.             if damage > 0:
  120.  
  121.                 monster.hp = monster.hp - damage
  122.                 print "\nThe " + monster.name + " loses " + `damage` + "hp.."
  123.  
  124.             else:
  125.                 print "\nYour attack did nothing.."
  126.  
  127.         elif x == -1:
  128.  
  129.             print "\nYour attack completely missed!"
  130.  
  131.         else:
  132.             print "\nError! chance() failed!"
  133.  
  134.     def action_2(self):
  135.         print "You give a battle cry"
  136.  
  137.     def action_3(self):
  138.         print "You healed yourself"
  139.  
  140.     def action_4(self):
  141.         print "You scanned the monster:"
  142.  
  143. #define monster classes
  144.  
  145. class goblin():
  146.  
  147.     name = "Goblin"
  148.     level = 1
  149.  
  150.     maxhp = 20
  151.     hp = 20
  152.     mp = 10
  153.     atk = 2
  154.     dfn = 1
  155.     crit = 0.2
  156.     dodge = 0.1
  157.  
  158.     actions = 2
  159.  
  160.     def action_1(self):
  161.     #standard attack
  162.  
  163.         x = playerchance()
  164.  
  165.         if x == 1:
  166.            
  167.             print "\nThe " + monster.name + " lands a CRITICAL HIT on " + player.name + "."
  168.             print "Hitting for " + `monster.atk` + " true damage!"
  169.             print "\n" + player.name + " loses " + `monster.atk` + "hp.."
  170.  
  171.             player.hp = player.hp - monster.atk
  172.  
  173.         elif x == 0:
  174.            
  175.             damage = monster.atk - player.dfn
  176.            
  177.             print "\n"+ monster.name + " attacks for " + `monster.atk` + " damage"
  178.             print "and " + player.name + " blocks " + `player.dfn` + " of it."
  179.  
  180.             if damage > 0:
  181.  
  182.                 player.hp = player.hp - damage
  183.                 print "\n" + player.name + " loses " + `damage` + "hp.."
  184.  
  185.             else:
  186.                 print "\nIts attack did nothing.."
  187.  
  188.         elif x == -1:
  189.  
  190.             print "\nYou dodged the " + monster.name + "'s attack!"
  191.  
  192.         else:
  193.             print "\nError! chance() failed!"
  194.  
  195.        
  196.  
  197. class dragon():
  198.  
  199.     name = "Dragon"
  200.     level = 2
  201.  
  202.     maxhp = 200
  203.     hp = 200
  204.     mp = 100
  205.     atk = 20
  206.     dfn = 10
  207.     crit = 0.2
  208.     dodge = 0.2
  209.  
  210.     actions = 4
  211.  
  212.     def action_1(self):
  213.     #standard attack
  214.  
  215.         x = playerchance()
  216.  
  217.         if x == 1:
  218.            
  219.             print "\nThe " + monster.name + " lands a CRITICAL HIT on " + player.name + "."
  220.             print "Hitting for " + `monster.atk` + " true damage!"
  221.             print "\n" + player.name + " loses " + `monster.atk` + "hp.."
  222.  
  223.             player.hp = player.hp - monster.atk
  224.  
  225.         elif x == 0:
  226.            
  227.             damage = monster.atk - player.dfn
  228.            
  229.             print "\n" + monster.name + " attacks for " + `monster.atk` + " damage"
  230.             print "and " + player.name + " blocks " + `player.dfn` + " of it."
  231.  
  232.             if damage > 0:
  233.  
  234.                 player.hp = player.hp - damage
  235.                 print "\n" + player.name + " loses " + `damage` + "hp.."
  236.  
  237.             else:
  238.                 print "\nIts attack did nothing.."
  239.  
  240.         elif x == -1:
  241.  
  242.             print "\nYou dodged the " + monster.name + "'s attack!"
  243.  
  244.         else:
  245.             print "\nError! chance() failed!"
  246.  
  247. #define battle functions
  248. monster = goblin()
  249.  
  250. #
  251. def hp_update():
  252.  
  253.     a = monster.hp
  254.     b = monster.maxhp
  255.     c = player.hp
  256.  
  257.     if float( a )/ b  >= 0.75:
  258.         print "\nThe " + monster.name + " appears healthy"
  259.     elif float( a )/ b < 0.75 and float( a )/ b  >= 0.5:
  260.         print "\nThe " + monster.name + " seems injured"
  261.     elif float( a )/ b  < 0.5 and float( a )/ b  >= 0.25:
  262.         print "\nThe " + monster.name + " is in alot of pain"
  263.     elif float( a )/ b  < 0.25 and float( a )/ b  >= 0.1:
  264.         print "\nThe " + monster.name + " is gravely wounded"
  265.     elif float( a )/ b  < 0.1:
  266.         print "\nThe " + monster.name + " could die at any second"
  267.     else:
  268.         print "\nError! hp_update() failed!"
  269.        
  270.     print "and you have " + `c` + "hp remaining.\n"
  271.  
  272. #      
  273. def action_menu():
  274.  
  275.     action_menu_error = 1
  276.    
  277.     print "1." + player.action_name_1
  278.     print "2." + player.action_name_2
  279.     print "3." + player.action_name_3
  280.     print "4." + player.action_name_4
  281.  
  282.     while action_menu_error == 1:
  283.  
  284.         action = raw_input("Choose an action: ")
  285.  
  286.         if action == "1":
  287.             player.action_1()
  288.             action_menu_error = 0
  289.         elif action == "2":
  290.             player.action_2()
  291.             action_menu_error = 0
  292.         elif action == "3":
  293.             player.action_3()
  294.             action_menu_error = 0
  295.         elif action == "4":
  296.             player.action_4()
  297.             action_menu_error = 0
  298.         else:
  299.             print "Invalid action!"
  300.  
  301. #
  302. def deathcheck():
  303.     if monster.hp <= 0:
  304.         print "\nAnds falls to the ground, defeated.."
  305.         print "\nYOU ARE VICTORIOUS!"
  306.  
  307.         continue_error = 1
  308.         while continue_error == 1:
  309.             nextlevel = raw_input("Continue on to the next monster? y/n? ")
  310.  
  311.             if nextlevel == "y":
  312.                 monster.level = monster.level + 1
  313.                 break
  314.                
  315.             elif nextlevel == "n":
  316.                 game_mode = "main menu"
  317.                 break
  318.                
  319.             else:
  320.                 print "\nInvalid selection!"
  321.                
  322.        
  323.     elif player.hp <= 0:
  324.         print "\nAnd with that, your quest is over.."
  325.         print "\nYOU HAVE BEEN DEFEATED!"
  326.  
  327.         raw_input()
  328.         game_mode = "main menu"
  329.        
  330.  
  331. #main menu
  332. while game_mode == "main menu":  
  333.     print "**********************************"
  334.     print "******  PREPARE YOURSELF *********"
  335.     print "************** FOR ***************"
  336.     print "********** !!BATTLE!! ************"
  337.     print "**********************************\n\n"
  338.  
  339.     print "  1. ARCADE MODE       2. INFO    "
  340.     print "  **************       *******    \n\n"
  341.  
  342.  
  343.     main_menu_error = 1
  344.  
  345.     while main_menu_error == 1:
  346.        
  347.         menu_selection = raw_input("      Select option: ")
  348.         if menu_selection == "1":
  349.             game_mode = "arcade"
  350.             main_menu_error = 0
  351.         else:
  352.             print "Invalid selction!"
  353.  
  354. ##################   Arcade mode
  355.  
  356. while game_mode == "arcade":
  357.  
  358.     player = hero()
  359.     monster = goblin()
  360.  
  361. #intro
  362.  
  363.     player.name = raw_input("\nPlease enter your name: ")
  364.  
  365.     print "\nAre you ready?"
  366.     print "\nReady to take up arms \nagainst the monsterous \nhordes that await you?"
  367.     print "\nYou should be.\n\n..because they're \nready for you."
  368.     print "\nPrepare yourself, " + player.name + "!"
  369.     print "\nPREPARE YOURSELF FOR BATTLE!!!"
  370.     raw_input("\n(hit enter to continue)")
  371.  
  372. # Level 1 (Goblin)
  373.  
  374.     print "\n\nA NEW CHALLENGER HAS APPEARED!"
  375.     print "A lone Goblin warrior stands before you.\n"
  376.  
  377.     monster = goblin()
  378.     while monster.level == 1:
  379.         hp_update()
  380.         action_menu()
  381.         deathcheck()
  382.         monster.action_1()
  383.         deathcheck()
  384.        
  385.            
  386.                
  387.        
  388. # Level 2 (??)
  389.        
  390.     print "\n\nA NEW CHALLENGER HAS APPEARED!"
  391.     print "You stand in awe of a mighty Dragon.\n"
  392.  
  393.     monster = dragon()
  394.     while monster.level == 2:
  395.         hp_update()
  396.         action_menu()
  397.         deathcheck()
  398.         monster.action_1()
  399.         deathcheck()
  400.        
  401.     break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement