uccjshrimpton

Year 12 Object Oriented Programming Introduction

Jul 14th, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.03 KB | None | 0 0
  1. from random import randint
  2.  
  3. class player:
  4.     def __init__(self,name):
  5.         self.name = name
  6.         self.health = 100
  7.         self.mana = randint(100,200)
  8.         self.defense = randint(10,15)
  9.         self.attack = randint(20,25)
  10.         self.xp = 0
  11.         self.level = 1
  12.  
  13.     def print_stats(self):
  14.         print("-----------")
  15.         print("Adventurer name:",self.name)
  16.         print("Health:",self.health)
  17.         print("Mana:",self.mana)
  18.         print("Defense:",self.defense)
  19.         print("Attack:",self.attack)
  20.         print("-----------")
  21.  
  22.     def eat_food(self,food):
  23.         if food == "apple":
  24.             print("You are allergic to apples and you die.")
  25.             self.health = 0
  26.             self.print_stats()
  27.             print("Yo ded.")
  28.         else:
  29.             print("You are healed for 5, well done.")
  30.             self.health += 5
  31.             self.print_stats()
  32.             print("Great job!")
  33.    
  34.    
  35. player1 = player(input("Enter name\n-->"))
  36. player2 = player(input("Enter name\n-->"))
Add Comment
Please, Sign In to add comment