From 8f090b951a62f6e1a6053f4c00214c6999829116 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Sun, 12 Jul 2015 22:53:40 +0200 Subject: [PATCH 1/4] add the basis for a function which let's the pet sleep --- README.md | 1 - __pycache__/pet_functions.cpython-34.pyc | Bin 5071 -> 5360 bytes __pycache__/pet_variables.cpython-34.pyc | Bin 550 -> 563 bytes pet_functions.py | 13 +++++++++++-- pet_variables.py | 1 + tamagotchi.py | 4 +++- 6 files changed, 15 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index d8f0bb2..0489059 100644 --- a/README.md +++ b/README.md @@ -10,7 +10,6 @@ tamagotchi programme which shouldn't be too hard: * sleeping with all values with over 50% full heals the pet if it has lost health * add pooping and cleaning function * let it get sick if it's health is low, by random chance or if there's too much poop -* decrease the hunger value after x seconds * add sleep function, you have to switch the lights off otherwise it will have nightmare and loose one health point. * add the possibility to get sick. Maybe compare two random numbers. * add a function to restart the game or exit it after the pet died. diff --git a/__pycache__/pet_functions.cpython-34.pyc b/__pycache__/pet_functions.cpython-34.pyc index 98e8d6bd3203ec22499ce51fb6f45fa0bc6edfb6..b1199299a198496ea2e96a6a0cbb17f054769d19 100644 GIT binary patch delta 826 zcmYjOJxml)5T3c+y`Q~zzvRFLiAPQYOAJH{(DR2w8;u4Mi6IaZg6@KM2e6e;uT$E}+$ z+5o=5p-*GG!s_>Lmr9uH0mp_X0FxFt2xE3{^BVp}EYOhl6uX)`+IvL1xo*rwuuOkr z8+e_b#~Opnh-8K9<*IkfF z=5{q_`o8REOP*GcS8$4Asgst+rk`d2)G&)NmJF*Lpl!nnP=-yIsjxqqIxcov`W|r-2#5%BL zMYV)i=ux_LHH@u6O^1NdfDTSw*Flz50i0Z&H_ULu&%m27Z*)XPImwDO;VsGHf*Ta8 zelZ+#wJ}?4c*}jWstABjLo4YqHGah}d$R7Yw2XQ4Zg5u-RsUG=w)E<5!;Z>0yUTy4CuULJvie zf)|BK=Olule?VnV{s2L|2tD@d&4Vn6;L(|FMctvbV)tMBmG_V8F8Zj%IR4+L$3P*FVai*30|gV zh42c!tL)%)I_GWUP1^N#@D^p&ZCs&W)lL77RJND^O`EQI@#6~|Z*-sl=pv*DTL@TK zu*Hf(?K>N~4x|>`Lof=8(tfr)bPpBqx0C|+sTR#RS2M_zxO;YScQxB{@?Ms$nUiwS z7ODz`LZ_H0_LI2BK|aC+sL;nUBVaRA(jgW8_h?fT-cTX;9>YviKJu}2nv-UR+QD+f zJ^vFOMa?j?{WrlP;&U3*jy304up&kN9$EHzw)_iC)((4Y#&f6KzTBYChoYuno;cNN-kW}Q>1B}q4LD(pDIFZCO+Bkt{Xuh!!O>x3Z3(X2i uFQ!B9ReW}C^+CGc%jV@>@<}FbX;l-m1EsZgb)BIY&H-%pHC@&f9sU8I7-%H` diff --git a/__pycache__/pet_variables.cpython-34.pyc b/__pycache__/pet_variables.cpython-34.pyc index 08d1ccdac43bfd618987a6a1d07180ebd3d36d27..279b3e6806063da6a9ba35527dc1ef2b43c201f1 100644 GIT binary patch delta 87 zcmZ3+vYAEs9S<*;>FGtG3mF+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..aae1089 100644 --- a/pet_functions.py +++ b/pet_functions.py @@ -110,7 +110,7 @@ def decrease_poke_count(): # 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: @@ -163,7 +163,7 @@ 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 +175,12 @@ 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.") + if pet_variables.max_hunger / pet_variables.pet_hunger > 0.5: + print("Sleeping works") + else: + print("Something is broken") 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() From a3bc091008d78df0d3a792dc16840e2a80cc7d4e Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Sun, 12 Jul 2015 22:56:25 +0200 Subject: [PATCH 2/4] updated the readme --- README.md | 2 ++ 1 file changed, 2 insertions(+) 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. From e3fe4e7da38c4c51db801d892f872cf19db4cbf2 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Sun, 12 Jul 2015 23:10:17 +0200 Subject: [PATCH 3/4] doing some cleanup --- .idea/workspace.xml | 121 +++++++++++++++++++++++++------------------- pet_functions.py | 12 ++++- 2 files changed, 80 insertions(+), 53 deletions(-) diff --git a/.idea/workspace.xml b/.idea/workspace.xml index fe225e7..89ec6b6 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,9 +2,8 @@ - - - + + @@ -28,11 +27,9 @@ - - - - - + + + @@ -41,7 +38,7 @@ - + @@ -51,7 +48,7 @@ - + @@ -65,9 +62,9 @@ @@ -75,8 +72,10 @@ - @@ -101,6 +100,8 @@ + + @@ -121,8 +122,6 @@ - - @@ -329,28 +328,28 @@ - + - - - + - - + + + - + + @@ -382,32 +381,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -420,13 +393,59 @@ + + + + + + + + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/pet_functions.py b/pet_functions.py index aae1089..2211381 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) @@ -71,14 +71,17 @@ def aging(): 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,9 +106,11 @@ 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(): @@ -129,6 +134,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,6 +163,7 @@ 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(): @@ -176,6 +183,7 @@ def poking(): mixer.music.play() time.sleep(3) + # A function which let's the pet sleep and regenerates it's stats def sleeping(): os.system('clear') From 99d625ea06915cd1ae8af8d69a8eda16abcea4ec Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 13 Jul 2015 20:38:59 +0200 Subject: [PATCH 4/4] adding a sleep function to the sleeping activity otherwise it passes too fast to see --- __pycache__/pet_functions.cpython-34.pyc | Bin 5360 -> 5386 bytes pet_functions.py | 1 + 2 files changed, 1 insertion(+) diff --git a/__pycache__/pet_functions.cpython-34.pyc b/__pycache__/pet_functions.cpython-34.pyc index b1199299a198496ea2e96a6a0cbb17f054769d19..4a96bb7f7df09adec16da486dd1291ff706bd81a 100644 GIT binary patch delta 241 zcmeyM*`>w#j)#|PC(Dx1%^NxUIT(E>&*W%i44f>@IhiqZ@_Nomj8T)FxcV96Ctu>4 z#F#QUmAjuYbMja28s0nx28LoLAi=;`WHdQ|OLFpbp4E&co1J;385x^4$MfkjGWKrn zrUSWAQV<5B0Wby`PN!j9@)YO8^y!1Ulp<*5&!NADN$i*ne$jijV cIGIP}q_i*(3lOrxAsY`L4>u1dk1&rg02CZJOaK4? delta 210 zcmeCu`k=}Aj)#})>7_-X(>HSVb1?c$p2^Y3=s#JSb24Ml$Y^o^m*nK>JgXV=H#_r6Gcwk0j_1>5WNhEu z%b&!^IAQY#fp?6IizeR}vS;*|EHCWNmcqagtjRXHQdp5Q9b^Ur!vp)t^MzHJfP$xm y