#!/usr/bin/env python3 # -*- coding: utf-8 -*- """ Felix Muzny 11/18/2022 DS 2000 Lecture 20 - classes and objects, part 2 Write a program, pokemon.py, that defines a Pokemon class then instantiates two Pokemon and has them battle each other. """ import random class Pokemon: def __init__(self, health): """ Create a new Pokemon Parameters ---------- health : int Starting life for this Pokemon. Returns ------- None. """ # set the class attribute of health # to the value of the parameter health self.health = health self.power = 5 def is_conscious(self): """ Returns whether or not this Pokemon is still conscious Returns ------- bool True if the health of this Pokemon is over 0 """ # bool - True if conscious # False otherwise return self.health > 0 def attack(self, other_pokemon): """ Have this pokemon attack another one, reducing its health! Parameters ---------- other_pokemon : Pokemon the pokemon being attacked Returns ------- None. """ # the other pokemon's health should be # reduced other_pokemon.health -= self.power + random.randint(-2, 2) def main(): print("Pokemon battle") poliwrath = Pokemon(30) print("Poliwrath:", poliwrath.health) print(poliwrath.is_conscious()) bulbasaur = Pokemon(10) print("Bulbasaur:", bulbasaur.health) print(bulbasaur.is_conscious()) while poliwrath.is_conscious() and bulbasaur.is_conscious(): poliwrath.attack(bulbasaur) bulbasaur.attack(poliwrath) print("Poliwrath:", poliwrath.health) print("Bulbasaur:", bulbasaur.health) print() print("Poliwrath consciousness:", poliwrath.is_conscious()) print("Bulbasaur consciousness:", bulbasaur.is_conscious()) if __name__ == "__main__": main()