# Class notes for Wednesday, March 22, 2006

# PeaceBots spread goodwill throughout the world.  Each one has a
# name and an inventory of flowers.

class PeaceBot:

    def __init__(self, n, f):
        self.name = n
        self.flowers = f

    def speak(self):
        print "I am %s the PeaceBot." % self.name
        print "I have %d flowers." % self.flowers

    def takeFlowers(self, howMany):
        self.flowers = self.flowers + howMany
        print "Groooooovy, thanks!"

    def greet(self, otherBot):
        print "Greetings, %s, I am %s." % (otherBot.name, self.name)

    def offerFlowers(self, howMany, otherBot):
        if otherBot == self:
            print "Stop being so stingy!"
        else:
            self.greet(otherBot)
            print "Here, have %d flowers." % howMany
            self.flowers = self.flowers - howMany
            otherBot.takeFlowers(howMany)

#--------------------------------------------------------------------
# Example

def main():
    fred = PeaceBot("Fred", 10)
    melanie = PeaceBot("Melanie", 20)
    melanie.speak()
    fred.speak()
    melanie.offerFlowers(3, fred)
    melanie.speak()
    fred.speak()

# >>> main()
# I am Melanie the PeaceBot.
# I have 20 flowers.
# I am Fred the PeaceBot.
# I have 10 flowers.
# Greetings, Fred, I am Melanie.
# Here, have 3 flowers.
# Groooooovy, thanks!
# I am Melanie the PeaceBot.
# I have 17 flowers.
# I am Fred the PeaceBot.
# I have 13 flowers.

