initial commit
This commit is contained in:
@@ -0,0 +1,60 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
from tamagotchi import Tamagotchi
|
||||||
|
from util import Util
|
||||||
|
import names
|
||||||
|
|
||||||
|
decayaspeed = 1
|
||||||
|
ticks = 50
|
||||||
|
show_pct = True
|
||||||
|
|
||||||
|
class Mayorgotchi:
|
||||||
|
mygotchis = []
|
||||||
|
name = ''
|
||||||
|
|
||||||
|
def __init__(self, list_of_tamagotchis):
|
||||||
|
self.mygotchis = list_of_tamagotchis
|
||||||
|
self.name = names.get_last_name()
|
||||||
|
|
||||||
|
def remove_corpses(self):
|
||||||
|
for n in self.mygotchis:
|
||||||
|
if n.is_dead():
|
||||||
|
self.mygotchis.remove(n)
|
||||||
|
|
||||||
|
def give_status(self):
|
||||||
|
result = 'I am Mayorgotchi ' + self.name + '. These are the Tamagotchis in my Village:\n\n'
|
||||||
|
for n in self.mygotchis:
|
||||||
|
if show_pct:
|
||||||
|
result += n.status_pct()
|
||||||
|
else:
|
||||||
|
result += n.status_abs()
|
||||||
|
return result
|
||||||
|
|
||||||
|
def step(self):
|
||||||
|
for n in self.mygotchis:
|
||||||
|
n.step()
|
||||||
|
self.remove_corpses()
|
||||||
|
|
||||||
|
|
||||||
|
# Temoprarty Test Section
|
||||||
|
list = []
|
||||||
|
for n in range(0,10):
|
||||||
|
list.append(Util().make_Tamagotchi())
|
||||||
|
|
||||||
|
mayor = Mayorgotchi(list)
|
||||||
|
|
||||||
|
print mayor.give_status()
|
||||||
|
|
||||||
|
for n in range (0, ticks):
|
||||||
|
mayor.step()
|
||||||
|
|
||||||
|
print '----------------------After '+str(ticks)+' ticks------------------------------\n'
|
||||||
|
|
||||||
|
print mayor.give_status()
|
||||||
|
|
||||||
|
for n in range (0, ticks):
|
||||||
|
mayor.step()
|
||||||
|
|
||||||
|
print '----------------------After another '+str(ticks)+' ticks------------------------------\n'
|
||||||
|
|
||||||
|
print mayor.give_status()
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
from __future__ import unicode_literals
|
||||||
|
from os.path import abspath, join, dirname
|
||||||
|
import random
|
||||||
|
|
||||||
|
|
||||||
|
__title__ = 'names'
|
||||||
|
__version__ = '0.3.0.post1'
|
||||||
|
__author__ = 'Trey Hunner'
|
||||||
|
__license__ = 'MIT'
|
||||||
|
|
||||||
|
|
||||||
|
full_path = lambda filename: abspath(join(dirname(__file__), filename))
|
||||||
|
|
||||||
|
|
||||||
|
FILES = {
|
||||||
|
'first:male': full_path('dist.male.first'),
|
||||||
|
'first:female': full_path('dist.female.first'),
|
||||||
|
'last': full_path('dist.all.last'),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def get_name(filename):
|
||||||
|
selected = random.random() * 90
|
||||||
|
with open(filename) as name_file:
|
||||||
|
for line in name_file:
|
||||||
|
name, _, cummulative, _ = line.split()
|
||||||
|
if float(cummulative) > selected:
|
||||||
|
return name
|
||||||
|
return "" # Return empty string if file is empty
|
||||||
|
|
||||||
|
|
||||||
|
def get_first_name(gender=None):
|
||||||
|
if gender is None:
|
||||||
|
gender = random.choice(('male', 'female'))
|
||||||
|
if gender not in ('male', 'female'):
|
||||||
|
raise ValueError("Only 'male' and 'female' are supported as gender")
|
||||||
|
return get_name(FILES['first:%s' % gender]).capitalize()
|
||||||
|
|
||||||
|
|
||||||
|
def get_last_name():
|
||||||
|
return get_name(FILES['last']).capitalize()
|
||||||
|
|
||||||
|
|
||||||
|
def get_full_name(gender=None):
|
||||||
|
return "{0} {1}".format(get_first_name(gender), get_last_name())
|
||||||
Binary file not shown.
+88799
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,10 @@
|
|||||||
|
from __future__ import print_function
|
||||||
|
from names import get_full_name
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
print(get_full_name())
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,87 @@
|
|||||||
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
class Tamagotchi:
|
||||||
|
status = ''
|
||||||
|
name = ''
|
||||||
|
hunger = 0
|
||||||
|
happiness = 0
|
||||||
|
hygiene = 0
|
||||||
|
sleep = 0
|
||||||
|
dead = False
|
||||||
|
decayspeed = 0
|
||||||
|
|
||||||
|
def __init__(self, name, hunger, happiness, hygiene, sleep, decayspeed):
|
||||||
|
self.name = name
|
||||||
|
self.hunger = [hunger, hunger]
|
||||||
|
self.happiness = [happiness, happiness]
|
||||||
|
self.hygiene = [hygiene, hygiene]
|
||||||
|
self.sleep = [sleep, sleep]
|
||||||
|
self.dead = False
|
||||||
|
self.status = 'Idle'
|
||||||
|
self.decayspeed = decayspeed
|
||||||
|
|
||||||
|
def feed_other(self, tamagotchi):
|
||||||
|
tamagotchi.hunger += 5
|
||||||
|
|
||||||
|
def play_with(self, tamagotchi):
|
||||||
|
tamagotchi.happiness += 5
|
||||||
|
self.happiness += 5
|
||||||
|
|
||||||
|
def wash_other(self,tamagotchi):
|
||||||
|
tamagotchi.hygiene += 5
|
||||||
|
|
||||||
|
def sleep(self):
|
||||||
|
self.sleep += 5
|
||||||
|
|
||||||
|
def decay(self, amount):
|
||||||
|
if not self.dead:
|
||||||
|
if self.hunger[0] < amount:
|
||||||
|
self.hunger[0] = 0
|
||||||
|
self.dead = True
|
||||||
|
self.status = 'Dead'
|
||||||
|
else:
|
||||||
|
self.hunger[0] -= amount
|
||||||
|
|
||||||
|
if self.happiness[0] < amount:
|
||||||
|
self.happiness[0] = 0
|
||||||
|
else:
|
||||||
|
self.happiness[0] -= amount
|
||||||
|
|
||||||
|
if self.hygiene[0] < amount:
|
||||||
|
self.hygiene[0] = 0
|
||||||
|
else:
|
||||||
|
self.hygiene[0] -= amount
|
||||||
|
|
||||||
|
if self.sleep[0] <= 0:
|
||||||
|
self.status = "Sleeping"
|
||||||
|
|
||||||
|
if self.status is 'Sleeping':
|
||||||
|
if self.sleep[0] <= self.sleep[1] - amount:
|
||||||
|
self.sleep[0] += 5
|
||||||
|
if self.sleep[0] >= self.sleep[1]:
|
||||||
|
self.status = 'Idle'
|
||||||
|
else:
|
||||||
|
self.sleep[0] -= amount
|
||||||
|
|
||||||
|
def step(self):
|
||||||
|
self.decay(self.decayspeed)
|
||||||
|
|
||||||
|
def is_dead(self):
|
||||||
|
if self.dead:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def percentage(self, part, whole):
|
||||||
|
return 100 * float(part)/float(whole)
|
||||||
|
|
||||||
|
def status_abs(self):
|
||||||
|
return '{0:15} {1:10} Hunger:{2:10} Happiness:{3:10} Hygiene:{4:10} Sleep:{5:10}\n'.format(self.name,self.status,str(self.hunger[0])+'/'+str(self.hunger[1]),str(self.happiness[0])+'/'+str(self.happiness[1]),str(self.hygiene[0])+'/'+str(self.hygiene[1]),str(self.sleep[0])+'/'+str(self.sleep[1]))
|
||||||
|
|
||||||
|
def status_pct(self):
|
||||||
|
hunger_pct = '%.0f%%' %(self.percentage(self.hunger[0], self.hunger[1]))
|
||||||
|
happiness_pct = '%.0f%%' %self.percentage(self.happiness[0], self.happiness[1])
|
||||||
|
hygiene_pct = '%.0f%%' %self.percentage(self.hygiene[0], self.hygiene[1])
|
||||||
|
sleep_pct = '%.0f%%' %self.percentage(self.sleep[0], self.sleep[1])
|
||||||
|
|
||||||
|
return '{0:20} {1:10} Hunger:{2:5} Happiness:{3:5} Hygiene:{4:5} Sleep:{5:5}\n'.format(self.name,self.status,hunger_pct,happiness_pct,hygiene_pct,sleep_pct)
|
||||||
Binary file not shown.
@@ -0,0 +1,17 @@
|
|||||||
|
#! /usr/bin/python
|
||||||
|
|
||||||
|
from tamagotchi import Tamagotchi
|
||||||
|
import random
|
||||||
|
import names
|
||||||
|
|
||||||
|
class Util:
|
||||||
|
|
||||||
|
def make_Tamagotchi(self):
|
||||||
|
name = names.get_last_name()
|
||||||
|
hunger = random.randrange(80,120,1)
|
||||||
|
happiness = random.randrange(80,120,1)
|
||||||
|
hygiene = random.randrange(80,120,1)
|
||||||
|
sleep = random.randrange(80,120,1)
|
||||||
|
decayspeed = random.randrange(1,3,1)
|
||||||
|
|
||||||
|
return Tamagotchi(name,hunger,happiness,hygiene,sleep,decayspeed)
|
||||||
Reference in New Issue
Block a user