diff --git a/mayorgotchi.py b/mayorgotchi.py index 1aa160c..7a407c2 100644 --- a/mayorgotchi.py +++ b/mayorgotchi.py @@ -7,6 +7,7 @@ import random class Mayorgotchi: mygotchis = [] name = '' + graveyard = 0 def __init__(self, list_of_tamagotchis): self.mygotchis = list_of_tamagotchis @@ -15,10 +16,11 @@ class Mayorgotchi: def remove_corpses(self): for n in self.mygotchis: if n.is_dead(): + self.graveyard += 1 self.mygotchis.remove(n) def give_status(self,show_pct): - result = 'I am Mayorgotchi ' + self.name + '. These are the Tamagotchis in my Village:\n\n' + result = 'I am Mayorgotchi ' + self.name + '.\nIn my Village '+str(self.graveyard)+' Tamagotchis died so far.\nThese are the Tamagotchis living in my Village:\n\n' for n in self.mygotchis: if show_pct: result += n.status_pct() @@ -52,6 +54,17 @@ class Mayorgotchi: else: return None + def get_unhappy(self): + unhappies = [] + result = [] + for n in self.mygotchis: + if n.happiness[0] <= 20: + unhappies.append(n) + if len(unhappies) > 0: + return unhappies[random.randrange(0,len(unhappies), 1)] + else: + return None + def order_feed(self): hungry = self.get_hungry() if hungry is not None: @@ -62,6 +75,11 @@ class Mayorgotchi: if dirty is not None: self.get_free().wash_other(dirty) + def order_play(self): + unhappy = self.get_unhappy() + if unhappy is not None: + self.get_free().play_with(unhappy) + def step(self): for n in self.mygotchis: @@ -69,3 +87,4 @@ class Mayorgotchi: self.remove_corpses() self.order_feed() self.order_wash() + self.order_play() diff --git a/mayorgotchi.pyc b/mayorgotchi.pyc index 68ec52b..6582139 100644 Binary files a/mayorgotchi.pyc and b/mayorgotchi.pyc differ diff --git a/tamagotchi.py b/tamagotchi.py index 55150bd..d9c1447 100644 --- a/tamagotchi.py +++ b/tamagotchi.py @@ -26,16 +26,13 @@ class Tamagotchi: self.potential = potential self.power = potential - def set_status(self, status): - self.status = status - def feed_other(self, tamagotchi): self.status = 'Working' tamagotchi.status = 'Eating' def play_with(self, tamagotchi): - tamagotchi.happiness += 5 - self.happiness += 5 + self.status = 'Working' + tamagotchi.status = 'Playing' def wash_other(self,tamagotchi): self.status = 'Working' @@ -55,10 +52,10 @@ class Tamagotchi: def update_hunger(self): if self.status is 'Eating': if self.hunger[0] <= self.hunger[1]: - self.hunger[0] += 10 + self.hunger[0] += 30 else: self.status = 'Idle' - elif self.status is 'Idle': + else: # The Tamagotchi is starving if self.hunger[0] < self.decayspeed: self.hunger[0] = 0 @@ -76,8 +73,24 @@ class Tamagotchi: else: self.hygiene[0] += self.recovery else: - self.hygiene[0] -= self.decayspeed + if self.hygiene[0] <= 0: + self.hygiene[0] = 0 + else: + self.hygiene[0] -= self.decayspeed + def update_happiness(self): + if self.status is 'Playing': + if self.happiness[0] >= self.happiness[1]: + self.status = 'Idle' + if self.happiness[0] >= self.happiness[1] -self.recovery: + self.happiness[0] = self.happiness[1] + else: + self.happiness[0] += self.recovery + else: + if self.happiness[0] <= 0: + self.happiness[0] = 0 + else: + self.happiness[0] -= self.decayspeed def step(self): if not self.dead: @@ -88,14 +101,10 @@ class Tamagotchi: else: self.power -= 1 else: - if self.happiness[0] < self.decayspeed: - self.happiness[0] = 0 - else: - self.happiness[0] -= self.decayspeed - self.update_hunger() self.update_sleep() self.update_hygiene() + self.update_happiness() def is_dead(self): if self.dead: diff --git a/tamagotchi.pyc b/tamagotchi.pyc index 430b61e..fa8318c 100644 Binary files a/tamagotchi.pyc and b/tamagotchi.pyc differ