Advertisement
thepokedraglash

Untitled

Jan 12th, 2023 (edited)
365
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.84 KB | Source Code | 0 0
  1. #
  2. #   Pokemon Battle Simulator Python Code
  3. #   Created by Draglash for PKA
  4. #   http://aminoapps.com/p/swodup
  5. #
  6.  
  7. import random
  8.  
  9. class Pokemon:
  10.     def __init__(self, name, type1, type2, hp, atk, df, spatk, spdf, spd, move1, move2, move3, move4):
  11.         self.name = name
  12.         self.type1 = type1
  13.         self.type2 = type2
  14.         self.hp = hp
  15.         self.atk = atk
  16.         self.df = df
  17.         self.spatk = spatk
  18.         self.spdf= spdf
  19.         self.spd = spd
  20.         self.move1 = move1
  21.         self.move2 = move2
  22.         self.move3 = move3
  23.         self.move4 = move4
  24.    
  25.      
  26. class Move:
  27.     def __init__(self, name, form, typ, pwr):
  28.         self.name = name
  29.         self.form = form
  30.         self.typ = typ
  31.         self.pwr = pwr
  32.        
  33.  
  34. Flamethrower = Move("Flamethrower", "Special", "Fire", 90)
  35. Slash = Move("Slash", "Physical", "Normal", 70)
  36. Air_Slash = Move("Air Slash", "Special", "Flying", 75)
  37. Fire_Fang = Move("Fire Fang", "Physical","Fire", 65)
  38. Aqua_Tail = Move("Aqua Tail", "Physical", "Water", 90)
  39. Water_Pulse = Move("Water Pulse", "Special", "Water", 60)
  40. Bite = Move("Bite", "Physical","Dark", 60)
  41. Rapid_Spin = Move("Rapid Spin", "Physical", "Normal", 50)
  42. Seed_Bomb = Move("Seed Bomb","Physical","Grass",60)
  43. Sludge_Bomb = Move("Sludge Bomb", "Special","Poison", 90)
  44. Razor_Leaf = Move("Razor Leaf", "Physical","Grass", 55)
  45. Double_Edge = Move("Double Edge","Physical","Normal", 120)
  46.    
  47. Pok1 = Pokemon("Charizard", "Fire", "Flying", 185, 149, 143, 177, 150, 167, Flamethrower, Air_Slash, Fire_Fang, Slash)
  48. Pok2 = Pokemon("Blastoise", "Water", None, 186, 148, 167, 150, 172, 143, Water_Pulse, Aqua_Tail, Bite, Rapid_Spin)
  49. Pok3 = Pokemon("Venusaur", "Grass", "Poison", 187, 147, 148, 167, 167, 145, Seed_Bomb, Sludge_Bomb, Double_Edge, Razor_Leaf)
  50.  
  51.  
  52. def PokAttack(pok1, pok2, move):
  53.     critChance = [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1.5]
  54.     randDamage = [85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100]
  55.     STABdmg = 1
  56.     gamestate = 0   # if gamestate = 1, Pokemon is fainted and game is over
  57.     if move.typ == pok1.type1:
  58.         STABdmg = 1.5
  59.     elif move.typ == pok1.type2:
  60.         STABdmg = 1.5
  61.     else: pass
  62.  
  63.     dmg = move.pwr
  64.    
  65.     # changes formula so moves use the correct attack stat
  66.     if move.form == "Physical" :
  67.         damage = (((22 * dmg * (pok1.atk / pok2.df)) / 50) + 2) * random.choice (critChance) * (random. choice (randDamage)) * STABdmg
  68.     else:
  69.         damage = (((22 * dmg * (pok1.spatk / pok2.spdf)) / 50) + 2) * random.choice (critChance) * (random .choice (randDamage)) * STABdmg
  70.  
  71.     if move.typ == "Fire" and pok2.type1 == "Water":    # all the type combinations. probably better to use a dictionary or array in the future
  72.         damage *= 0.5
  73.     if move.typ == "Fire" and pok2.type1 == "Grass":
  74.         damage *= 1.8
  75.     if move.typ == "Fire" and pok2.type1 == "Fire":
  76.         damage *= 0.5
  77.     if move.typ == "Grass" and pok2.type1 == "Water":
  78.         damage *= 1.8
  79.     if move.typ == "Grass" and pok2.type1 == "Flying":
  80.         damage *= 0.5
  81.     if move.typ == "Grass" and pok2.type1 == "Grass":
  82.         damage *= 0.5
  83.     if move.typ == "Grass" and pok2.type1 == "Fire":
  84.         damage *= 0.5
  85.     if move.typ == "Water" and pok2.type1 == "Water":
  86.         damage *= 0.5
  87.     if move.typ == "Water" and pok2.type1 == "Grass":
  88.         damage *= 0.5
  89.     if move.typ == "Water" and pok2.type1== "Fire":
  90.         damage *= 1.8
  91.     if move.typ == "Flying" and pok2.type1 == "Grass":
  92.         damage *= 1.8
  93.  
  94.  
  95.     damage = round(damage,0)
  96.     damage = int(damage/100)
  97.    
  98.    
  99.     print(f'{pok1.name} used {move.name}')
  100.     pok2.hp -= damage
  101.     print(f"{pok2.name} takes {damage} damage !")
  102.        
  103.     if pok2.hp <= 0:
  104.         gamestate = 1
  105.         pok2.hp = 0
  106.            
  107.     print(f'{pok2.name} has {pok2.hp} HP left. \n')
  108.        
  109.     return gamestate
  110.  
  111.  
  112. party = []
  113.  
  114. pokedex = [Pok1, Pok2, Pok3]
  115.  
  116. pokemonChoice = int(input(f'Please choose a Pokemon to use: (1) {Pok1.name} (2) {Pok2.name} (3) {Pok3.name}: '))
  117.  
  118. if pokemonChoice == 1:
  119.     party.append (Pok1)
  120.     print (f"You have chosen {Pok1.name}.")
  121.  
  122. elif pokemonChoice == 2:
  123.     party.append (Pok2)
  124.     print(f"You have chosen {Pok2.name}.")
  125.  
  126. elif pokemonChoice == 3:
  127.     party.append (Pok3)
  128.     print (f"You have chosen {Pok3.name}.")
  129.  
  130. else:
  131.     choicelol = random.choice(pokedex)
  132.     party.append(choicelol)
  133.     print (f'Invalid input. Random Pokemon chosen... {choicelol.name}.\n')
  134.  
  135.  
  136. pokemonChoice2 = int(input(f'Please choose a Pokemon to battle against: (1) {Pok1.name} (2) {Pok2.name} (3) {Pok3.name}: '))
  137.  
  138. if pokemonChoice2 == 1:
  139.     party.append(Pok1)
  140.     print (f"You have chosen to battle {Pok1.name}.")
  141.  
  142. elif pokemonChoice2 == 2:
  143.     party.append (Pok2)
  144.     print(f"You have chosen to battle {Pok2.name}.")
  145.  
  146. elif pokemonChoice2 == 3:
  147.     party.append (Pok3)
  148.     print (f"You have chosen to battle {Pok3.name}.")
  149.  
  150. else:
  151.     choicelol = random.choice(pokedex)
  152.     party.append(choicelol)
  153.     print (f'Invalid input. Random Pokemon chosen... {choicelol.name}.\n')
  154.  
  155.  
  156. gamestate = 0
  157. while gamestate == 0:
  158.     if party[0].spd >= party [1].spd:
  159.         print(f"Choose a move: (1) {party[0].move1.name} (2) {party[0].move2.name } (3) {party[0].move3.name} (4) {party[0].move4.name}")
  160.         moveChoice1 = int(input())
  161.         if moveChoice1 == 1:
  162.             if PokAttack(party[0], party[1], party[0].move1) == 1:
  163.                 gamestate = 1
  164.         elif moveChoice1 == 2:
  165.             if PokAttack(party[0], party [1], party[0].move2) == 1:
  166.                 gamestate = 1
  167.         elif moveChoice1 == 3:
  168.             if PokAttack (party[0], party[1], party [0] .move3) == 1:
  169.                 gamestate = 1
  170.         elif moveChoice1 == 4:
  171.             if PokAttack(party[0], party[1], party[0].move4) == 1:
  172.                 gamestate = 1
  173.         if gamestate != 1:
  174.             randMove = random.randint(1,4)
  175.             if randMove == 1:
  176.                 if PokAttack (party[1], party[0], party [1] .move1) == 1:
  177.                     gamestate = 2
  178.             elif randMove == 2:
  179.                 if PokAttack (party[1], party[0], party [1] .move2) == 1:
  180.                     gamestate = 2
  181.             elif randMove == 3:
  182.                 if PokAttack (party[1], party[0], party [1] .move3) == 1:
  183.                     gamestate = 2
  184.             elif randMove == 4:
  185.                 if PokAttack (party[1], party[0], party [1] .move4) == 1:
  186.                     gamestate = 2
  187.     else:
  188.         randMove = random.randint(1,4)
  189.         if randMove == 1:
  190.             if PokAttack (party[1], party[0], party [1] .move1) == 1:
  191.                 gamestate = 2
  192.         elif randMove == 2:
  193.             if PokAttack (party[1], party[0], party [1] .move2) == 1:
  194.                 gamestate = 2
  195.         elif randMove == 3:
  196.             if PokAttack (party[1], party[0], party [1] .move3) == 1:
  197.                 gamestate = 2
  198.         elif randMove == 4:
  199.             if PokAttack (party[1], party[0], party [1] .move4) == 1:
  200.                 gamestate = 2
  201.         if gamestate != 2:
  202.             print(f"Choose a move: (1) {party[0].move1.name} (2) {party[0].move2.name } (3) {party[0].move3.name} (4) {party[0].move4.name}")
  203.             moveChoice2 = int(input())
  204.             if moveChoice2 == 1:
  205.                 if PokAttack(party[0], party[1], party[0].move1) == 1:
  206.                     gamestate = 1
  207.             elif moveChoice2 == 2:
  208.                 if PokAttack(party[0], party [1], party[0].move2) == 1:
  209.                     gamestate = 1
  210.             elif moveChoice2 == 3:
  211.                 if PokAttack (party[0], party[1], party [0] .move3) == 1:
  212.                     gamestate = 1
  213.             elif moveChoice2 == 4:
  214.                 if PokAttack(party[0], party[1], party[0].move4) == 1:
  215.                     gamestate = 1
  216.    
  217. if gamestate == 1:
  218.     print("You win!")
  219. elif gamestate == 2:
  220.     print("You lose...")
  221.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement