Compare commits

2 Commits

Author SHA1 Message Date
luxick
f67cb0d9d0 Replaced Constant names 2016-03-01 16:43:30 +01:00
luxick
07af201350 Introduced Eggs.
Every tamagotchi will spawn an egg, all the time(DEBUG)
2016-02-26 19:04:12 +01:00
7 changed files with 73 additions and 29 deletions

6
cli.py
View File

@@ -20,7 +20,7 @@ class cursesUI:
self.villagenr = 0 self.villagenr = 0
self.percentage = True self.percentage = True
self.running = True self.running = True
self.paused = start_paused self.paused = START_PAUSED
self.stdscr = curses.initscr() self.stdscr = curses.initscr()
curses.noecho() curses.noecho()
@@ -31,7 +31,7 @@ class cursesUI:
height, width = self.stdscr.getmaxyx() height, width = self.stdscr.getmaxyx()
self.win = curses.newpad(16383, width) self.win = curses.newpad(16383, width)
self.king.createKingdom(startNrVillages) self.king.createKingdom(STARTNR_VILLAGES)
while self.running: while self.running:
self.build_screen(self.king, self.ticks) self.build_screen(self.king, self.ticks)
@@ -79,7 +79,7 @@ class cursesUI:
if not self.kingdomview: if not self.kingdomview:
self.percentage = not self.percentage self.percentage = not self.percentage
elif key < 0: elif key < 0:
time.sleep(ticklenght) time.sleep(TICKLENGHT)
if not self.running: if not self.running:
curses.endwin() curses.endwin()

View File

@@ -2,17 +2,17 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Define if simulation should be started paused or running # Define if simulation should be started paused or running
start_paused = True START_PAUSED = True
# The lenght of one game cycle in milliseconds # The lenght of one game cycle in milliseconds
ticklenght = 0.001 TICKLENGHT = 0.001
# Controls if Tamagotchi stats are shown in absolute vlaues or precentage (Possible values: True/False) # Controls if Tamagotchi stats are shown in absolute vlaues or precentage (Possible values: True/False)
show_pct = True SHOW_PTC = True
# Number of Tamagotchis to be created at the start of the simulation # Number of Tamagotchis to be created at the start of the simulation
startnr = 60 STARTNR = 60
startNrVillages = 50 STARTNR_VILLAGES = 50
# If the value of a Tamagotchis stats drops below this he will be fed/washed/etc # If the value of a Tamagotchis stats drops below this he will be fed/washed/etc
# Synatx [Hunger, Hygiene, Happiness] # Synatx [Hunger, Hygiene, Happiness]
interventionPoints = [50, 50, 50] INTERVENTION_POINTS = [50, 50, 50]
# If the hunger stat falls below this level Tamagotchis can be fed # If the hunger stat falls below this level Tamagotchis can be fed
feeding_point = 50 feeding_point = 50
# If the hygiene stat falls below this level Tamagotchis can be washed # If the hygiene stat falls below this level Tamagotchis can be washed
@@ -20,15 +20,15 @@ washing_point = 50
# If the happiness stat falls below this level Tamagotchis can be played with # If the happiness stat falls below this level Tamagotchis can be played with
play_point = 50 play_point = 50
# When new Tamagotchis are created their stats will be be created randomly between these. # When new Tamagotchis are created their stats will be be created randomly between these.
statrange = [100, 200] STATRANGE = [100, 200]
# Tamagotchis decay at a set rate per tick. The value of decay is randomly chosen between these two. # Tamagotchis decay at a set rate per tick. The value of decay is randomly chosen between these two.
decay = [1, 3] DECAY = [1, 3]
# These two define how long it takes a Tamagotchi to perform work (preparing food/washing someone/playing with someone) # These two define how long it takes a Tamagotchi to perform work (preparing food/washing someone/playing with someone)
# The value is choosen randomly between these two. Obviously a lower number is better. # The value is choosen randomly between these two. Obviously a lower number is better.
workpower = [3, 6] WORKPOWER = [3, 6]
# This defines the bounds of how much a Tamagotchi can recover when eating/sleeping/playing etc. # This defines the bounds of how much a Tamagotchi can recover when eating/sleeping/playing etc.
recovery = [10, 20] RECOVERY = [10, 20]
# Defines the range in witch the lifetime of Tamagotichs will be created in ticks # Defines the range in witch the lifetime of Tamagotichs will be created in ticks
life = [2000, 3000] LIFE = [2000, 3000]

21
egg.py Normal file
View File

@@ -0,0 +1,21 @@
#!/usr/bin/python
# -*- coding: utf-8 -*-
class Egg:
alive = True
age = 0
care = 100
def __init__(self):
self.alive = True
self.age = 0
self.care = 100
def step(self):
if self.alive:
if self.care >= 0:
age += 1
else:
self.alive = False

View File

@@ -42,5 +42,5 @@ class Kinggotchi:
def createKingdom(self, startvillages): def createKingdom(self, startvillages):
for _ in itertools.repeat(None, startvillages): for _ in itertools.repeat(None, startvillages):
self.add_village(Mayorgotchi(Util().make_list_of_Tamagotchis(startnr))) self.add_village(Mayorgotchi(Util().make_list_of_Tamagotchis(STARTNR)))

View File

@@ -5,9 +5,11 @@ from tamagotchi import Tamagotchi
import random import random
from config import * from config import *
from util import Util from util import Util
from egg import Egg
class Mayorgotchi: class Mayorgotchi:
mygotchis = [] mygotchis = []
myeggs = []
name = '' name = ''
graveyard = 0 graveyard = 0
@@ -21,10 +23,13 @@ class Mayorgotchi:
self.graveyard += 1 self.graveyard += 1
self.mygotchis.remove(n) self.mygotchis.remove(n)
def give_status(self,show_pct): def give_status(self,SHOW_PTC):
result = 'I am Mayorgotchi ' + self.name + '.\nIn my Village live '+str(len(self.mygotchis))+' Tamagotchis.\nIn my Village '+str(self.graveyard)+' Tamagotchis died so far.\n\n' result = "Town: " + self.name + "\n"
result += "Population: " + str(len(self.mygotchis)) + " "
result += "Graveyard: " + str(self.graveyard) + " "
result += "Eggs: " + str(len(self.myeggs)) + "\n\n"
for n in self.mygotchis: for n in self.mygotchis:
if show_pct: if SHOW_PTC:
result += n.status_pct() result += n.status_pct()
else: else:
result += n.status_abs() result += n.status_abs()
@@ -120,8 +125,22 @@ class Mayorgotchi:
for n in self.mygotchis: for n in self.mygotchis:
n.step() n.step()
self.remove_corpses() self.remove_corpses()
self.checkCildBirth()
self.order_feed() self.order_feed()
self.order_wash() self.order_wash()
self.order_play() self.order_play()
def addToVillage(self, new):
if isinstance(new, Egg):
self.myeggs.append(new)
elif isinstance(new, Tamagotchi):
self.mygotchis.append(new)
def checkCildBirth(self):
for n in self.mygotchis:
if n.fertility[0] == True:
self.addToVillage(Egg())

View File

@@ -14,6 +14,7 @@ class Tamagotchi:
power = 0 power = 0
recovery = 0 recovery = 0
lifetime = 0 lifetime = 0
fertility = [True, 0]
def __init__(self, name, hunger, happiness, hygiene, sleep, decayspeed, potential, recovery, lifetime): def __init__(self, name, hunger, happiness, hygiene, sleep, decayspeed, potential, recovery, lifetime):
self.name = name self.name = name
@@ -130,3 +131,6 @@ class Tamagotchi:
rtn += 'Sleep: {0:5}'.format(sleep_pct) rtn += 'Sleep: {0:5}'.format(sleep_pct)
rtn += '\n' rtn += '\n'
return rtn return rtn
def checkFertility(self):
return True

20
util.py
View File

@@ -7,19 +7,19 @@ from config import *
import os import os
class Util: class Util:
def make_Tamagotchi(self): def make_Tamagotchi(self):
name = self.generateName() name = self.generateName()
hunger = random.randrange(statrange[0],statrange[1],1) hunger = random.randrange(STATRANGE[0],STATRANGE[1],1)
happiness = random.randrange(statrange[0],statrange[1],1) happiness = random.randrange(STATRANGE[0],STATRANGE[1],1)
hygiene = random.randrange(statrange[0],statrange[1],1) hygiene = random.randrange(STATRANGE[0],STATRANGE[1],1)
sleep = random.randrange(statrange[0],statrange[1],1) sleep = random.randrange(STATRANGE[0],STATRANGE[1],1)
decayspeed = random.randrange(decay[0],decay[1],1) decayspeed = random.randrange(DECAY[0],DECAY[1],1)
potential = random.randrange(workpower[0], workpower[1],1) potential = random.randrange(WORKPOWER[0], WORKPOWER[1],1)
recoveryspeed = random.randrange(recovery[0], recovery[1], 1) recoveryspeed = random.randrange(RECOVERY[0], RECOVERY[1], 1)
lifetime = random.randrange(life[0], life[1], 1) lifetime = random.randrange(LIFE[0], LIFE[1], 1)
return Tamagotchi(name,hunger,happiness,hygiene,sleep,decayspeed,potential,recoveryspeed,lifetime) return Tamagotchi(name, hunger, happiness, hygiene, sleep, decayspeed,
potential, recoveryspeed, lifetime)
def make_list_of_Tamagotchis(self, number): def make_list_of_Tamagotchis(self, number):
tmp = [] tmp = []