# -*- coding: iso-8859-15 -*-
# --------------------------------------------------------------
# 13.03.2018 ow / items.py / python
#
import random
import uselib, publib
class cItem:
def __init__(self, type, name=None):
if name is None or name == '':
name = publib.RandomString(5)
self.name = name
self.type = type
# return a string for object
def __str__(self):
result = " {:10} {:10}".format(self.GetType(), self.GetName())
return(result)
def GetName(self):
return(self.name)
def GetType(self):
return(self.type)
class cAnimal(cItem):
def __init__(self, type, name, maxfood):
super().__init__(type, name)
self.maxfood = maxfood
self.foodinbelly = 0.0
# return a string for object
def __str__(self):
result = super().__str__() + '{:>5.0f}'.format(self.maxfood)
return(result)
def Feed(self, amount):
part = 0
part = self.maxfood - self.foodinbelly
if part > amount:
part = amount
self.foodinbelly += part
self.Stomach()
return(part)
def Stomach(self):
self.foodinbelly *= random.randint(85,95)/100
class cDairyAnimal(cAnimal):
def __init__(self, type, name, maxfood, maxmilk):
super().__init__(type, name, maxfood)
self.maxmilk = maxmilk
self.milk = 0.0
def Stomach(self):
self.milk = self.maxmilk*self.foodinbelly/self.maxfood
super().Stomach()
def GiveMilk(self):
milk = self.milk
self.milk = 0.0
return(milk)