finalizing the sleeping function

This commit is contained in:
Nebucatnetzer 2015-07-14 12:39:47 +02:00
parent a41cf688c9
commit 8d7d5223f6
6 changed files with 53 additions and 11 deletions

View File

@ -57,3 +57,5 @@ too easy.
## 12.07.2015
Added the function to poke the pet and it will speak.
If you poke to many times it will get angry.
I added as well a function which will let the pet sleep.
However atm it doesn't work as intended.

View File

@ -15,9 +15,9 @@ from pygame import mixer
# variables needed for the guessing game
secret = randint(1, 10)
### Functions providing the basic function of the programm
### Functions providing the basic function of the programme ###
# a function which displays the pet's stats in a nice way.'
# a function which displays the pet's stats in a nice way.
def pet_stats():
os.system('clear')
print(pet_variables.pet_name)
@ -55,30 +55,50 @@ def beginning():
# A function which changes the status of the pet depending of the age value.
# Each status has it's own characteristics.
def set_youngling_stats():
pet_variables.max_health = 10
pet_variables.max_happiness = 8
pet_variables.max_hunger = 7
def set_adult_stats():
pet_variables.max_health = 10
pet_variables.max_happiness = 8
pet_variables.max_hunger = 7
def set_elderly_stats():
pet_variables.max_health = 7
pet_variables.max_happiness = 5
pet_variables.max_hunger = 10
def reset_stats():
pet_variables.pet_health = pet_variables.max_health
pet_variables.pet_happiness = pet_variables.max_happiness
pet_variables.pet_hunger = pet_variables.max_hunger
def aging():
if pet_variables.pet_age == 5:
pet_variables.pet_status = "adult"
pet_variables.max_health = 10
pet_variables.max_happiness = 8
pet_variables.max_hunger = 7
set_adult_stats()
print("Congratulation your pet has become an adult. It needs less food now")
print("and it's health has improved however it's grumpier than a youngling.")
elif pet_variables.pet_age == 15:
pet_variables.pet_status = "elderly"
pet_variables.max_health = 7
pet_variables.max_happiness = 5
pet_variables.max_hunger = 10
set_elderly_stats()
print("Congratulation your pet has become an elderly it needs now less food.")
print("However it's health is worse and it's grumpier than an adult.")
### Functions to increase and decrease stats ###
def increase_hunger():
pet_variables.pet_hunger = pet_variables.pet_hunger + 1
def increase_poke_count():
pet_variables.poke_count = pet_variables.poke_count + 1
def increase_happiness():
if pet_variables.pet_happiness < pet_variables.max_happiness:
pet_variables.pet_happiness = pet_variables.pet_happiness + 1
@ -103,14 +123,16 @@ def decrease_health():
if pet_variables.pet_health > 0:
pet_variables.pet_health = pet_variables.pet_health - 1
def decrease_poke_count():
pet_variables.poke_count = pet_variables.poke_count - 1
# The function to decrease the stats and make the pet "live" needs to
# run in the background.
def decrease_stats():
while True:
time.sleep(15)
time.sleep(pet_variables.day)
decrease_hunger()
decrease_poke_count()
if pet_variables.pet_hunger <= 0:
@ -129,6 +151,7 @@ def stroking():
print("It makes comforting noises and leans against your hand.")
time.sleep(1)
# Increases the pets hungriness by +1 unless the hunger is bigger than
# the pet's maximum hunger. In this case the pet will vomit and looses hunger
# and health.
@ -157,13 +180,14 @@ def playing():
increase_happiness()
print("Game over!")
# let's you poke the pet and it will talk
# if you poke it more than 3 times it will get angry at you
def poking():
os.system('clear')
if pet_variables.poke_count < 4:
print("You poke " + pet_variables.pet_name + " and it starts to speak.")
pet_variables.increase_poke_count()
increase_poke_count()
mixer.init()
mixer.music.load('happy.mp3')
mixer.music.play()
@ -175,3 +199,16 @@ def poking():
mixer.music.load('angry.mp3')
mixer.music.play()
time.sleep(3)
# A function which let's the pet sleep and regenerates it's stats
def sleeping():
os.system('clear')
print("Your pet is sleeping now.")
time.sleep(10)
if pet_variables.max_hunger / pet_variables.pet_hunger > 0.5:
reset_stats()
print("Your pet woke up feeling rested and in a good mood.")
else:
print("Your pet has woken up.")
time.sleep(3)

View File

@ -22,3 +22,4 @@ owl = "(^0M0^)"
# programme variables
beginning_finished = False
poke_count = 0
day = 15

View File

@ -31,7 +31,7 @@ while pet_functions.is_alive():
print("What would you like to do?")
# Start the chosen activity and go back to the activity selector.
print("1: Feeding, 2: Playing, 3: Stroke Pet,")
print("4: Poking, 5: Show Stats,")
print("4: Poking, 5: Sleeping, 6: Show Stats")
try:
chosen_activity = int(input("Choose the desired activity:"))
if chosen_activity == 1:
@ -43,6 +43,8 @@ while pet_functions.is_alive():
elif chosen_activity == 4:
pet_functions.poking()
elif chosen_activity == 5:
pet_functions.sleeping()
elif chosen_activity == 6:
pet_functions.pet_stats()
except ValueError:
pet_functions.pet_stats()