Advertisement
katmai

programming is not a language

Feb 26th, 2024
674
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.62 KB | Source Code | 0 0
  1. import random
  2. from classes.game import Person, bcolors
  3. from classes.magic import Spell
  4.  
  5. # Another thing that came to my mind, as i am doing this, is that whatever you're doing here, is you creating your
  6. # own adversaries. The whole idea of "playing vs. the computer" is simply non-existent.
  7. # The computer doesn't "understand" the game. It doesn't know what "fire" or a "spell" is.
  8. # Those are just characters placed in memory blocks. The only one it has any meaning for, it's you.
  9. # You define the obstacles and their actions. It's a maze where you're doing whatever in order to get yourself lost.
  10.  
  11. # Magic Spells
  12. # Damaging
  13. # def __init__(self, name, cost, dmg, type):
  14. fire = Spell("Fire", 10, 100, "damaging")
  15. thunder = Spell("Thunder", 12, 124, "damaging")
  16. lightning = Spell("Lightning", 12, 100, "damaging")
  17. meteor = Spell("Meteor", 20, 200, "damaging")
  18. quake = Spell("Quake", 14, 120, "damaging")
  19. # Healing
  20. cure = Spell("Cure", 12, 120, "healing")
  21. cura = Spell("Cura", 18, 200, "healing")
  22.  
  23. # wanted to name defense as 'def' but apparently Python recognizes it as 'def' from define function even within the brackets and it messes things up.
  24. # so i had to use 'df' instead. stupid :))
  25. # def __init__(self, hp, mp, atk, df, magic):
  26. player = Person(460, 65, 60, 34, [fire, thunder, lightning, meteor, cure, cura])
  27. enemy = Person(1200, 65, 45, 25, [fire, thunder, lightning, meteor, cure, cura])
  28.  
  29. running = True
  30. i = 0
  31.  
  32. # No reason to label the beginning of the game with RED or FAIL. It's just the beginning.
  33. # It's neither good nor bad.
  34. # Also the beginning doesn't start with you being attacked, but with you choosing an action.
  35. # The response only happens afterwards.
  36. # As far as enemy goes, you don't have a real one. You're making one up, so you have someone to fight with.
  37. print(bcolors.GREEN + bcolors.BOLD + "Someone has started the game" + bcolors.ENDC)
  38.  
  39. while running:
  40.     print("==============================")
  41.     player.choose_action()
  42.     choice = input(bcolors.CYAN + bcolors.BOLD + "Choose your own action: " + bcolors.ENDC)
  43.     index = int(choice)
  44.     # i think it's important to always remember which action generated the result, to see "why" that is happening.
  45.     print(bcolors.CYAN + bcolors.BOLD + "You chose to use: " + player.get_action_name(index) + bcolors.ENDC)
  46.  
  47.     if index == 0:
  48.         dmg = player.generate_damage()
  49.         enemy.take_damage(dmg)
  50.         print("You attacked for", dmg, "Points of damage.")
  51.     elif index == 1:
  52.         print("==============================")
  53.         player.choose_spell()
  54.         choice = input(bcolors.CYAN + bcolors.BOLD + "Choose spell: " + bcolors.ENDC)
  55.         index = int(choice)
  56.         # i think it's important to always remember which action generated the result, to see "why" that is happening.
  57.         print(bcolors.CYAN + bcolors.BOLD + "You chose to use a: " + player.spells[index].name + bcolors.ENDC)
  58.  
  59.         dmg = player.spells[index].generate_damage()
  60.         spell = player.spells[index]
  61.         current_mp = player.get_mp()
  62.  
  63.         if spell.cost > current_mp:
  64.             print(bcolors.RED + "\nNot enough MP\n" + bcolors.ENDC)
  65.             # continue forces to use the next iteration of the loop aka start over at 'if index == 0:...'
  66.             # but i think the idea is that the code below doesn't run unless i've made a choice.
  67.             # continue, as a word, means - moving on, going forward, not stopping. And yet, yere, in Python,
  68.             # it carries a different meaning. It means "Stop the execution of the current loop, whatever instructions"
  69.             # and go to the top of the loop and run the next iteration.
  70.             # it just means a completely different thing.
  71.             # does this mean that with enough iterations,
  72.             # a word meaning would end up being derived from the surrounding context?
  73.             # but then, how does each of the words have any meaning at all?
  74.             continue
  75.  
  76.         player.reduce_mp(spell.cost)
  77.  
  78.         if spell.type == "healing":
  79.             player.heal_damage(dmg)
  80.             print(bcolors.BLUE + "\n" + spell.name + " heals for ", str(dmg), "HP." + bcolors.ENDC)
  81.         elif spell.type == "damaging":
  82.             enemy.take_damage(dmg)
  83.             print(bcolors.CYAN + "\n" + spell.name + " deals ", str(dmg), "points of damage" + bcolors.ENDC)
  84.     elif index == 7:
  85.         exit()
  86.  
  87.     # enemy choice is set to always attack but what if we also gave a choice to the enemy,
  88.     # just as we do have a choice as well ?
  89.     # enemy_choice = random.randrange(0,6)
  90.     # enemy.choose_action(enemy_choice)
  91.     # print(enemy_choice)
  92.     # this time we go with the flow. enemy always attacks regardless
  93.     # but again, to be cheeky, if there's no enemy, there's no choice, because there's no understanding.
  94.     # there is no enemy choice
  95.     enemy_choice = 1
  96.  
  97.     dmg = enemy.generate_damage()
  98.     player.take_damage(dmg)
  99.     print("Enemy attacked for", dmg, "Points of damage.")
  100.  
  101.     print("-------------------------------------")
  102.     print("Enemy HP:", bcolors.CYAN + str(enemy.get_hp()) + "/" + str(enemy.get_max_hp()) + bcolors.ENDC)
  103.     print("Your HP:", bcolors.CYAN + str(player.get_hp()) + "/" + str(player.get_max_hp()) + bcolors.ENDC)
  104.     print("Your MP:", bcolors.BLUE + str(player.get_mp()) + "/" + str(player.get_max_mp()) + bcolors.ENDC)
  105.  
  106.     # The game being over doesn't really mean anything bad or good, so as to color it with
  107.     if enemy.get_hp() == 0:
  108.         print(bcolors.RED + "The game is over" + bcolors.ENDC)
  109.         running = False
  110.     elif player.get_hp() == 0:
  111.         print(bcolors.RED + "The game is over" + bcolors.ENDC)
  112.         running = False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement