[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Python enumerations



>  class Apple:
>    def onEat(self): print 'Ate an apple.'

I did something similar with an RPG-style Item class. It went something like:

class Item:
  def __init__(self,foo):
    self.taste = "sweet"
    self.calories = 100
  def Use(self,how="eat",who_is_using_me=None):
    person = who_is_using_me
    if how == "eat":
      person.food += self.calories
      person.SenseInput(self.taste)
      self.reference_to_game_world.DeleteItem(self)

>>> peach = Item()
>>> peach.Use("eat",K)