Nitin-L

AttributeError: 'list' object has no attribute 'g_s'

Mar 30th, 2020
202
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 4.60 KB | None | 0 0
  1. from Classes.Game import Person, Bcolor
  2. from Classes.Magic import Spell
  3. from Classes.inventory import Item
  4.  
  5. print("\n")
  6. print("NAME                                HP                                      MP")
  7.  
  8. # Black Magic
  9. Fire = Spell("Fire", 10, 50, "b")
  10. Thunder = Spell("Thunder", 20, 100, "b")
  11. Blizzard = Spell("Blizzard", 30, 150, "b")
  12. Earthquake = Spell("Earthquake", 40, 200, "b")
  13. Water = Spell("Water", 50, 250, "black")
  14.  
  15. # White Magic
  16. Cure = Spell("Cure", 40, 90, "w")
  17. MAXcure = Spell("MAXcure", 80, 120, "w")
  18.  
  19. # Create some items
  20. potion = Item("Potion", "potion", "Heals 50 HP", 50)
  21. hipotion = Item("HI-Potion", "potion", "Heals 100 HP", 100)
  22. superpotion = Item("SUPER-Potion", "potion", "Heals 200 HP", 200)
  23. elixr = Item("Elixr", "elixr", "Complete restoration of HP/MP for 1 player member", 9999)
  24. megaelixr = Item("MEGA-Elixr", "elixr", "Complete restoration of HP/MP", 9999)
  25.  
  26. grenade = Item("Grenade", "attack", " Deals 500 damage", 500)
  27.  
  28. p_s =  [Fire, Blizzard, Thunder, Cure, MAXcure]
  29. p_i = [{"item":potion, "quantity":15},
  30.        {"item":hipotion, "quantity":5},
  31.        {"item":superpotion, "quantity":5},
  32.        {"item":elixr, "quantity":2},
  33.        {"item":megaelixr, "quantity":1},
  34.        {"item":grenade, "quantity":3}]
  35.  
  36. # Instantiate People
  37. Player1 = Person("Nitin", 860, 180, 60 , 34, p_s, p_i)
  38. Player2 = Person("Putti", 1060, 380, 80 , 44, p_s, p_i)
  39. Player3 = Person("Budda", 560, 280, 130 , 94, p_s, p_i)
  40. Player = [Player1, Player2, Player3]
  41.  
  42. Enemy = Person("Thima", 1200, 65, 45, 25, [], [])
  43.  
  44. run = True
  45. i = 0
  46.  
  47. print(Bcolor.FAIL + Bcolor.BOLD + "An Enemy attacks!" + Bcolor.ENDC)
  48.  
  49. while run:
  50.     print("-------")
  51.     for player in Player:
  52.         Player.g_s()
  53.  
  54.     for player in Player:
  55.         Player.choose_actions()
  56.         choice = input("Choose action : ")
  57.         index = int(choice) - 1
  58.  
  59.         if index ==0:
  60.             dm = Player.gen_dm()
  61.             Enemy.take_dm(dm)
  62.             print("You attacked for ", dm, "points of damage.")
  63.  
  64.         elif index == 1:
  65.             print(Bcolor.OKBLUE + "Magic" + Bcolor.ENDC)
  66.             i = 1
  67.             for Spell in Player.magic:
  68.                 print("     ", str(i) + ":", Spell.name, " cost : ", Spell.cost)
  69.                 i += 1
  70.  
  71.             magic_choice = int(input("Choose magic: ")) - 1    # Line 18 and 19 code style merged in a single line
  72.  
  73.             if magic_choice == -1:        # To switch back to the previous menu page
  74.                 continue
  75.  
  76.             Spell = Player.magic[magic_choice]
  77.             magic_dm = Spell.gen_dm()
  78.  
  79.             current_mp = Player.get_mp()
  80.  
  81.             if Spell.cost > current_mp:
  82.                 print(Bcolor.FAIL + "\nNot enough MP\n" + Bcolor.ENDC)
  83.                 continue
  84.  
  85.             Player.reduce_mp(Spell.cost)
  86.  
  87.             if Spell.type == "w":
  88.                 Player.heal(magic_dm)
  89.                 print(Bcolor.OKBLUE + Spell.name + " heals for", str(magic_dm), " HP" + Bcolor.ENDC)
  90.             elif Spell.type == "b":
  91.                 Enemy.take_dm(magic_dm)
  92.                 print(Bcolor.OKBLUE + Spell.name + " deals", str(magic_dm), " points of damage" + Bcolor.ENDC)
  93.  
  94.         elif index == 2:
  95.             Player.item_choice()
  96.             i_c = int(input("Choose item: ")) - 1
  97.  
  98.             if i_c == -1:
  99.                 continue        # To switch back to the previous menu page
  100.  
  101.             item = Player.items[i_c]["item"]
  102.  
  103.             if Player.items[i_c]["quantity"] == 0:
  104.                 print(Bcolor.FAIL + "Not enough items" + Bcolor.ENDC)
  105.                 continue
  106.  
  107.             Player.items[i_c]["quantity"] -= 1
  108.  
  109.             if item.type == "potion":
  110.                 Player.heal(item.prop)
  111.                 print(Bcolor.OKBLUE + item.name + " heals for", str(item.prop), " HP" + Bcolor.ENDC)
  112.  
  113.             elif item.type == "elixr":
  114.                 Player.hp = Player.maxhp
  115.                 Player.mp = Player.maxmp
  116.                 print(Bcolor.OKGREEN + item.name + " restores full HP/MP" + Bcolor.ENDC)
  117.  
  118.             elif item.type == "attack":
  119.                 Enemy.take_dm(item.prop)
  120.                 print(Bcolor.FAIL + item.name + " deals", str(item.prop), "points of damage" + Bcolor.ENDC)
  121.  
  122.     Enemy_choice = 1
  123.  
  124.     Enemy_dm = Enemy.gen_dm()
  125.     Player.take_dm(Enemy_dm)
  126.     print("Enemy attacks for ", Enemy_dm)
  127.  
  128.     print("------")
  129.     print("Enemy HP: ", Bcolor.FAIL + str(Enemy.get_hp()) + Bcolor.ENDC)
  130.  
  131.     if Enemy.get_hp() == 0:
  132.         print(Bcolor.OKGREEN + "You win!!" + Bcolor.ENDC)
  133.         run = False
  134.     elif Player.get_hp() == 0:
  135.         print(Bcolor.FAIL + "You are defeated!!" + Bcolor.ENDC)
  136.         run = False
Add Comment
Please, Sign In to add comment