Compare commits
5 Commits
master
...
developmen
Author | SHA1 | Date |
---|---|---|
Andreas Zweili | b207707fa3 | |
Andreas Zweili | 76769c2279 | |
Andreas Zweili | be0e7e0bf4 | |
Andreas Zweili | 3cb88fe198 | |
Andreas Zweili | 612896caff |
327
pet_functions.py
327
pet_functions.py
|
@ -1,5 +1,3 @@
|
||||||
# imports the global variables
|
|
||||||
import pet_variables
|
|
||||||
# imports the time library needed to delay certain functions
|
# imports the time library needed to delay certain functions
|
||||||
import time
|
import time
|
||||||
# imports the random library needed to generate a random number for
|
# imports the random library needed to generate a random number for
|
||||||
|
@ -10,207 +8,190 @@ import os
|
||||||
# imports the pygame library needed to play the sound in the
|
# imports the pygame library needed to play the sound in the
|
||||||
# poking function
|
# poking function
|
||||||
from pygame import mixer
|
from pygame import mixer
|
||||||
|
import threading
|
||||||
|
|
||||||
# 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 programme ###
|
### a class for controlling the pet ###
|
||||||
|
|
||||||
# a function which displays the pet's stats in a nice way.
|
class Pet(object):
|
||||||
def pet_stats():
|
def __init__(self, name, photo, status, health, age, hunger, happiness, poke_count,
|
||||||
os.system('clear')
|
max_health, max_hunger, max_happiness):
|
||||||
print(pet_variables.pet_name)
|
# The pet's stats
|
||||||
print(pet_variables.pet_photo)
|
self.name = name
|
||||||
print("Status: " + pet_variables.pet_status)
|
self.photo = photo
|
||||||
print("Age: " + str(pet_variables.pet_age))
|
self.status = status
|
||||||
print("Health: " + pet_variables.pet_health * "♥")
|
self.health = health
|
||||||
print("Hunger: " + pet_variables.pet_hunger * "*")
|
self.age = age
|
||||||
print("Happines: " + pet_variables.pet_happiness * "☺")
|
self.hunger = hunger
|
||||||
|
self.happiness = happiness
|
||||||
|
self.poke_count = poke_count
|
||||||
|
self.max_health = max_health
|
||||||
|
self.max_hunger = max_hunger
|
||||||
|
self.max_happiness = max_happiness
|
||||||
|
|
||||||
|
# a function which displays the pet's stats in a nice way.
|
||||||
|
def display_stats(self):
|
||||||
|
os.system('clear')
|
||||||
|
print(self.name)
|
||||||
|
print(self.photo)
|
||||||
|
print("Status: " + self.status)
|
||||||
|
print("Age: " + str(self.age))
|
||||||
|
print("Health: " + self.health * "♥")
|
||||||
|
print("Hunger: " + self.hunger * "*")
|
||||||
|
print("Happines: " + self.happiness * "☺")
|
||||||
|
|
||||||
# A function which checks if the pet is still alive
|
# A function which checks if the pet is still alive
|
||||||
def is_alive():
|
def is_alive(self):
|
||||||
return pet_variables.pet_health > 0
|
return self.health > 0
|
||||||
|
|
||||||
|
# A function which changes the status of the pet depending of the age value.
|
||||||
|
# Each status has it's own characteristics.
|
||||||
|
|
||||||
# A function which let's the player choose his pet.
|
def set_youngling_stats(self):
|
||||||
def beginning():
|
self.max_health = 10
|
||||||
print("Which pet do you want to look after?")
|
self.max_happiness = 8
|
||||||
print("1: Cat, 2: Mouse, 3: Fish, 4: Owl")
|
self.max_hunger = 7
|
||||||
chosen_pet = int(input("Choose your pet:"))
|
|
||||||
if chosen_pet == 1:
|
|
||||||
pet_variables.pet_photo = pet_variables.cat
|
|
||||||
elif chosen_pet == 2:
|
|
||||||
pet_variables.pet_photo = pet_variables.mouse
|
|
||||||
elif chosen_pet == 3:
|
|
||||||
pet_variables.pet_photo = pet_variables.fish
|
|
||||||
elif chosen_pet == 4:
|
|
||||||
pet_variables.pet_photo = pet_variables.owl
|
|
||||||
pet_variables.pet_name = input("How do you want to call your pet?")
|
|
||||||
|
|
||||||
|
def set_adult_stats(self):
|
||||||
|
self.max_health = 10
|
||||||
|
self.max_happiness = 8
|
||||||
|
self.max_hunger = 7
|
||||||
|
|
||||||
# A function which changes the status of the pet depending of the age value.
|
def set_elderly_stats(self):
|
||||||
# Each status has it's own characteristics.
|
self.max_health = 7
|
||||||
|
self.max_happiness = 5
|
||||||
|
self.max_hunger = 10
|
||||||
|
|
||||||
def set_youngling_stats():
|
def reset_stats(self):
|
||||||
pet_variables.max_health = 10
|
self.health = self.max_health
|
||||||
pet_variables.max_happiness = 8
|
self.happiness = self.max_happiness
|
||||||
pet_variables.max_hunger = 7
|
self.hunger = self.max_hunger
|
||||||
|
|
||||||
|
def aging(self):
|
||||||
|
if self.age == 5:
|
||||||
|
self.status = "adult"
|
||||||
|
self.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 self.age == 15:
|
||||||
|
self.status = "elderly"
|
||||||
|
self.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.")
|
||||||
|
|
||||||
def set_adult_stats():
|
### Functions to increase and decrease stats ###
|
||||||
pet_variables.max_health = 10
|
|
||||||
pet_variables.max_happiness = 8
|
|
||||||
pet_variables.max_hunger = 7
|
|
||||||
|
|
||||||
|
def increase_hunger(self):
|
||||||
|
if self.hunger < self.max_hunger:
|
||||||
|
self.hunger += 1
|
||||||
|
|
||||||
def set_elderly_stats():
|
def increase_poke_count(self):
|
||||||
pet_variables.max_health = 7
|
self.poke_count += 1
|
||||||
pet_variables.max_happiness = 5
|
|
||||||
pet_variables.max_hunger = 10
|
|
||||||
|
|
||||||
|
def increase_happiness(self):
|
||||||
|
if self.happiness < self.max_happiness:
|
||||||
|
self.happiness += 1
|
||||||
|
|
||||||
def reset_stats():
|
def increase_health(self):
|
||||||
pet_variables.pet_health = pet_variables.max_health
|
if self.health < self.max_health:
|
||||||
pet_variables.pet_happiness = pet_variables.max_happiness
|
self.health += 1
|
||||||
pet_variables.pet_hunger = pet_variables.max_hunger
|
|
||||||
|
|
||||||
|
def decrease_hunger(self):
|
||||||
|
if self.hunger > 0:
|
||||||
|
self.hunger -= 1
|
||||||
|
|
||||||
def aging():
|
def decrease_happiness(self):
|
||||||
if pet_variables.pet_age == 5:
|
if self.happiness > 0:
|
||||||
pet_variables.pet_status = "adult"
|
self.happiness -= 1
|
||||||
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"
|
|
||||||
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.")
|
|
||||||
|
|
||||||
|
def decrease_health(self):
|
||||||
|
if self.health > 0:
|
||||||
|
self.health -= 1
|
||||||
|
|
||||||
### Functions to increase and decrease stats ###
|
def decrease_poke_count(self):
|
||||||
|
self.poke_count -= 1
|
||||||
|
|
||||||
def increase_hunger():
|
# The function to decrease the stats and make the pet "live" needs to
|
||||||
if pet_variables.pet_hunger < pet_variables.max_hunger:
|
# run in the background.
|
||||||
pet_variables.pet_hunger += 1
|
def _decrease_stats(self):
|
||||||
|
while True:
|
||||||
|
time.sleep(2)
|
||||||
|
self.decrease_hunger()
|
||||||
|
if self.hunger <= 0:
|
||||||
|
self.decrease_health()
|
||||||
|
self.decrease_happiness()
|
||||||
|
|
||||||
|
def decrease_stats(self):
|
||||||
|
threading.Thread(target=self.decrease_stats).start()
|
||||||
|
|
||||||
def increase_poke_count():
|
### Activities ###
|
||||||
pet_variables.poke_count += 1
|
|
||||||
|
|
||||||
|
# A function which simulates stroking it doesn't have any
|
||||||
|
# effect on the pet.
|
||||||
|
def stroking(self):
|
||||||
|
os.system('clear')
|
||||||
|
print()
|
||||||
|
print("You're stroking the back of your pet gently.")
|
||||||
|
print("It makes comforting noises and leans against your hand.")
|
||||||
|
time.sleep(1)
|
||||||
|
|
||||||
def increase_happiness():
|
# Increases the pets hungriness by +1 unless the hunger is bigger than
|
||||||
if pet_variables.pet_happiness < pet_variables.max_happiness:
|
# the pet's maximum hunger. In this case the pet will vomit and looses hunger
|
||||||
pet_variables.pet_happiness += 1
|
# and health.
|
||||||
|
def feeding(self):
|
||||||
|
os.system('clear')
|
||||||
|
print("Hungriness of " + self.name + ": " + self.hunger * "*")
|
||||||
|
feeding_confirmed = input("Do you want to feed your pet?")
|
||||||
|
if feeding_confirmed in ("Y", "y"):
|
||||||
|
self.increase_hunger()
|
||||||
|
|
||||||
|
# A simple guessing game which increases the pet's happiness
|
||||||
def increase_health():
|
def playing(self):
|
||||||
if pet_variables.pet_health < pet_variables.max_health:
|
guess = 0
|
||||||
pet_variables.pet_health += 1
|
os.system('clear')
|
||||||
|
while guess != secret:
|
||||||
|
g = input("Guess the Number")
|
||||||
def decrease_hunger():
|
guess = int(g)
|
||||||
if pet_variables.pet_hunger > 0:
|
if guess == secret:
|
||||||
pet_variables.pet_hunger -= 1
|
print("You win!")
|
||||||
|
|
||||||
|
|
||||||
def decrease_happiness():
|
|
||||||
if pet_variables.pet_happiness > 0:
|
|
||||||
pet_variables.pet_happiness -= 1
|
|
||||||
|
|
||||||
|
|
||||||
def decrease_health():
|
|
||||||
if pet_variables.pet_health > 0:
|
|
||||||
pet_variables.pet_health -= 1
|
|
||||||
|
|
||||||
|
|
||||||
def decrease_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(pet_variables.day)
|
|
||||||
decrease_hunger()
|
|
||||||
if pet_variables.pet_hunger <= 0:
|
|
||||||
decrease_health()
|
|
||||||
decrease_happiness()
|
|
||||||
|
|
||||||
|
|
||||||
### Activities ###
|
|
||||||
|
|
||||||
# A function which simulates stroking it doesn't have any
|
|
||||||
# effect on the pet.
|
|
||||||
def stroking():
|
|
||||||
os.system('clear')
|
|
||||||
print()
|
|
||||||
print("You're stroking the back of your pet gently.")
|
|
||||||
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.
|
|
||||||
def feeding():
|
|
||||||
os.system('clear')
|
|
||||||
print("Hungriness of " + pet_variables.pet_name + ": " + pet_variables.pet_hunger * "*")
|
|
||||||
feeding_confirmed = input("Do you want to feed your pet?")
|
|
||||||
if feeding_confirmed in ("Y", "y"):
|
|
||||||
increase_hunger()
|
|
||||||
|
|
||||||
|
|
||||||
# A simple guessing game which increases the pet's happiness
|
|
||||||
def playing():
|
|
||||||
guess = 0
|
|
||||||
os.system('clear')
|
|
||||||
while guess != secret:
|
|
||||||
g = input("Guess the Number")
|
|
||||||
guess = int(g)
|
|
||||||
if guess == secret:
|
|
||||||
print("You win!")
|
|
||||||
else:
|
|
||||||
if guess > secret:
|
|
||||||
print("Your guess is too high")
|
|
||||||
else:
|
else:
|
||||||
print("Too low")
|
if guess > secret:
|
||||||
increase_happiness()
|
print("Your guess is too high")
|
||||||
print("Game over!")
|
else:
|
||||||
|
print("Too low")
|
||||||
|
self.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(self):
|
||||||
|
os.system('clear')
|
||||||
|
if self.poke_count < 3:
|
||||||
|
print("You poke " + self.name + " and it starts to speak.")
|
||||||
|
self.increase_poke_count()
|
||||||
|
mixer.init()
|
||||||
|
mixer.music.load('happy.mp3')
|
||||||
|
mixer.music.play()
|
||||||
|
time.sleep(5)
|
||||||
|
else:
|
||||||
|
print("You annoyed " + self.name + "." + " It got angry at you.")
|
||||||
|
self.decrease_happiness()
|
||||||
|
mixer.init()
|
||||||
|
mixer.music.load('angry.mp3')
|
||||||
|
mixer.music.play()
|
||||||
|
time.sleep(3)
|
||||||
|
|
||||||
# let's you poke the pet and it will talk
|
# A function which let's the pet sleep and regenerates it's stats
|
||||||
# if you poke it more than 3 times it will get angry at you
|
def sleeping(self):
|
||||||
def poking():
|
os.system('clear')
|
||||||
os.system('clear')
|
print("Your pet is sleeping now.")
|
||||||
if pet_variables.poke_count < 3:
|
time.sleep(10)
|
||||||
print("You poke " + pet_variables.pet_name + " and it starts to speak.")
|
if self.max_hunger / self.hunger > 0.5:
|
||||||
increase_poke_count()
|
self.reset_stats()
|
||||||
mixer.init()
|
print("Your pet woke up feeling rested and in a good mood.")
|
||||||
mixer.music.load('happy.mp3')
|
else:
|
||||||
mixer.music.play()
|
print("Your pet has woken up.")
|
||||||
time.sleep(5)
|
|
||||||
else:
|
|
||||||
print("You annoyed " + pet_variables.pet_name + "." + " It got angry at you.")
|
|
||||||
decrease_happiness()
|
|
||||||
mixer.init()
|
|
||||||
mixer.music.load('angry.mp3')
|
|
||||||
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)
|
|
||||||
|
|
|
@ -1,25 +0,0 @@
|
||||||
# The pet's stats
|
|
||||||
pet_name = "Fluffy"
|
|
||||||
pet_photo = "<`)))><"
|
|
||||||
pet_status = "youngling"
|
|
||||||
pet_health = 5
|
|
||||||
pet_age = 0
|
|
||||||
pet_hunger = 5
|
|
||||||
pet_happiness = 5
|
|
||||||
pet_stomach = 0
|
|
||||||
|
|
||||||
# age based max values
|
|
||||||
max_health = 5
|
|
||||||
max_hunger = 5
|
|
||||||
max_happiness = 10
|
|
||||||
|
|
||||||
# Pictures and symbols used ingame
|
|
||||||
cat = "(=^o.o^=)__"
|
|
||||||
mouse = "<:3 )~~~~"
|
|
||||||
fish = "<`)))><"
|
|
||||||
owl = "(^0M0^)"
|
|
||||||
|
|
||||||
# programme variables
|
|
||||||
beginning_finished = False
|
|
||||||
poke_count = 0
|
|
||||||
day = 15
|
|
|
@ -1,33 +1,48 @@
|
||||||
# import the threading module
|
# import the threading module
|
||||||
import threading
|
import threading
|
||||||
# import the pets_variables
|
|
||||||
import pet_variables
|
|
||||||
# a module which includes various custom functions
|
# a module which includes various custom functions
|
||||||
import pet_functions
|
from pet_functions import Pet
|
||||||
|
|
||||||
|
# global variable need to lock the beginning
|
||||||
|
beginning_finished = False
|
||||||
|
day = 15
|
||||||
|
|
||||||
|
# Pictures and symbols used ingame
|
||||||
|
cat = "(=^o.o^=)__"
|
||||||
|
mouse = "<:3 )~~~~"
|
||||||
|
fish = "<`)))><"
|
||||||
|
owl = "(^0M0^)"
|
||||||
|
|
||||||
|
# initializing the tamagotchi
|
||||||
|
tamagotchi = Pet(name="empty", photo="empty", status="youngling", age=0, health=5, hunger=5, happiness=5,
|
||||||
|
max_happiness=10, max_health=5, max_hunger=5, poke_count=0)
|
||||||
|
|
||||||
|
|
||||||
# Beginning of the main routine which makes up the actual game.
|
# A function which let's the player choose his pet.
|
||||||
|
def beginning():
|
||||||
# thread which runs in the background to cause hunger, etc
|
global beginning_finished
|
||||||
t = threading.Thread(target=pet_functions.decrease_stats)
|
print("Which pet do you want to look after?")
|
||||||
t.start()
|
print("1: Cat, 2: Mouse, 3: Fish, 4: Owl")
|
||||||
# Only starts if the pet is still alive.
|
chosen_pet = int(input("Choose your pet:"))
|
||||||
while pet_functions.is_alive():
|
if chosen_pet == 1:
|
||||||
if not pet_variables.beginning_finished:
|
pet_photo = cat
|
||||||
# Let the player choose his pet and skip the beginning from then on.
|
elif chosen_pet == 2:
|
||||||
pet_functions.beginning()
|
pet_photo = mouse
|
||||||
pet_variables.beginning_finished = True
|
elif chosen_pet == 3:
|
||||||
print()
|
pet_photo = fish
|
||||||
print()
|
elif chosen_pet == 4:
|
||||||
print("Your pet is currently a youngling which means it's needs a lot of attention.")
|
pet_photo = owl
|
||||||
print("Take good care of it or it will die very soon.")
|
pet_name = input("How do you want to call your pet?")
|
||||||
# checks if the pet has reached a new life stage and updates it accordingly
|
tamagotchi.name = pet_name
|
||||||
pet_functions.aging()
|
tamagotchi.photo = pet_photo
|
||||||
print()
|
print()
|
||||||
# Each round print the pets stats so that the player can see them.
|
|
||||||
pet_functions.pet_stats()
|
|
||||||
print()
|
print()
|
||||||
# Present the player with activities to choose from
|
print("Your pet is currently a youngling which means it's needs a lot of attention.")
|
||||||
|
print("Take good care of it or it will die very soon.")
|
||||||
|
beginning_finished = True
|
||||||
|
|
||||||
|
# Present the player with activities to choose from
|
||||||
|
def menu():
|
||||||
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,")
|
||||||
|
@ -35,17 +50,37 @@ while pet_functions.is_alive():
|
||||||
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:
|
||||||
pet_functions.feeding()
|
tamagotchi.feeding()
|
||||||
elif chosen_activity == 2:
|
elif chosen_activity == 2:
|
||||||
pet_functions.playing()
|
tamagotchi.playing()
|
||||||
elif chosen_activity == 3:
|
elif chosen_activity == 3:
|
||||||
pet_functions.stroking()
|
tamagotchi.stroking()
|
||||||
elif chosen_activity == 4:
|
elif chosen_activity == 4:
|
||||||
pet_functions.poking()
|
tamagotchi.poking()
|
||||||
elif chosen_activity == 5:
|
elif chosen_activity == 5:
|
||||||
pet_functions.sleeping()
|
tamagotchi.sleeping()
|
||||||
elif chosen_activity == 6:
|
elif chosen_activity == 6:
|
||||||
pet_functions.pet_stats()
|
tamagotchi.display_stats()
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pet_functions.pet_stats()
|
tamagotchi.display_stats()
|
||||||
print("Your pet died.")
|
|
||||||
|
# Beginning of the main routine which makes up the actual game.
|
||||||
|
|
||||||
|
# Only starts if the pet is still alive.
|
||||||
|
def main():
|
||||||
|
while tamagotchi.is_alive():
|
||||||
|
if not beginning_finished:
|
||||||
|
# Let the player choose his pet and skip the beginning from then on.
|
||||||
|
beginning()
|
||||||
|
tamagotchi.decrease_stats()
|
||||||
|
# checks if the pet has reached a new life stage and updates it accordingly
|
||||||
|
tamagotchi.aging()
|
||||||
|
print()
|
||||||
|
# Each round print the pets stats so that the player can see them.
|
||||||
|
tamagotchi.display_stats()
|
||||||
|
print()
|
||||||
|
menu()
|
||||||
|
print("Your pet died.")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__": main()
|
||||||
|
|
Reference in New Issue