Advertisement
Guest User

Adventure V.1

a guest
Oct 22nd, 2019
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.57 KB | None | 0 0
  1. import time
  2. import random
  3. import sys
  4.  
  5. def dprint(text, speed=0.05):
  6.   for char in text:
  7.     sys.stdout.write(char)
  8.     sys.stdout.flush()
  9.     time.sleep(speed)
  10.   print('')
  11.  
  12. # Eneme Class
  13. class enemy:
  14.  
  15.   def __init__(self):
  16.     self.name = random.choice(['Rob', 'Bob', 'Rick', 'Nick', 'Joe'])
  17.     self.hp = random.randint(50, 100)
  18.     self.mp = random.randint(1,5)
  19.     self.atk1 = ['Punch', 10]
  20.     self.atk2 = ['Kick', 15]
  21.  
  22.   def attack(self, player):
  23.     print('\n')
  24.     print('--{} -- HP: {} --'.format(self.name, self.hp))
  25.     print('--{} -- HP: {} --'.format(player.name, player.hp))
  26.     ATTACKS = [self.atk1, self.atk2]
  27.     atk_choice = random.choice(ATTACKS)
  28.     print('{} chose {}!'.format(self.name, atk_choice[0]))
  29.     player.hp -= atk_choice[1]
  30.     self.atk1[1] *= self.mp + 1
  31.     self.atk2[1] *= self.mp + 1
  32.     if player.hp <= 0:
  33.       print('{} has died to {}!'.format(player.name, self.name))
  34.     elif self.hp <= 0:
  35.       print('{} has died to {}!'.format(self.name, player.name))
  36.     else:
  37.       print('--{} -- HP: {} --'.format(self.name, self.hp))
  38.       print('--{} -- HP: {} --'.format(player.name, player.hp))
  39.  
  40.   def heal(self, player):
  41.     heal_yn = random.choice('y', 'n')
  42.     if heal_yn == 'y':
  43.       print('--{} -- HP: {} --'.format(self.name, self.hp))
  44.       print('--{} -- HP: {} --'.format(player.name, player.hp))
  45.       print('\n{} feels bad for attacking you so he\'s giving you HP!'.format(self.name))
  46.       heal_amnt = random.randint(self.hp, 100)
  47.       if heal_amnt >= self.hp:
  48.         heal_amnt = random.randint(self.hp, 100)
  49.       if (player.hp + heal_amnt) >= 100:
  50.         heal_amnt = random.randint(self.hp, 100)
  51.       else:
  52.         self.hp -= heal_amnt
  53.         enemy.hp += heal_amnt
  54.       print('--{} -- HP: {} --'.format(self.name, self.hp))
  55.       print('--{} -- HP: {} --'.format(player.name, player.hp))
  56.     if heal_yn == 'n':
  57.       print('{} doesn\'t want to give away HP!!'.format(self.name))
  58.  
  59.  
  60.  
  61. # Player Class
  62. class player:
  63.  
  64.   def __init__(self, name, atk1, atk2):
  65.     self.name = name
  66.     self.hp = 100
  67.     self.mp = 1
  68.     self.atk1 = atk1
  69.     self.atk2 = atk2
  70.     self.bandages = [10, 10]
  71. #  How many Bandages-^    ^ How much HP it gives you!
  72.  
  73.   def attack(self, enemy):
  74.     try:
  75.       print('--{} -- HP: {} --'.format(self.name, self.hp))
  76.       print('--{} -- HP: {} --'.format(enemy.name, enemy.hp))
  77.       atk_choice = int(input('Which attack do you wish to use?\n1: {}\n2: {}\n'.format(self.atk1[0], self.atk2[0])))
  78.       if atk_choice == 1 or atk_choice == self.atk1[0]:
  79.         print('{} chose {}!'.format(self.name, self.atk1[0]))
  80.         enemy.hp -= self.atk1[1]
  81.       if atk_choice == 2 or atk_choice == self.atk2[0]:
  82.         print('{} chose {}!'.format(self.name, self.atk2[0]))
  83.         enemy.hp -= self.atk2[1]
  84.       if enemy.hp <= 0:
  85.         print('{} has died to {}!'.format(enemy.name, self.name))
  86.       elif self.hp <= 0:
  87.         print('{} has died to {}!'.format(self.name, enemy.name))
  88.       else:
  89.         print('--{} -- HP: {} --'.format(self.name, self.hp))
  90.         print('--{} -- HP: {} --'.format(enemy.name, enemy.hp))
  91.     except Exception:
  92.       return None
  93.  
  94.  
  95.   def heal_self(self):
  96.     self.bandages[0] -= 1
  97.     print('--{} -- HP: {} --'.format(self.name, self.hp))
  98.     print('You have {} bandages left'.format(self.bandages[0]))
  99.     self.hp += self.bandages[1]
  100.     print('--{} -- HP: {} --'.format(self.name, self.hp))
  101.  
  102.  
  103.   def heal(self, enemy):
  104.     print('--{} -- HP: {} --'.format(self.name, self.hp))
  105.     print('--{} -- HP: {} --'.format(enemy.name, enemy.hp))
  106.     try:
  107.       heal_amnt = float(input('How much HP do you want to transfer to {}?'.format(enemy.name)))
  108.       if heal_amnt >= self.hp:
  109.         print('You cannot transfer all your HP!')
  110.       if (enemy.hp + heal_amnt) >= 100:
  111.         print('{} cannot have over 100 HP!!'.format(enemy.name))
  112.       else:
  113.         self.hp -= heal_amnt
  114.         enemy.hp += heal_amnt
  115.       print('--{} -- HP: {} --'.format(self.name, self.hp))
  116.       print('--{} -- HP: {} --'.format(enemy.name, enemy.hp))
  117.     except Exception:
  118.       return None      
  119.  
  120.  
  121. # Starts Up Variables
  122. e1 = enemy()
  123. e2 = enemy()
  124. e3 = enemy()
  125. e4 = enemy()
  126. BOSS = enemy()
  127. BOSS.hp = 200
  128. BOSS.atk1 = (['Fire Breath', 30])
  129.  
  130. player_choices = ('run', 'attack', 'save')
  131.  
  132. def home_page():
  133.   print('##################')
  134.   print('#     1: Play    #')
  135.   print('#     2: Exit    #')
  136.   print('##################')
  137.   try:
  138.     home_selection = int(input('1 or 2\n> '))
  139.     if home_selection == 1:
  140.       start_game()
  141.     elif home_selection == 2:
  142.       sys.exit()
  143.   except Exception as e:
  144.     return None
  145.  
  146. # Basic start of the game
  147. def start_game():
  148.   global p
  149.   #try:
  150.   print('Hello Traveler!!')
  151.  
  152.     # Name
  153.   print('What\'s your name?')
  154.   new_name = input()
  155.   dprint('Hey, {}!'.format(new_name))
  156.  
  157.     # Atk1
  158.   dprint('What\'s your Number one best Attack?')
  159.   atk1_name = input()
  160.   dprint('How much damage does that attack do?')
  161.   atk1_dmg = int(input())
  162.   if atk1_dmg > 20:
  163.     dprint('Your damage Cannot be greater than 20!')
  164.     dprint('Now...')
  165.     dprint('How much damage does that attack do?')
  166.     atk1_dmg = int(input())
  167.   else:
  168.     pass
  169.     # Atk2
  170.   dprint('Ok, now...')
  171.   dprint('What\'s your Second best Attack?')
  172.   atk2_name = input()
  173.   dprint('How much damage does that attack do?')
  174.   atk2_dmg = int(input())
  175.  
  176.   dprint('Sweet!!')
  177.  
  178.     #Starting the player/user class
  179.   p = player(new_name, [atk1_name, atk1_dmg], [atk2_name, atk2_dmg])
  180.  
  181.   dprint('Hope you have fun {}! Just be careful of the Foe\'s you\'ll encouter along the way!!'.format(new_name))
  182.   time.sleep(1)
  183.   dprint('As the man walks away and you turn around and start wandering,\nyou run into an enemy ready to attack you! ')
  184.   starter_lvl()
  185.  
  186.   #except Exception:
  187.     #return None
  188.  
  189.  
  190.  
  191. def starter_lvl():
  192.   global p
  193.   p_option = int(input('Do you wish to 1: Attack or 2: Run?'))
  194.   if p_option == 2:
  195.     print('You don\'t get to play! You didn\'t even want to fight the first enemy!')
  196.     sys.exit()
  197.  
  198.  
  199.   if p_option == 1:
  200.     health = p.hp
  201.     while health > 0:
  202.       p.attack(e1)
  203.       e1.attack(p)
  204.  
  205.       #try:
  206.       heal_yn = input('Do you wish to use a bandage? y or n\n> ').lower().strip()
  207.       if heal_yn == 'y':
  208.         p.heal_self()
  209.       elif heal_yn == 'n':
  210.         try:
  211.           enemie_heal = input('Do you wish to heal the enemie instead?')
  212.         except Exception:
  213.           return None
  214.       #except Exception:
  215.         #return None
  216.  
  217.  
  218.   lvl1()    
  219.  
  220.  
  221. def lvl1():
  222.   pass
  223.  
  224. def lvl2():
  225.   pass
  226.  
  227. def lvl3():
  228.   pass
  229.  
  230. def lvl4():
  231.   pass
  232. start_game()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement