Advertisement
gruntfutuk

Cat Dog fight

Jun 17th, 2019
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. from random import choice
  2.  
  3. class Pet():
  4.     def __init__(self, name, bite, energy):
  5.         self.name = name
  6.         self.bite = bite
  7.         self.energy = energy
  8.     def alive(self):
  9.          return self.energy > 0
  10.     def report(self):
  11.          print(f"({0 if self.energy < 0 else self.energy})")
  12.          if self.energy <= 0:
  13.              print(f"{self.name} dead!")
  14.  
  15. class Cat(Pet):
  16.     def bites(self, other):
  17.         other.bitten(self)
  18.         print("meow")
  19.     def bitten(self, other):
  20.         self.energy -= other.bite
  21.         print("screech ", end='')
  22.         Pet.report(self)
  23.  
  24. class Dog(Pet):
  25.     def bites(self, other):
  26.         other.bitten(self)
  27.         print("woof")
  28.     def bitten(self, other):
  29.         self.energy -= other.bite
  30.         print("yowl ", end='')
  31.         Pet.report(self)
  32.        
  33. cat = Cat("puss", 5, 80)
  34. dog = Dog("rex", 8, 50)
  35.  
  36. while cat.alive() and dog.alive():
  37.     pet = choice(((dog, cat), (cat, dog)))
  38.     pet[0].bites(pet[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement