class Critter:
def __init__(self):
self.m_Hunger = 0
def Greet(self):
print "Hi. I'm a critter. My hunger level is " , self.m_Hunger
crit1 = Critter()
crit2 = Critter()
crit1.m_Hunger = 9;
print "crit1's hunger level is " , crit1.m_Hunger
crit2.m_Hunger = 3;
print "crit2's hunger level is " , crit2.m_Hunger
crit1.Greet()
crit2.Greet()
class Critter:
def __init__(self,h=0):
print "A new critter has been born!"
self.m_Hunger = h
def Greet(self):
print "Hi. I'm a critter. My hunger level is " , self.m_Hunger
crit = Critter(7);
crit.Greet();
class Critter:
def __init__(self,h=0):
print "A new critter has been born!"
self.m_Hunger = h
def Greet(self):
print "Hi. I'm a critter. My hunger level is " , self.m_Hunger
def GetHunger(self):
return self.m_Hunger;
def SetHunger(self,hunger):
if (hunger < 0):
print "You can't set a critter's hunger to a negative number.";
else:
self.m_Hunger = hunger;
crit = Critter(5)
#print crit.m_Hunger; //illegal, m_Hunger is private!
print "Calling GetHunger(): " , crit.GetHunger()
print "Calling SetHunger() with -1.";
crit.SetHunger(-1);
print "Calling SetHunger() with 9.";
crit.SetHunger(9);
print "Calling GetHunger(): " , crit.GetHunger()
class Critter:
s_Total = 0
def __init__(self,h=0):
print "A new critter has been born!"
self.m_Hunger = h
Critter.s_Total += 1
def GetTotal(self):
return Critter.s_Total;
print "The total number of critters is: ";
print Critter.s_Total
crit1 = Critter()
crit2 = Critter()
crit3 = Critter()
print "\nThe total number of critters is: ",
print Critter.GetTotal(crit1)
class Critter:
def __init__(self,hunger = 0, boredom = 0):
self.m_Hunger= hunger
self.m_Boredom = boredom
def GetMood(self):
return (self.m_Hunger + self.m_Boredom);
def PassTime(self,time):
self.m_Hunger += time;
self.m_Boredom += time;
def Talk(self):
print "I'm a critter and I feel ";
mood = self.GetMood();
if (mood > 15):
print "mad.\n";
elif (mood > 10):
print "frustrated.\n";
elif (mood > 5):
print "okay.\n";
else:
print "happy.\n";
self.PassTime(0);
def Eat(self,food):
print "Brruppp.\n";
self.m_Hunger -= food;
if (self.m_Hunger < 0):
self.m_Hunger = 0;
self.PassTime(0);
def Play(self,fun):
print "Wheee!\n";
self.m_Boredom -= fun;
if (self.m_Boredom < 0):
self.m_Boredom = 0;
self.PassTime(0);
crit = Critter()
crit.Talk();
while True:
print "\nCritter Caretaker\n\n";
print "0 - Quit\n";
print "1 - Listen to your critter\n";
print "2 - Feed your critter\n";
print "3 - Play with your critter\n\n";
print "Choice: ";
choice = int(raw_input())
if choice == 0:
print "Good-bye.\n";
break
elif choice == 1:
crit.Talk();
elif choice == 2:
crit.Eat(0);
elif choice == 3:
crit.Play(0);
else:
print "\nSorry, but " , choice , " isn't a valid choice.\n";
class Critter:
def __init__(self,hunger = 0, boredom = 0):
self.m_Hunger= hunger
self.m_Boredom = boredom
def Talk(self):
print "I'm a critter and I feel ";
mood = self.GetMood();
if (mood > 15):
print "mad.\n";
elif (mood > 10):
print "frustrated.\n";
elif (mood > 5):
print "okay.\n";
else:
print "happy.\n";
self.PassTime();
def Eat(self,food = 4):
print "Brruppp.";
self.m_Hunger -= food;
if (self.m_Hunger < 0):
self.m_Hunger = 0;
self.PassTime();
def Play(self,fun = 4):
print "Wheee!";
self.m_Boredom -= fun;
if (self.m_Boredom < 0):
self.m_Boredom = 0;
self.PassTime();
def PassTime(self, time = 1):
self.m_Hunger += time;
self.m_Boredom += time;
def GetMood(self):
return (self.m_Hunger + self.m_Boredom);
crit = Critter()
crit.Talk();
choice = 1;
choices = [1,2,3,0]
i = 0
while choice != 0 :
print "\nCritter Caretaker\n";
print "0 - Quit";
print "1 - Listen to your critter";
print "2 - Feed your critter";
print "3 - Play with your critter\n";
print "Choice: ",
choice = choices[i] #int(raw_input())
i += 1
if choice ==0:
print "Good-bye.\n";
elif choice==1:
crit.Talk();
elif choice == 2:
crit.Eat();
elif choice == 3:
crit.Play();
else:
print "\nSorry, but " , choice , " isn't a valid choice.";