from random import randint #define basic info need for other classes game_mode = "main menu" class stats(): strength = 5 constitution = 5 agility = 5 intelligence = 5 class monster(): name = "Monster" level = 0 hp = 1 maxhp = 1 mp = 1 atk = 1 dfn = 1 crit = 0 dodge = 0 actions = 1 def action_1(self): print "TEST" def action_2(self): print "TEST" def action_2(self): print "TEST" def action_2(self): print "TEST" class player(): name = "Player" hp = 1 mp = 1 atk = 1 dfn = 1 crit = 0 dodge = 0 def playerchance(): a = player.crit b = monster.dodge chance = randint(1,100) if chance > 100 - ( 100 * a ): return 1 elif chance < 100 * b: return -1 else: return 0 def monsterchance(): a = monster.crit b = player.dodge chance = randint(1,100) if chance > 100 - ( 100 * a ): return 1 elif chance < 100 * b: return -1 else: return 0 #define player classes class hero(): hp = stats.constitution * 4 mp = stats.intelligence * 2 atk = int(stats.strength / 2) dfn = int(stats.constitution / 4) crit = (stats.agility * 2) / float(100) dodge = (stats.agility * 2) / float(100) action_name_1 = "Slash" action_name_2 = "Battle Cry" action_name_3 = "Heal" action_name_4 = "Scan" def action_1(self): #Slash x = playerchance() if x == 1: print "\nYou land a CRITICAL SLASH on " + monster.name + "." print "Hitting for " + `player.atk` + " true damage!" print "\nThe " + monster.name + " loses " + `player.atk` + "hp.." monster.hp = monster.hp - player.atk elif x == 0: damage = player.atk - monster.dfn print "\nYou slash at the " + monster.name + " for " + `player.atk` + " damage" print "and it blocks " + `monster.dfn` + " of it." if damage > 0: monster.hp = monster.hp - damage print "\nThe " + monster.name + " loses " + `damage` + "hp.." else: print "\nYour attack did nothing.." elif x == -1: print "\nYour attack completely missed!" else: print "\nError! chance() failed!" def action_2(self): print "You give a battle cry" def action_3(self): print "You healed yourself" def action_4(self): print "You scanned the monster:" #define monster classes class goblin(): name = "Goblin" level = 1 maxhp = 20 hp = 20 mp = 10 atk = 2 dfn = 1 crit = 0.2 dodge = 0.1 actions = 2 def action_1(self): #standard attack x = playerchance() if x == 1: print "\nThe " + monster.name + " lands a CRITICAL HIT on " + player.name + "." print "Hitting for " + `monster.atk` + " true damage!" print "\n" + player.name + " loses " + `monster.atk` + "hp.." player.hp = player.hp - monster.atk elif x == 0: damage = monster.atk - player.dfn print "\n"+ monster.name + " attacks for " + `monster.atk` + " damage" print "and " + player.name + " blocks " + `player.dfn` + " of it." if damage > 0: player.hp = player.hp - damage print "\n" + player.name + " loses " + `damage` + "hp.." else: print "\nIts attack did nothing.." elif x == -1: print "\nYou dodged the " + monster.name + "'s attack!" else: print "\nError! chance() failed!" class dragon(): name = "Dragon" level = 2 maxhp = 200 hp = 200 mp = 100 atk = 20 dfn = 10 crit = 0.2 dodge = 0.2 actions = 4 def action_1(self): #standard attack x = playerchance() if x == 1: print "\nThe " + monster.name + " lands a CRITICAL HIT on " + player.name + "." print "Hitting for " + `monster.atk` + " true damage!" print "\n" + player.name + " loses " + `monster.atk` + "hp.." player.hp = player.hp - monster.atk elif x == 0: damage = monster.atk - player.dfn print "\n" + monster.name + " attacks for " + `monster.atk` + " damage" print "and " + player.name + " blocks " + `player.dfn` + " of it." if damage > 0: player.hp = player.hp - damage print "\n" + player.name + " loses " + `damage` + "hp.." else: print "\nIts attack did nothing.." elif x == -1: print "\nYou dodged the " + monster.name + "'s attack!" else: print "\nError! chance() failed!" #define battle functions monster = goblin() # def hp_update(): a = monster.hp b = monster.maxhp c = player.hp if float( a )/ b >= 0.75: print "\nThe " + monster.name + " appears healthy" elif float( a )/ b < 0.75 and float( a )/ b >= 0.5: print "\nThe " + monster.name + " seems injured" elif float( a )/ b < 0.5 and float( a )/ b >= 0.25: print "\nThe " + monster.name + " is in alot of pain" elif float( a )/ b < 0.25 and float( a )/ b >= 0.1: print "\nThe " + monster.name + " is gravely wounded" elif float( a )/ b < 0.1: print "\nThe " + monster.name + " could die at any second" else: print "\nError! hp_update() failed!" print "and you have " + `c` + "hp remaining.\n" # def action_menu(): action_menu_error = 1 print "1." + player.action_name_1 print "2." + player.action_name_2 print "3." + player.action_name_3 print "4." + player.action_name_4 while action_menu_error == 1: action = raw_input("Choose an action: ") if action == "1": player.action_1() action_menu_error = 0 elif action == "2": player.action_2() action_menu_error = 0 elif action == "3": player.action_3() action_menu_error = 0 elif action == "4": player.action_4() action_menu_error = 0 else: print "Invalid action!" # def deathcheck(): if monster.hp <= 0: print "\nAnds falls to the ground, defeated.." print "\nYOU ARE VICTORIOUS!" continue_error = 1 while continue_error == 1: nextlevel = raw_input("Continue on to the next monster? y/n? ") if nextlevel == "y": monster.level = monster.level + 1 break elif nextlevel == "n": game_mode = "main menu" break else: print "\nInvalid selection!" elif player.hp <= 0: print "\nAnd with that, your quest is over.." print "\nYOU HAVE BEEN DEFEATED!" raw_input() game_mode = "main menu" #main menu while game_mode == "main menu": print "**********************************" print "****** PREPARE YOURSELF *********" print "************** FOR ***************" print "********** !!BATTLE!! ************" print "**********************************\n\n" print " 1. ARCADE MODE 2. INFO " print " ************** ******* \n\n" main_menu_error = 1 while main_menu_error == 1: menu_selection = raw_input(" Select option: ") if menu_selection == "1": game_mode = "arcade" main_menu_error = 0 else: print "Invalid selction!" ################## Arcade mode while game_mode == "arcade": player = hero() monster = goblin() #intro player.name = raw_input("\nPlease enter your name: ") print "\nAre you ready?" print "\nReady to take up arms \nagainst the monsterous \nhordes that await you?" print "\nYou should be.\n\n..because they're \nready for you." print "\nPrepare yourself, " + player.name + "!" print "\nPREPARE YOURSELF FOR BATTLE!!!" raw_input("\n(hit enter to continue)") # Level 1 (Goblin) print "\n\nA NEW CHALLENGER HAS APPEARED!" print "A lone Goblin warrior stands before you.\n" monster = goblin() while monster.level == 1: hp_update() action_menu() deathcheck() monster.action_1() deathcheck() # Level 2 (??) print "\n\nA NEW CHALLENGER HAS APPEARED!" print "You stand in awe of a mighty Dragon.\n" monster = dragon() while monster.level == 2: hp_update() action_menu() deathcheck() monster.action_1() deathcheck() break