From 15983586fcf9c6f4f3309b3e65b7fac6b4c9166e Mon Sep 17 00:00:00 2001 From: luxick Date: Sun, 23 Aug 2015 15:35:54 +0200 Subject: [PATCH] added Kinggotchi, multiple Villages in Kingdom --- config.py | 4 ++-- kinggotchi.py | 25 ++++++++++++++++++++++++- test.py | 19 +++++++++++-------- 3 files changed, 37 insertions(+), 11 deletions(-) diff --git a/config.py b/config.py index a7c7610..995a65d 100644 --- a/config.py +++ b/config.py @@ -1,9 +1,9 @@ #!/usr/bin/python # The lenght of one game cycle in milliseconds -ticklenght = 0.05 +ticklenght = 0.005 # Number of Tamagotchis to be created at the start of the simulation -startnr = 50 +startnr = 100 # The amount of points a Tamagotchi loses per tick decayaspeed = 1 # If the hunger stat falls below this level Tamagotchis can be fed diff --git a/kinggotchi.py b/kinggotchi.py index 695f5eb..dee825a 100644 --- a/kinggotchi.py +++ b/kinggotchi.py @@ -16,5 +16,28 @@ class Kinggotchi: self.myvillages.append(mayor) def show_kingdom(self): - result = 'I am Kinggotchi '+str(self.name)+'.\nThese are the '+str(len(self.myvillages))+' Villages in my Kingdom:\n' + result = 'I am Kinggotchi '+str(self.name)+'.\nIn my Kingdom live '+str(self.all_tamagotchis())+' Tamagotichs.\nIn my Kingdom '+str(self.all_dead())+' Tamagotchis have died so far.\n\nThese are the '+str(len(self.myvillages))+' Villages in my Kingdom:\n' + + for n in self.myvillages: + result += '-------------------------------------------------------------------------------\n' + result += n.give_overview() + + return result + + def step(self): + for n in self.myvillages: + n.step() + + def all_tamagotchis(self): + result = 0 + for n in self.myvillages: + result += len(n.mygotchis) + return result + + def all_dead(self): + result = 0 + for n in self.myvillages: + result += n.graveyard + return result + \ No newline at end of file diff --git a/test.py b/test.py index 6315322..8be4937 100644 --- a/test.py +++ b/test.py @@ -1,20 +1,24 @@ #!/usr/bin/python from mayorgotchi import Mayorgotchi +from kinggotchi import Kinggotchi from util import Util from config import * import time import curses # Temporary test section - -list = [] ticks = 0 -for n in range(0,startnr): - list.append(Util().make_Tamagotchi()) -mayor = Mayorgotchi(list) +def make_list(number): + list = [] + for n in range(0,number): + list.append(Util().make_Tamagotchi()) + return list +king = Kinggotchi() +for n in range(0, 10): + king.add_village(Mayorgotchi(make_list(startnr))) screen = curses.initscr() curses.noecho() @@ -24,11 +28,10 @@ screen.nodelay(1) while True: screen.move(0,0) - mayor.step() screen.addstr('Simulation running. Press [q] to exit.\n') screen.addstr('----------------------After '+str(ticks)+' ticks------------------------------\n') - #screen.addstr(mayor.give_status(show_pct)) - screen.addstr(mayor.give_overview()) + screen.addstr(king.show_kingdom()) + king.step() ticks += 1 screen.clrtobot()