SHARE
TWEET

Untitled

a guest Oct 12th, 2017 51 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. import random
  2. import time
  3.  
  4. class Character():
  5.  
  6.     def __init__(self, character_name):
  7.         self.name = character_name
  8.         self.health = random.randint(18,22)
  9.         self.armor_class = random.randint(14, 20)
  10.         self.strength = random.randint(8, 24)
  11.         self.dexterity = random.randint(8, 24)
  12.         self.constitution = random.randint(8, 24)
  13.         self.intelligence = random.randint(8, 24)
  14.         self.wisdom = random.randint(8, 24)
  15.         self.charisma = random.randint(8, 24)
  16.         print("Name:", self.name, "Health:", self.health, "Armor Class:", self.armor_class, "Strength:", self.strength, "dexterity:", self.dexterity, "constitution:", self.constitution, \
  17.               "intelligence:", self.intelligence, "wisdom:", self.wisdom, "charisma:", self.charisma)
  18.  
  19. def modifier_check(ability_score):
  20.     if ability_score < 2:
  21.         return -5
  22.     elif ability_score < 4:
  23.         return -4
  24.     elif ability_score < 6:
  25.         return -3
  26.     elif ability_score < 8:
  27.         return -2
  28.     elif ability_score < 10:
  29.         return -1
  30.     elif ability_score < 12:
  31.         return 0
  32.     elif ability_score < 14:
  33.         return 1
  34.     elif ability_score < 16:
  35.         return 2
  36.     elif ability_score < 18:
  37.         return 3
  38.     elif ability_score < 20:
  39.         return 4
  40.     elif ability_score < 22:
  41.         return 5
  42.     elif ability_score < 24:
  43.         return 6
  44.     elif ability_score < 26:
  45.         return 7
  46.     else:
  47.         return 8
  48.  
  49. def roll_d20():
  50.     roll = random.randint(1,20)
  51.     print("Die came up", roll)
  52.     return roll
  53.  
  54. def roll_d6():
  55.     return random.randint(1,6)
  56.  
  57. def Attack(attacker, defender):
  58.     attacker_strength = attacker.strength
  59.     defender_defense = defender.armor_class
  60.     attack_roll = roll_d20() + modifier_check(attacker_strength)
  61.     if attack_roll >= defender.armor_class:
  62.         print("Hit! Rolled a", attack_roll, "vs. defender's", defender.armor_class)
  63.         damage = roll_d6()
  64.         defender.health -= damage
  65.         print ("Dealt", damage, "damage! defender health:", defender.health)
  66.     else:
  67.         print("Missed! Rolled a", attack_roll, "vs. defender's", defender.armor_class)
  68.  
  69. def Fight(user, enemy):
  70.     character_taking_turn = user
  71.     character_defending = enemy
  72.     while user.health and enemy.health > 0:
  73.         print("It's", character_taking_turn.name + "'s", "turn!")
  74.         Attack(character_taking_turn, character_defending)
  75.         new_defender = character_taking_turn
  76.         character_taking_turn = character_defending
  77.         character_defending = new_defender
  78.         time.sleep(2)
  79.     if user.health <= 0:
  80.         print(user.name, "died! Fight over!")
  81.     elif enemy.health <= 0:
  82.         print(enemy.name, "died! Fight over!")
  83.  
  84.  
  85.  
  86.  
  87. new_player = Character("Spencer")
  88. orc = Character("Orc")
  89.  
  90. Fight(new_player, orc)
RAW Paste Data
Top