Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from random import randint
- from random import choice
- from random import sample
- def Battle():
- print("""
- ______ ___ _____ _____ _ _____
- | ___ \/ _ \_ _|_ _| | | ___|
- | |_/ / /_\ \| | | | | | | |__
- | ___ \ _ || | | | | | | __|
- | |_/ / | | || | | | | |____| |___
- \____/\_| |_/\_/ \_/ \_____/\____/
- """)
- def YourMove():
- print("""
- __ _______ _ _______ ___ ________ _ _ _____
- \ \ / / _ | | | | ___ \ | \/ | _ || | | | ___|
- \ V /| | | | | | | |_/ / | . . | | | || | | | |__
- \ / | | | | | | | / | |\/| | | | || | | | __|
- | | \ \_/ / |_| | |\ \ | | | \ \_/ /\ \_/ / |___
- \_/ \___/ \___/\_| \_| \_| |_/\___/ \___/\____/
- """)
- def FoesMove():
- print("""
- _____ ___ _____ _ ____ __ __ _____ _______
- | ___/ _ \| ____( ) ___| | \/ |/ _ \ \ / / ____|
- | |_ | | | | _| |/\___ \ | |\/| | | | \ \ / /| _|
- | _|| |_| | |___ ___) | | | | | |_| |\ V / | |___
- |_| \___/|_____| |____/ |_| |_|\___/ \_/ |_____|
- """)
- def TurnEnd():
- print("""
- _____ _ _ ____ _ _ _____ _ _ ____
- |_ _| | | | _ \| \ | | | ____| \ | | _ \
- | | | | | | |_) | \| | | _| | \| | | | |
- | | | |_| | _ <| |\ | | |___| |\ | |_| |
- |_| \___/|_| \_\_| \_| |_____|_| \_|____/
- """)
- def FetchData(LookingFor):
- #Creates and returns a list of meaningful data from Game_Data depending on what parameter is being searched for.
- AllData = open("Game_Data.txt","r").readlines()
- ValidData = []
- for Index, Line in enumerate(AllData):
- AllData[Index] = Line[:-1]
- AllData.remove("")
- StartOfValid = AllData.index(LookingFor.upper())
- EndOfValid = AllData.index(str(LookingFor.upper()+" END"))
- for ValidEntry in range(StartOfValid+1,EndOfValid-1):
- ValidData.append(AllData[ValidEntry])
- return ValidData
- def SeparateMoveData(MoveLineData):
- #Separates and returns the move TYPE, DAMAGE, and NAME
- MoveLineData = MoveLineData.split(",")
- return MoveLineData[0],int(MoveLineData[1]),MoveLineData[2]
- def IsolateMoveNames(Abilities):
- #Isolates the names of moves and returns them as a list.
- AbilityNames = []
- for Ability in Abilities:
- AbilityNames.append(Ability[2])
- return AbilityNames
- class Creature:
- def __init__(self,Level):
- #Initialises an instance of the creature class. Assigns statistics and moves for the creature to use in battle.
- self.IsAlive = True
- self.Name = self.GetName()
- self.Level = Level
- self.Health = 90 + (Level * 10)
- self.Defense = randint(10,20) + (Level * 10)
- self.Agility = randint(40,50) + (Level * 10)
- Specialisations = ["Magic","Physical"]
- self.Specialisation = choice(Specialisations)
- if self.Specialisation == "Magic":
- self.Strength = randint(10,20) + (Level * 10)
- self.Intellect = randint(40,50) + (Level * 10)
- self.Weakness = "Physical"
- else:
- self.Strength = randint(40,50) + (Level * 10)
- self.Intellect = randint(10,20) + (Level * 10)
- self.Weakness = "Magic"
- self.Abilities = self.GetAbilities(self.Specialisation)
- self.Type = "AI"
- def GetName(self):
- #Acquires name for monster from Game_Data file
- Names = FetchData("Names")
- return choice(Names)
- def GetAbilities(self,Specialisation):
- #Acquires 4 abilities from Game_Data file, returns the following values seperately: MOVETYPE, DAMAGE, MOVENAME
- Abilities = FetchData(Specialisation)
- for Index, Ability in enumerate(Abilities):
- Abilities[Index] = [SeparateMoveData(Ability)[0],SeparateMoveData(Ability)[1],SeparateMoveData(Ability)[2]]
- return sample(Abilities,4)
- def PrintStats(self,PrintAll):
- #Enables the easy printing of the stats, parameter is boolean, TRUE returns all stats, FALSE returns just essential stats
- print("- - - - - - - - - - - - - - - - -")
- print("STATISTICAL BREAKDOWN")
- print("- - - - - - - - - - - - - - - - -")
- print("Name.............",self.Name)
- print("Level............",self.Level)
- print("Health...........",self.Health)
- if PrintAll == True:
- print("Defense..........",self.Defense)
- print("Agility..........",self.Agility)
- print("Strength.........",self.Strength)
- print("Intellect........",self.Intellect)
- print("Specialisation...",self.Specialisation)
- print("Weakness.........",self.Weakness)
- print("Abilities........",", ".join(IsolateMoveNames(self.Abilities)))
- print("- - - - - - - - - - - - - - - - -\n")
- def GetAttack(self):
- #Acquires a move for the object to utilise in combat and returns it in it's SeparateMoveData list form TYPE, DAMAGE, and NAME.
- if self.IsAlive == True:
- return self.CalculateAttack(choice(self.Abilities))
- else:
- self.Died()
- def CalculateAttack(self,SeparateAttackData):
- #Takes the chosen attack and applies multiplier damage based on object stats.
- if SeparateAttackData[0] == "Physical":
- SeparateAttackData[1] += SeparateAttackData[1]*(self.Strength/100)
- elif SeparateAttackData[0] == "Magic":
- SeparateAttackData[1] += SeparateAttackData[1]*(self.Intellect/100)
- return SeparateAttackData
- def ReceivingAttack(self,SeparateAttackData,AttackerName):
- #Declares what happens when the object receives an attack, utilises the list form of an attack TYPE, DAMAGE, and NAME.
- #ADD CHANCE TO MISS BASED ON AGILITY NEGATED BY AGILITY OF ENEMY
- #Deals additional damage if the attack is of the same type as the object's weakness.
- if SeparateAttackData[0] == self.Weakness:
- print(AttackerName+"'s attack",SeparateAttackData[2],"is type",SeparateAttackData[0]+". This is",self.Name+"'s weakness. The attack is super effective")
- SeparateAttackData[1] += SeparateAttackData[1]*(0.4)
- #Reduces incoming attack based on object's defense rating.
- SeparateAttackData[1] -= SeparateAttackData[1]*(self.Defense/100)
- SeparateAttackData[1] = round(SeparateAttackData[1])
- print(SeparateAttackData[2],"hits",self.Name,"for",SeparateAttackData[1],"damage.")
- self.Health -= SeparateAttackData[1]
- self.PrintStats(False)
- if self.Health <= 0:
- self.Died()
- def Died(self):
- #Declares what happens when the object dies.
- self.IsAlive = False
- print(self.Name,"has been killed.\n\n")
- class Player(Creature):
- #Initialises an instance of the player class, creates a character for the player to play.
- def __init__(self,Name,Level,Specialisation):
- self.IsAlive = True
- self.Experience = 0
- self.Name = Name
- self.Level = Level
- self.Health = 90 + (Level * 10)
- self.Defense = randint(10,20) + (Level * 10)
- self.Agility = randint(40,50) + (Level * 10)
- self.Specialisation = Specialisation
- if self.Specialisation == "Magic":
- self.Strength = randint(10,20) + (Level * 10)
- self.Intellect = randint(40,50) + (Level * 10)
- self.Weakness = "Physical"
- else:
- self.Strength = randint(40,50) + (Level * 10)
- self.Intellect = randint(10,20) + (Level * 10)
- self.Weakness = "Magic"
- self.Abilities = self.GetAbilities(self.Specialisation)
- self.Type = "Player"
- def GetAttack(self):
- #Asks for the user to input the ability they would like to attack with.
- if self.IsAlive == True:
- print("Which ability would you like to use?")
- for Index, Ability in enumerate(IsolateMoveNames(self.Abilities)):
- print(str(Index + 1)+")",Ability)
- UserInp = input()
- print()
- while (UserInp.title() not in IsolateMoveNames(self.Abilities)) and (UserInp != "1" and UserInp != "2" and UserInp != "3" and UserInp != "4"):
- print("Not a valid input, please try again.")
- UserInp = input()
- print()
- if (UserInp == "1" or UserInp == "2" or UserInp == "3" or UserInp == "4"):
- UserInp = int(UserInp)-1
- else:
- #Converts what the user enters back into it's SeparateMoveData form and returns it TYPE, DAMAGE, and NAME.
- UserInp = IsolateMoveNames(self.Abilities).index(UserInp.title())
- return self.CalculateAttack(self.Abilities[UserInp])
- else:
- self.Died()
Add Comment
Please, Sign In to add comment