finalizing the sleeping function
This commit is contained in:
parent
a41cf688c9
commit
8d7d5223f6
|
@ -57,3 +57,5 @@ too easy.
|
||||||
## 12.07.2015
|
## 12.07.2015
|
||||||
Added the function to poke the pet and it will speak.
|
Added the function to poke the pet and it will speak.
|
||||||
If you poke to many times it will get angry.
|
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.
|
||||||
|
|
Binary file not shown.
Binary file not shown.
|
@ -15,9 +15,9 @@ from pygame import mixer
|
||||||
# variables needed for the guessing game
|
# variables needed for the guessing game
|
||||||
secret = randint(1, 10)
|
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():
|
def pet_stats():
|
||||||
os.system('clear')
|
os.system('clear')
|
||||||
print(pet_variables.pet_name)
|
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.
|
# A function which changes the status of the pet depending of the age value.
|
||||||
# Each status has it's own characteristics.
|
# 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():
|
def aging():
|
||||||
if pet_variables.pet_age == 5:
|
if pet_variables.pet_age == 5:
|
||||||
pet_variables.pet_status = "adult"
|
pet_variables.pet_status = "adult"
|
||||||
pet_variables.max_health = 10
|
set_adult_stats()
|
||||||
pet_variables.max_happiness = 8
|
|
||||||
pet_variables.max_hunger = 7
|
|
||||||
print("Congratulation your pet has become an adult. It needs less food now")
|
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.")
|
print("and it's health has improved however it's grumpier than a youngling.")
|
||||||
elif pet_variables.pet_age == 15:
|
elif pet_variables.pet_age == 15:
|
||||||
pet_variables.pet_status = "elderly"
|
pet_variables.pet_status = "elderly"
|
||||||
pet_variables.max_health = 7
|
set_elderly_stats()
|
||||||
pet_variables.max_happiness = 5
|
|
||||||
pet_variables.max_hunger = 10
|
|
||||||
print("Congratulation your pet has become an elderly it needs now less food.")
|
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.")
|
print("However it's health is worse and it's grumpier than an adult.")
|
||||||
|
|
||||||
|
|
||||||
### Functions to increase and decrease stats ###
|
### Functions to increase and decrease stats ###
|
||||||
|
|
||||||
def increase_hunger():
|
def increase_hunger():
|
||||||
pet_variables.pet_hunger = pet_variables.pet_hunger + 1
|
pet_variables.pet_hunger = pet_variables.pet_hunger + 1
|
||||||
|
|
||||||
|
|
||||||
def increase_poke_count():
|
def increase_poke_count():
|
||||||
pet_variables.poke_count = pet_variables.poke_count + 1
|
pet_variables.poke_count = pet_variables.poke_count + 1
|
||||||
|
|
||||||
|
|
||||||
def increase_happiness():
|
def increase_happiness():
|
||||||
if pet_variables.pet_happiness < pet_variables.max_happiness:
|
if pet_variables.pet_happiness < pet_variables.max_happiness:
|
||||||
pet_variables.pet_happiness = pet_variables.pet_happiness + 1
|
pet_variables.pet_happiness = pet_variables.pet_happiness + 1
|
||||||
|
@ -103,14 +123,16 @@ def decrease_health():
|
||||||
if pet_variables.pet_health > 0:
|
if pet_variables.pet_health > 0:
|
||||||
pet_variables.pet_health = pet_variables.pet_health - 1
|
pet_variables.pet_health = pet_variables.pet_health - 1
|
||||||
|
|
||||||
|
|
||||||
def decrease_poke_count():
|
def decrease_poke_count():
|
||||||
pet_variables.poke_count = pet_variables.poke_count - 1
|
pet_variables.poke_count = pet_variables.poke_count - 1
|
||||||
|
|
||||||
|
|
||||||
# The function to decrease the stats and make the pet "live" needs to
|
# The function to decrease the stats and make the pet "live" needs to
|
||||||
# run in the background.
|
# run in the background.
|
||||||
def decrease_stats():
|
def decrease_stats():
|
||||||
while True:
|
while True:
|
||||||
time.sleep(15)
|
time.sleep(pet_variables.day)
|
||||||
decrease_hunger()
|
decrease_hunger()
|
||||||
decrease_poke_count()
|
decrease_poke_count()
|
||||||
if pet_variables.pet_hunger <= 0:
|
if pet_variables.pet_hunger <= 0:
|
||||||
|
@ -129,6 +151,7 @@ def stroking():
|
||||||
print("It makes comforting noises and leans against your hand.")
|
print("It makes comforting noises and leans against your hand.")
|
||||||
time.sleep(1)
|
time.sleep(1)
|
||||||
|
|
||||||
|
|
||||||
# Increases the pets hungriness by +1 unless the hunger is bigger than
|
# 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
|
# the pet's maximum hunger. In this case the pet will vomit and looses hunger
|
||||||
# and health.
|
# and health.
|
||||||
|
@ -157,13 +180,14 @@ def playing():
|
||||||
increase_happiness()
|
increase_happiness()
|
||||||
print("Game over!")
|
print("Game over!")
|
||||||
|
|
||||||
|
|
||||||
# let's you poke the pet and it will talk
|
# let's you poke the pet and it will talk
|
||||||
# if you poke it more than 3 times it will get angry at you
|
# if you poke it more than 3 times it will get angry at you
|
||||||
def poking():
|
def poking():
|
||||||
os.system('clear')
|
os.system('clear')
|
||||||
if pet_variables.poke_count < 4:
|
if pet_variables.poke_count < 4:
|
||||||
print("You poke " + pet_variables.pet_name + " and it starts to speak.")
|
print("You poke " + pet_variables.pet_name + " and it starts to speak.")
|
||||||
pet_variables.increase_poke_count()
|
increase_poke_count()
|
||||||
mixer.init()
|
mixer.init()
|
||||||
mixer.music.load('happy.mp3')
|
mixer.music.load('happy.mp3')
|
||||||
mixer.music.play()
|
mixer.music.play()
|
||||||
|
@ -175,3 +199,16 @@ def poking():
|
||||||
mixer.music.load('angry.mp3')
|
mixer.music.load('angry.mp3')
|
||||||
mixer.music.play()
|
mixer.music.play()
|
||||||
time.sleep(3)
|
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)
|
||||||
|
|
|
@ -22,3 +22,4 @@ owl = "(^0M0^)"
|
||||||
# programme variables
|
# programme variables
|
||||||
beginning_finished = False
|
beginning_finished = False
|
||||||
poke_count = 0
|
poke_count = 0
|
||||||
|
day = 15
|
||||||
|
|
|
@ -31,7 +31,7 @@ while pet_functions.is_alive():
|
||||||
print("What would you like to do?")
|
print("What would you like to do?")
|
||||||
# Start the chosen activity and go back to the activity selector.
|
# Start the chosen activity and go back to the activity selector.
|
||||||
print("1: Feeding, 2: Playing, 3: Stroke Pet,")
|
print("1: Feeding, 2: Playing, 3: Stroke Pet,")
|
||||||
print("4: Poking, 5: Show Stats,")
|
print("4: Poking, 5: Sleeping, 6: Show Stats")
|
||||||
try:
|
try:
|
||||||
chosen_activity = int(input("Choose the desired activity:"))
|
chosen_activity = int(input("Choose the desired activity:"))
|
||||||
if chosen_activity == 1:
|
if chosen_activity == 1:
|
||||||
|
@ -43,6 +43,8 @@ while pet_functions.is_alive():
|
||||||
elif chosen_activity == 4:
|
elif chosen_activity == 4:
|
||||||
pet_functions.poking()
|
pet_functions.poking()
|
||||||
elif chosen_activity == 5:
|
elif chosen_activity == 5:
|
||||||
|
pet_functions.sleeping()
|
||||||
|
elif chosen_activity == 6:
|
||||||
pet_functions.pet_stats()
|
pet_functions.pet_stats()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pet_functions.pet_stats()
|
pet_functions.pet_stats()
|
||||||
|
|
Reference in New Issue