import random, math

class Insetto:
    def __init__(self, pX = 0, pY = 0, energ=100):
        self.posX = pX
        self.posY = pY
        self.energia = energ

    def muoviUnPasso(self):
        if self.energia <= 0:
            return
        direzione = ["sinistra", "destra", "sopra", "sotto"]
        movimento = random.choice(direzione)
        if movimento == "sinistra":
            self.posX -= 1
        elif movimento == "destra":
            self.posX += 1
        elif movimento == "sopra":
            self.posY += 1
        elif movimento == "sotto":
            self.posY -= 1
        self.energia -= 5

    def get_posizione(self):
        return [self.posX, self.posY]

    def get_energia(self):
        return self.energia

    def mangia(self, cibo = 10):
        self.energia += cibo
        if self.energia > 300:
            self.energia = 0


    def in_vita(self):
        return self.energia > 0


class Scarabeo(Insetto):
    def __init__(self, pX = 0, pY = 0, en=100):
        Insetto.__init__(self, pX, pY, en)

    def vola(self):
        self.posX = random.randrange(-4, 5)
        self.posY = random.randrange(-4, 5)
        self.energia -= 10

class Carabo(Insetto):
    def __init__(self, pX = 0, pY = 0, en = 100):
        Insetto.__init__(self, pX, pY, en)

    def muoviUnPasso(self):
        Insetto.muoviUnPasso(self)
        self.energia -= 5


ugo = Scarabeo()
while ugo.in_vita():
    posiz = ugo.get_posizione()
    print "mi trovo in: " + str(posiz) + " ho un'energia di: " \
                         + str(ugo.get_energia())
    tipoMov = random.randrange(8)
    if tipoMov >= 6:
        print "volo!"
        ugo.vola()
    else:
        print "cammino"
        ugo.muoviUnPasso()

    if posiz[0] >= 2 or posiz[1] >= 3:
        ugo.mangia()







