From 8d7d5223f65bca563c2359db3214e66fe6a81456 Mon Sep 17 00:00:00 2001 From: Nebucatnetzer Date: Tue, 14 Jul 2015 12:39:47 +0200 Subject: [PATCH] finalizing the sleeping function --- README.md | 2 + __pycache__/pet_functions.cpython-34.pyc | Bin 5071 -> 6099 bytes __pycache__/pet_variables.cpython-34.pyc | Bin 550 -> 563 bytes pet_functions.py | 57 +++++++++++++++++++---- pet_variables.py | 1 + tamagotchi.py | 4 +- 6 files changed, 53 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 0489059..dc7b0ed 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/__pycache__/pet_functions.cpython-34.pyc b/__pycache__/pet_functions.cpython-34.pyc index 98e8d6bd3203ec22499ce51fb6f45fa0bc6edfb6..7005762f8992eec85b794a0b0dfc575baef96930 100644 GIT binary patch delta 2031 zcmb7FO>7%Q6rS<^*j|slcATHON!m@_{A_+4r}-%~A!%qUl|NS%0z{FBOlRvlalGm5 zMkSFTpaR!Qog=6xBsjn!%BfsHLi}712W~lm;8F>3;lh#kW?jccT)Lb6@^)t4zIpHa z=K1H*U#5$Hv9$HwAD_PRd4Z7MNynvueIA}*ZNFHgt7C+_#0b}vp%G5NTdxQMmOV@$!~tAgq~v~lLY~QV59b3fT-))to3%#0Sz8OjY8WiS zqQC?oGzqsDmHS5F@)N`or@&Vf0WcQYrxAt`M&viCf`d`3e7g}w5zoU+XT-55iHLC? zVu~uy|BraAn8T1>gL|T}69v8WpP=Iy^u;k4g?g?>RaGTjkLszbaYNPCjA~0OZoDJG z9Bx8onMZ3xt|bNsQ^Ld0sD=-jr0}yJ1O5)U_>9!@NFf*BDY58^Hxcu1am+vHO>rM2D zp^sd(23pfs(r>kgsVK|+5rf=&Rs5ayNs=Wu^x8SY&dUN!I{&3y>-0rE(wMzg?E z99W7|aZaV>rN1@L;uoGm-xG--6#fRVE71!%C%`IlYf-T%dFFw+gsY#CMcbt%`I24k zx!<|e0a=5vmk;jQBb3g_2iZ~jnfxs~)V~VLuEW#5G_Wqf6Z{|tbAtt+L?Xx98KjTv zq)!#llwalw($C#uDOFKbA143IEkP4>yB0d!= zQpI;wtCG2;vi%B1f&l=`)}}ow<1E^KkCmJ9l(^H2EkUbed6f%rZ4)q98~@gC15yBHqDgrvF?aDso{| zpqn@@S{1Yoq+CTUf(W9hAa|~cRuTl!Cfd|F{~cd*=6?75=kd*X{IlBfIhpurT1Ncs zlXJJrg!nGDeRR@~(vwd-OC-P#;!JAa%02iE5W}1LUD>`Q8B}@q_=!+(Qa=lm2mO)K8x>9uE_>|%kj$bK+0pSG1JP2SdsI;kGb~00uVpUe9i<4ZJOAVxH#Z>fXyI#{GOHCO}Bq87-Ziv~haP=z_ijYE^oltS2@J z1gWAmpF4Inx8~1J=5o`rg&hYN)S60IYbDTRhAXR&Z1$aZhur)mx$+SL0Xpp}NMb_} z2P0LuYQG7zkwYG&#CUbymDeW5rbcdYhM_Vz-XM|f_$B%xaF~NT@Ii43()hACQ$}@f zh3*BDM0P$eX#i-(WGo4b*dMEfZk&n5;XN+Isw<^%>E=`K8jqra{tOlB;?ogd#}-WQ zf1rjC#(~mqsKcew_PUfU`KrnggX+7HHLg;c3{Ci}v@Yy*!)G;%uE4bF=n+{8HFGtG3mF+09y1^TAfLejh>Hs*DyMLWUG{1N~F delta 72 zcmdnYvW!Lf9S<+p>LZInXD~7_JZ3-wKt6*55Eo}nR8C>xVu%u$I5Cu+1t{XDDLC=% Qp2_PN;~5nu^D!v{07obf@&Et; diff --git a/pet_functions.py b/pet_functions.py index 792be50..312c395 100644 --- a/pet_functions.py +++ b/pet_functions.py @@ -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) diff --git a/pet_variables.py b/pet_variables.py index 9fa9ca1..4b56398 100644 --- a/pet_variables.py +++ b/pet_variables.py @@ -22,3 +22,4 @@ owl = "(^0M0^)" # programme variables beginning_finished = False poke_count = 0 +day = 15 diff --git a/tamagotchi.py b/tamagotchi.py index 2546eb5..d40c80d 100644 --- a/tamagotchi.py +++ b/tamagotchi.py @@ -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()