uccjshrimpton

Dungeon Cleaner Battle CLASSES/FUNCTIONS WIP

May 23rd, 2016
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.67 KB | None | 0 0
  1. from random import randint
  2. from random import choice
  3. from random import sample
  4.  
  5. def Battle():
  6.     print("""
  7. ______  ___ _____ _____ _      _____
  8. | ___ \/ _ \_   _|_   _| |    |  ___|
  9. | |_/ / /_\ \| |   | | | |    | |__
  10. | ___ \ _  || |   | | | |    |  __|
  11. | |_/ / | | || |   | | | |____| |___
  12. \____/\_| |_/\_/   \_/ \_____/\____/
  13. """)
  14.  
  15. def YourMove():
  16.     print("""
  17. __   _______ _   _______  ___  ________  _   _ _____
  18. \ \ / /  _  | | | | ___ \ |  \/  |  _  || | | |  ___|
  19. \ V /| | | | | | | |_/ / | .  . | | | || | | | |__
  20.  \ / | | | | | | |    /  | |\/| | | | || | | |  __|
  21.  | | \ \_/ / |_| | |\ \ | |  | \ \_/ /\ \_/ / |___
  22.  \_/  \___/ \___/\_| \_| \_|  |_/\___/  \___/\____/
  23. """)
  24.  
  25. def FoesMove():
  26.     print("""
  27.  _____ ___  _____ _ ____    __  __  _____     _______
  28. |  ___/ _ \| ____( ) ___|  |  \/  |/ _ \ \  / / ____|
  29. | |_ | | | |  _| |/\___ \ | |\/| | | | \ \ / /|  _|
  30. |  _|| |_| | |___   ___) | | |  | | |_| |\ V / | |___
  31. |_|   \___/|_____| |____/  |_|  |_|\___/  \_/  |_____|
  32.  
  33. """)
  34.  
  35. def TurnEnd():
  36.     print("""
  37. _____ _   _ ____  _   _   _____ _   _ ____
  38. |_   _| | | |  _ \| \ | | | ____| \ | |  _ \
  39.  | | | | | | |_) |  \| | |  _| |  \| | | | |
  40.  | | | |_| |  _ <| |\ | | |___| |\ | |_| |
  41.  |_|  \___/|_| \_\_| \_| |_____|_| \_|____/
  42. """)
  43.  
  44. def FetchData(LookingFor):
  45.     #Creates and returns a list of meaningful data from Game_Data depending on what parameter is being searched for.
  46.     AllData = open("Game_Data.txt","r").readlines()
  47.     ValidData = []
  48.  
  49.     for Index, Line in enumerate(AllData):
  50.         AllData[Index] = Line[:-1]
  51.     AllData.remove("")
  52.  
  53.     StartOfValid = AllData.index(LookingFor.upper())
  54.     EndOfValid = AllData.index(str(LookingFor.upper()+" END"))
  55.  
  56.     for ValidEntry in range(StartOfValid+1,EndOfValid-1):
  57.         ValidData.append(AllData[ValidEntry])
  58.  
  59.     return ValidData
  60.  
  61. def SeparateMoveData(MoveLineData):
  62.     #Separates and returns the move TYPE, DAMAGE, and NAME
  63.     MoveLineData = MoveLineData.split(",")
  64.     return MoveLineData[0],int(MoveLineData[1]),MoveLineData[2]
  65.  
  66. def IsolateMoveNames(Abilities):
  67.     #Isolates the names of moves and returns them as a list.
  68.     AbilityNames = []
  69.     for Ability in Abilities:
  70.         AbilityNames.append(Ability[2])
  71.     return AbilityNames
  72.  
  73. class Creature:
  74.     def __init__(self,Level):
  75.         #Initialises an instance of the creature class. Assigns statistics and moves for the creature to use in battle.
  76.         self.IsAlive = True
  77.         self.Name = self.GetName()
  78.         self.Level = Level
  79.         self.Health = 90 + (Level * 10)
  80.         self.Defense = randint(10,20) + (Level * 10)
  81.         self.Agility = randint(40,50) + (Level * 10)
  82.         Specialisations = ["Magic","Physical"]
  83.         self.Specialisation = choice(Specialisations)
  84.         if self.Specialisation == "Magic":
  85.             self.Strength = randint(10,20) + (Level * 10)
  86.             self.Intellect = randint(40,50) + (Level * 10)
  87.             self.Weakness = "Physical"
  88.         else:
  89.             self.Strength = randint(40,50) + (Level * 10)
  90.             self.Intellect = randint(10,20) + (Level * 10)
  91.             self.Weakness = "Magic"
  92.         self.Abilities = self.GetAbilities(self.Specialisation)
  93.         self.Type = "AI"
  94.  
  95.     def GetName(self):
  96.         #Acquires name for monster from Game_Data file
  97.         Names = FetchData("Names")
  98.         return choice(Names)
  99.  
  100.     def GetAbilities(self,Specialisation):
  101.         #Acquires 4 abilities from Game_Data file, returns the following values seperately: MOVETYPE, DAMAGE, MOVENAME
  102.         Abilities = FetchData(Specialisation)
  103.  
  104.         for Index, Ability in enumerate(Abilities):
  105.              Abilities[Index] = [SeparateMoveData(Ability)[0],SeparateMoveData(Ability)[1],SeparateMoveData(Ability)[2]]
  106.  
  107.         return sample(Abilities,4)
  108.  
  109.     def PrintStats(self,PrintAll):
  110.         #Enables the easy printing of the stats, parameter is boolean, TRUE returns all stats, FALSE returns just essential stats
  111.         print("- - - - - - - - - - - - - - - - -")
  112.         print("STATISTICAL BREAKDOWN")
  113.         print("- - - - - - - - - - - - - - - - -")
  114.         print("Name.............",self.Name)
  115.         print("Level............",self.Level)
  116.         print("Health...........",self.Health)
  117.         if PrintAll == True:
  118.             print("Defense..........",self.Defense)
  119.             print("Agility..........",self.Agility)
  120.             print("Strength.........",self.Strength)
  121.             print("Intellect........",self.Intellect)
  122.             print("Specialisation...",self.Specialisation)
  123.             print("Weakness.........",self.Weakness)
  124.             print("Abilities........",", ".join(IsolateMoveNames(self.Abilities)))
  125.         print("- - - - - - - - - - - - - - - - -\n")
  126.  
  127.     def GetAttack(self):
  128.         #Acquires a move for the object to utilise in combat and returns it in it's SeparateMoveData list form TYPE, DAMAGE, and NAME.
  129.         if self.IsAlive == True:
  130.             return self.CalculateAttack(choice(self.Abilities))
  131.  
  132.         else:
  133.             self.Died()
  134.  
  135.     def CalculateAttack(self,SeparateAttackData):
  136.         #Takes the chosen attack and applies multiplier damage based on object stats.
  137.         if SeparateAttackData[0] == "Physical":
  138.             SeparateAttackData[1] += SeparateAttackData[1]*(self.Strength/100)
  139.         elif SeparateAttackData[0] == "Magic":
  140.             SeparateAttackData[1] += SeparateAttackData[1]*(self.Intellect/100)
  141.         return SeparateAttackData
  142.  
  143.     def ReceivingAttack(self,SeparateAttackData,AttackerName):
  144.         #Declares what happens when the object receives an attack, utilises the list form of an attack TYPE, DAMAGE, and NAME.
  145.  
  146.         #ADD CHANCE TO MISS BASED ON AGILITY NEGATED BY AGILITY OF ENEMY
  147.  
  148.         #Deals additional damage if the attack is of the same type as the object's weakness.
  149.         if SeparateAttackData[0] == self.Weakness:
  150.             print(AttackerName+"'s attack",SeparateAttackData[2],"is type",SeparateAttackData[0]+". This is",self.Name+"'s weakness. The attack is super effective")
  151.             SeparateAttackData[1] += SeparateAttackData[1]*(0.4)
  152.  
  153.         #Reduces incoming attack based on object's defense rating.
  154.         SeparateAttackData[1] -= SeparateAttackData[1]*(self.Defense/100)
  155.         SeparateAttackData[1] = round(SeparateAttackData[1])
  156.         print(SeparateAttackData[2],"hits",self.Name,"for",SeparateAttackData[1],"damage.")
  157.  
  158.         self.Health -= SeparateAttackData[1]
  159.  
  160.         self.PrintStats(False)
  161.  
  162.         if self.Health <= 0:
  163.             self.Died()
  164.  
  165.     def Died(self):
  166.         #Declares what happens when the object dies.
  167.         self.IsAlive = False
  168.         print(self.Name,"has been killed.\n\n")
  169.  
  170. class Player(Creature):
  171.     #Initialises an instance of the player class, creates a character for the player to play.
  172.     def __init__(self,Name,Level,Specialisation):
  173.         self.IsAlive = True
  174.         self.Experience = 0
  175.         self.Name = Name
  176.         self.Level = Level
  177.         self.Health = 90 + (Level * 10)
  178.         self.Defense = randint(10,20) + (Level * 10)
  179.         self.Agility = randint(40,50) + (Level * 10)
  180.         self.Specialisation = Specialisation
  181.         if self.Specialisation == "Magic":
  182.             self.Strength = randint(10,20) + (Level * 10)
  183.             self.Intellect = randint(40,50) + (Level * 10)
  184.             self.Weakness = "Physical"
  185.         else:
  186.             self.Strength = randint(40,50) + (Level * 10)
  187.             self.Intellect = randint(10,20) + (Level * 10)
  188.             self.Weakness = "Magic"
  189.         self.Abilities = self.GetAbilities(self.Specialisation)
  190.         self.Type = "Player"
  191.  
  192.     def GetAttack(self):
  193.         #Asks for the user to input the ability they would like to attack with.
  194.         if self.IsAlive == True:
  195.             print("Which ability would you like to use?")
  196.             for Index, Ability in enumerate(IsolateMoveNames(self.Abilities)):
  197.                 print(str(Index + 1)+")",Ability)
  198.             UserInp = input()
  199.             print()
  200.  
  201.             while (UserInp.title() not in IsolateMoveNames(self.Abilities)) and (UserInp != "1" and UserInp != "2" and UserInp != "3" and UserInp != "4"):
  202.                 print("Not a valid input, please try again.")
  203.                 UserInp = input()
  204.                 print()
  205.  
  206.             if (UserInp == "1" or UserInp == "2" or UserInp == "3" or UserInp == "4"):
  207.                 UserInp = int(UserInp)-1
  208.             else:
  209.                 #Converts what the user enters back into it's SeparateMoveData form and returns it TYPE, DAMAGE, and NAME.
  210.                 UserInp = IsolateMoveNames(self.Abilities).index(UserInp.title())
  211.  
  212.             return self.CalculateAttack(self.Abilities[UserInp])
  213.         else:
  214.             self.Died()
Add Comment
Please, Sign In to add comment