Compare commits
2 Commits
master
...
reproducti
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f67cb0d9d0 | ||
|
|
07af201350 |
6
cli.py
6
cli.py
@@ -20,7 +20,7 @@ class cursesUI:
|
||||
self.villagenr = 0
|
||||
self.percentage = True
|
||||
self.running = True
|
||||
self.paused = start_paused
|
||||
self.paused = START_PAUSED
|
||||
|
||||
self.stdscr = curses.initscr()
|
||||
curses.noecho()
|
||||
@@ -31,7 +31,7 @@ class cursesUI:
|
||||
height, width = self.stdscr.getmaxyx()
|
||||
self.win = curses.newpad(16383, width)
|
||||
|
||||
self.king.createKingdom(startNrVillages)
|
||||
self.king.createKingdom(STARTNR_VILLAGES)
|
||||
|
||||
while self.running:
|
||||
self.build_screen(self.king, self.ticks)
|
||||
@@ -79,7 +79,7 @@ class cursesUI:
|
||||
if not self.kingdomview:
|
||||
self.percentage = not self.percentage
|
||||
elif key < 0:
|
||||
time.sleep(ticklenght)
|
||||
time.sleep(TICKLENGHT)
|
||||
if not self.running:
|
||||
curses.endwin()
|
||||
|
||||
|
||||
22
config.py
22
config.py
@@ -2,17 +2,17 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Define if simulation should be started paused or running
|
||||
start_paused = True
|
||||
START_PAUSED = True
|
||||
# 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)
|
||||
show_pct = True
|
||||
SHOW_PTC = True
|
||||
# Number of Tamagotchis to be created at the start of the simulation
|
||||
startnr = 60
|
||||
startNrVillages = 50
|
||||
STARTNR = 60
|
||||
STARTNR_VILLAGES = 50
|
||||
# If the value of a Tamagotchis stats drops below this he will be fed/washed/etc
|
||||
# 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
|
||||
feeding_point = 50
|
||||
# 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
|
||||
play_point = 50
|
||||
# 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.
|
||||
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)
|
||||
# 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.
|
||||
recovery = [10, 20]
|
||||
RECOVERY = [10, 20]
|
||||
# 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
21
egg.py
Normal 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
|
||||
|
||||
|
||||
@@ -42,5 +42,5 @@ class Kinggotchi:
|
||||
|
||||
def createKingdom(self, 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)))
|
||||
|
||||
|
||||
@@ -5,9 +5,11 @@ from tamagotchi import Tamagotchi
|
||||
import random
|
||||
from config import *
|
||||
from util import Util
|
||||
from egg import Egg
|
||||
|
||||
class Mayorgotchi:
|
||||
mygotchis = []
|
||||
myeggs = []
|
||||
name = ''
|
||||
graveyard = 0
|
||||
|
||||
@@ -21,10 +23,13 @@ class Mayorgotchi:
|
||||
self.graveyard += 1
|
||||
self.mygotchis.remove(n)
|
||||
|
||||
def give_status(self,show_pct):
|
||||
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'
|
||||
def give_status(self,SHOW_PTC):
|
||||
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:
|
||||
if show_pct:
|
||||
if SHOW_PTC:
|
||||
result += n.status_pct()
|
||||
else:
|
||||
result += n.status_abs()
|
||||
@@ -120,8 +125,22 @@ class Mayorgotchi:
|
||||
for n in self.mygotchis:
|
||||
n.step()
|
||||
self.remove_corpses()
|
||||
|
||||
self.checkCildBirth()
|
||||
|
||||
self.order_feed()
|
||||
self.order_wash()
|
||||
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())
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -14,6 +14,7 @@ class Tamagotchi:
|
||||
power = 0
|
||||
recovery = 0
|
||||
lifetime = 0
|
||||
fertility = [True, 0]
|
||||
|
||||
def __init__(self, name, hunger, happiness, hygiene, sleep, decayspeed, potential, recovery, lifetime):
|
||||
self.name = name
|
||||
@@ -130,3 +131,6 @@ class Tamagotchi:
|
||||
rtn += 'Sleep: {0:5}'.format(sleep_pct)
|
||||
rtn += '\n'
|
||||
return rtn
|
||||
|
||||
def checkFertility(self):
|
||||
return True
|
||||
|
||||
20
util.py
20
util.py
@@ -7,19 +7,19 @@ from config import *
|
||||
import os
|
||||
|
||||
class Util:
|
||||
|
||||
def make_Tamagotchi(self):
|
||||
name = self.generateName()
|
||||
hunger = random.randrange(statrange[0],statrange[1],1)
|
||||
happiness = random.randrange(statrange[0],statrange[1],1)
|
||||
hygiene = random.randrange(statrange[0],statrange[1],1)
|
||||
sleep = random.randrange(statrange[0],statrange[1],1)
|
||||
decayspeed = random.randrange(decay[0],decay[1],1)
|
||||
potential = random.randrange(workpower[0], workpower[1],1)
|
||||
recoveryspeed = random.randrange(recovery[0], recovery[1], 1)
|
||||
lifetime = random.randrange(life[0], life[1], 1)
|
||||
hunger = random.randrange(STATRANGE[0],STATRANGE[1],1)
|
||||
happiness = random.randrange(STATRANGE[0],STATRANGE[1],1)
|
||||
hygiene = random.randrange(STATRANGE[0],STATRANGE[1],1)
|
||||
sleep = random.randrange(STATRANGE[0],STATRANGE[1],1)
|
||||
decayspeed = random.randrange(DECAY[0],DECAY[1],1)
|
||||
potential = random.randrange(WORKPOWER[0], WORKPOWER[1],1)
|
||||
recoveryspeed = random.randrange(RECOVERY[0], RECOVERY[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):
|
||||
tmp = []
|
||||
|
||||
Reference in New Issue
Block a user