# Critter Caretaker # A virtual pet to care for # Michael Dawson - 3/28/03 import os import sys if os.name == "nt": CMD = "cls" else: CMD = "clear" os.system(CMD) class Critter(object): """A virtual pet""" def __init__(self, name, hunger = 0, boredom = 0): self.name = name self.hunger = hunger self.boredom = boredom def __pass_time(self): self.hunger += 1 self.boredom += 1 def __get_mood(self): unhappiness = self.hunger + self.boredom if unhappiness < 5: mood = "happy" elif 5 <= unhappiness <= 10: mood = "okay" elif 11 <= unhappiness <= 15: mood = "frustrated" elif 16 <= unhappiness <= 25: mood = "mad" else: mood = "dieing" return mood mood = property(__get_mood) def view(self): POS = [ """ _____________ / \\ / \\ / (.) (.) \\ / \\ \\ v / \\ _______ / \\ \_____/ / \\_____________/ """, """ _____________ / \\ / \\ / (.) (.) \\ / \\ \\ v / \\ / \\ \\_____/ / \\_____________/ """, """ _____________ / \\ / \\ / (.) (.) \\ / \\ \\ v / \\ ___ / \\ / \\_____________/ """, """ _____________ / \\ / \\ / (.) (.) \\ / \\ \\ v / \\ _______ / \\ / \\ / \\_____________/ """, """ _____________ / \\ / \\ / |X| |X| \\ / \\ \\ v / \\ _______ / \\ / \\ / \\_____________/ """, """ _____________ / \\ / _ _ \\ / |X| |X| \\ / \\ \\ v / \\ _____ / \\ |__| / \\_____________/ """ ] unhappiness = self.hunger + self.boredom if unhappiness < 5: face = POS[0] elif 5 <= unhappiness <= 10: face = POS[1] elif 11 <= unhappiness <= 15: face = POS[2] elif 16 <= unhappiness <= 25: face = POS[3] elif 26 <= unhappiness <= 29: face = POS[4] else: face = POS[5] return face def talk(self): print "I'm", self.name, "and I feel", self.mood, "now.\n\n" print self.view() self.__pass_time() raw_input("\n\nPress the enter key to continue.") def eat(self, food = 4): print "Brruppp. Thank you." self.hunger -= food if self.hunger < 0: self.hunger = 0 self.__pass_time() raw_input("\n\nPress the enter key to continue.") def play(self, fun = 4): print "Wheee!" self.boredom -= fun if self.boredom < 0: self.boredom = 0 self.__pass_time() raw_input("\n\nPress the enter key to continue.") def dead(self): print "Oh, youre critter is dead!!!!!!" print self.view() def main(): crit_name = raw_input("What do you want to name your critter?: ") crit = Critter(crit_name) choice = None while choice != "0": os.system(CMD) if (crit.hunger + crit.boredom) >= 30: crit.dead() del crit break print \ """ Critter Caretaker 0 - Quit 1 - Listen to your critter 2 - Feed your critter 3 - Play with your critter """ choice = raw_input("Choice: ") print # exit if choice == "0": print "Good-bye." # listen to your critter elif choice == "1": crit.talk() # feed your critter elif choice == "2": crit.eat() # play with your critter elif choice == "3": crit.play() # some unknown choice else: print "\nSorry, but", choice, "isn't a valid choice." main() raw_input("\n\nPress the enter key to exit.")