Skip to content
Snippets Groups Projects
Commit 552843cb authored by Tim Huppertz's avatar Tim Huppertz
Browse files

Added buttons and logic.

parent 9eda474d
No related branches found
No related tags found
No related merge requests found
......@@ -16,6 +16,9 @@ class Koala():
self.exhaustion = 10
self.brushed = datetime.now()
self.brushtime = "22:15"
self.dirtiness = 0
self.loneliness = 0
self.weight = 10
def get_mood(self):
if datetime.now() > datetime.strptime(datetime.now().strftime("%d.%m.%Y") + " " + self.brushtime, "%d.%m.%Y %H:%M") and self.brushed < datetime.strptime(datetime.now().strftime("%d.%m.%Y") + " " + self.brushtime, "%d.%m.%Y %H:%M"):
......@@ -23,19 +26,36 @@ class Koala():
if self.hunger < 0:
return "fat"
elif self.hunger >= 10:
return "hungry"
if self.happiness >= 70:
return "happy"
elif self.happiness >= 50:
return "neutral"
else:
return "unhappy"
if self.dirtiness >= 10:
return "dirty"
if self.lonly >= 10:
return "lonly"
if self.weight >= 40:
return "fat"
if self.exhaustion >= 20:
return "tired"
def update(self):
self.happiness -= 1
self.hunger += 1
self.dirtiness += 0.5
self.loneliness += 0.5
self.exhaustion += 0.5
f = open(os.path.expanduser(os.path.join("~", ".deskoala", "koala.dat")), "wb")
pickle.dump(self, f)
......@@ -43,6 +63,8 @@ class Koala():
def feed(self):
self.hunger -= 2
self.dirtiness += 0.5
self.weight += 1
def turn(self):
self.happiness += 3
......@@ -54,7 +76,37 @@ class Koala():
self.hunger += 2
self.happiness += 1
self.exhaustion += 2
self.dirtiness += 0.5
self.weight -= 1
def soap(self):
self.dirtiness -= 5
def medicine(self):
self.happiness += 5
self.hunger -= 1
self.loneliness -= 5
def bonbon(self):
self.weight += 2
self.happiness += 5
self.hunger -= 1
self.dirtiness += 0.5
def hug(self):
self.happiness += 2
self.loneliness -= 2
def walk(self):
self.happiness += 5
self.loneliness -= 5
self.hunger += 5
self.weight -= 5
def sleep(self):
self.exhaustion -= 20
self.dirtiness += 1
class Deskoala(plasmascript.Applet):
def __init__(self,parent,args=None):
plasmascript.Applet.__init__(self,parent)
......@@ -76,7 +128,7 @@ class Deskoala(plasmascript.Applet):
self.show_mood()
self.buttons = QGraphicsLinearLayout(Qt.Vertical, self.layout)
for b in [("feed", self.feed), ("turn", self.turn), ("excercise", self.excercise), ("brush", self.brush)]:
for b in [("feed", self.feed), ("turn", self.turn), ("excercise", self.excercise), ("brush", self.brush), ("soap", self.soap), ("medicine", self.medicine), ("bonbon", self.bonbon), ("hug", self.hug), ("walk", self.walk), ("sleep", self.sleep)]:
button = Plasma.PushButton(self.applet)
button.setImage(self.package().filePath('images', 'button_' + b[0] + '.gif'))
self.connect(button, SIGNAL("clicked()"), b[1])
......@@ -123,5 +175,29 @@ class Deskoala(plasmascript.Applet):
self.koala.brush()
self.show_mood()
def soap(self):
self.koala.soap()
self.show_mood()
def medicine(self):
self.koala.medicine()
self.show_mood()
def bonbon(self):
self.koala.bonbon()
self.show_mood()
def hug(self):
self.koala.hug()
self.show_mood()
def walk(self):
self.koala.walk()
self.show_mood()
def sleep(self):
self.koala.sleep()
self.show_mood()
def CreateApplet(parent):
return Deskoala(parent)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment