From b8049a48e947e04e98ce678646cb31c84e1768c3 Mon Sep 17 00:00:00 2001 From: Nebucatnetzer Date: Fri, 10 Jul 2015 12:08:10 +0200 Subject: [PATCH 1/3] adding a pause of 1 second to the stroking function to make it more readable --- README.md | 42 +++++++++++++++++------ __pycache__/pet_functions.cpython-34.pyc | Bin 3880 -> 4149 bytes __pycache__/pet_variables.cpython-34.pyc | Bin 504 -> 525 bytes pet_functions.py | 11 ++++++ pet_variables.py | 1 + tamagotchi.py | 4 ++- 6 files changed, 46 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index b8facd0..37bba99 100644 --- a/README.md +++ b/README.md @@ -13,7 +13,7 @@ tamagotchi programme which shouldn't be too hard: * ~~give it points for hungriness~~ * ~~add the guessing game and increase the happiness by one point when you finished the game~~ * ~~create a list with things you can do~~ -* pet it to increase happiness +* ~~pet it to increase happiness~~ * poke it to make it speak, pokes let it loose a happiness point * ~~add max values depending on the status~~ * sleeping with all values with over 50% full heals the pet if it has lost health @@ -22,25 +22,45 @@ tamagotchi programme which shouldn't be too hard: * ~~let it age~~ * 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. +* 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. * add a function let the user exit the game * safe the stats in a text file +* make a seperate function for each age because it makes the aging +funciton more readable ## 30.6.2015 -Time function has to be implemented otherwise the decrease.* functions won't work. -It seems to work however the import time part has to go into the pet_functions.py file. -Maybe I should move all the imports to that file otherwise it's not clear why they are needed. +Time function has to be implemented otherwise the decrease.* functions +won't work. It seems to work however the import time part has to go into +the pet_functions.py file. Maybe I should move all the imports to that +file otherwise it's not clear why they are needed. -Moved all the imports to there relevant place +Moved all the imports to there relevant place And added the time import. Things are working now like intended. -However the pet doesn't get updated automatically. I currently don't know how to achieve that. +However the pet doesn't get updated automatically. +I currently don't know how to achieve that. I'll have to ask reddit how to do it. ## 06.07.2015 -I've written a function to decrease the stats in the background. Means the tamagotchi can now get hungry etc. -However it currently doesn't work. I don't know why atm. If you call it independently it works just fine. +I've written a function to decrease the stats in the background. +Means the tamagotchi can now get hungry etc. +However it currently doesn't work. I don't know why atm. If you call it +independently it works just fine. -In addition I've cleaned up the code a bit and made sure that the stats variables don't fall under 0 because that might cause some problems in the future. +In addition I've cleaned up the code a bit and made sure that the stats +variables don't fall under 0 because that might cause some problems +in the future. ## 07.07.2015 +I've fixed the decrease_stats function. However I wanted that it only +starts after the beginning is finished. So that the pet doesn't start +with a disadvantage. I currently don't know how to fix this. For the +moment it will work like this. I could add a function to the beginning +which resets the stats back to the default values. Might be a good work- +around however for the future I would like how to do it properly. + +## 08.07.2015 +The feature to the pet the pet will be so that it only prints a message. +It wouldn't be fun if it would increase happiness because that would be +too easy. + diff --git a/__pycache__/pet_functions.cpython-34.pyc b/__pycache__/pet_functions.cpython-34.pyc index 1b11897ef9a9783a82643a2b75c377de1300433e..7c06c37bc583d9c9967775c817498223069d3523 100644 GIT binary patch delta 387 zcmYjLO-n*S6uslC_eAGCjX;SYhAcxdEkjzgY1^U*qDAeVzUN2ko0>Ngx^ZEDpoX?> zi=dUX?ML(%+6Cngh@d+~)LibF%Q@%HoV$fbmU*XkY%&3K*lc~7uYU$TZD$WFgF*xZq<>$d%n)p)ngh144XZ-vOX zfyX+&8{pJ%TR|v))|PD(RDRFO$Plclyjhv?5*K5_c;j)#})&eFM|os0|&j~S2vkk8-%#KkESmGw+m7^2u2QkWT{IKU()LkcTH z6css{jB1 delta 111 zcmeBW`N6FGj)#})mhYU;^Mf8%6fXt3{mV1DL|5gA%&G8ijyIQ zjUkGQA%&eGikl&Yks*qQA%%k>ikBgUlOc+4Vrv*9|HL~%ldTyyu*d)nnf#Ga1^{oo B6x{#- diff --git a/pet_functions.py b/pet_functions.py index 3da37e3..5817181 100644 --- a/pet_functions.py +++ b/pet_functions.py @@ -93,6 +93,8 @@ def decrease_health(): pet_variables.pet_health = pet_variables.pet_health - 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) @@ -102,9 +104,18 @@ def decrease_stats(): decrease_happiness() +### Activities ### + # 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 stroking(): + 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 feeding(): print("Hungriness of " + pet_variables.pet_name + ": " + pet_variables.pet_hunger * "*") feeding_confirmed = input("Do you want to feed your pet?") diff --git a/pet_variables.py b/pet_variables.py index 318a17f..2373b74 100644 --- a/pet_variables.py +++ b/pet_variables.py @@ -6,6 +6,7 @@ pet_health = 5 pet_age = 0 pet_hunger = 5 pet_happiness = 5 +pet_stomach = 0 # age based max values max_health = 5 diff --git a/tamagotchi.py b/tamagotchi.py index a232490..40412cb 100644 --- a/tamagotchi.py +++ b/tamagotchi.py @@ -29,7 +29,7 @@ while pet_functions.is_alive(): print() # Present the player with activities to choose from print("What would you like to do?") - print("1: Feeding, 2: Playing, 3: Show Stats") + print("1: Feeding, 2: Playing, 3: Stroke Pet, 4: Show Stats") # Start the chosen activity and go back to the activity selector. chosen_activity = int(input("Choose the desired activity:")) if chosen_activity == 1: @@ -37,5 +37,7 @@ while pet_functions.is_alive(): elif chosen_activity == 2: pet_functions.playing() elif chosen_activity == 3: + pet_functions.stroking() + elif chosen_activity == 4: pet_functions.pet_stats() print("Your pet died.") From a72fe6c275142c4cac604beaeca929d3d6d01681 Mon Sep 17 00:00:00 2001 From: Nebucatnetzer Date: Sun, 12 Jul 2015 13:41:15 +0200 Subject: [PATCH 2/3] moving some variables into the pet_variables file --- README.md | 2 +- __pycache__/pet_functions.cpython-34.pyc | Bin 4232 -> 4150 bytes pet_functions.py | 13 ++++--------- 3 files changed, 5 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 37bba99..af987ab 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,6 @@ # tamagotchi ## Todo -* make the aging work parallel the main programme * adding a function to decrease the health ## Possible things to add @@ -28,6 +27,7 @@ tamagotchi programme which shouldn't be too hard: * safe the stats in a text file * make a seperate function for each age because it makes the aging funciton more readable +* add a function which lets the tamagotchi age (one week as a youngling, three weeks as an adult and two weeks as an elderly) ## 30.6.2015 Time function has to be implemented otherwise the decrease.* functions diff --git a/__pycache__/pet_functions.cpython-34.pyc b/__pycache__/pet_functions.cpython-34.pyc index 58f563ee193fb34468f927a345becd280feac409..abc493ca8061714487b43b0d8f28f7a7fdd5007a 100644 GIT binary patch delta 563 zcmY+BJ!n%=6vzK3H_1zGU-DklTAO~R_?9d!Qs`Exn8hW26j6#;OOMc2%@9)xqI9Sf zx7Hk-1P8&<>4Af5Mi*DRI*FiDch5Tz(EG*j-rxN?_r6~E+(>?h6~B14^3^rzqnx|t!>i~y?B%m|vw+Smyg(M~;~cv8O%;b~ z#Z=MMfvI4qrcDK=`ld=l1@v;+YaNk|=)*woS8hK~?(Xbv@5sCSd*AhX*)zAj)st(5 z)}^`Z6DG3&$ZM`qNYQ__+mHvYo(>9^bF?Jq!6~iDaY?8pQ{_HgmrvyrYRjtc)4F`~ zCv;C9jtposO~N`+C%sY`CE8DKR$D|bu@+6-53-ae} An*aa+ delta 642 zcmY+B&ubGw6vw}BH@mahY<@Jxnx<)++6Y;Z8mM@Xw0NkXhn7N6WWmJX^B`hEw+q4| z7F3F!s-2Ss@m~-Y^ytCA!d~^_rDu=M3w`p~|<&o&|loI~V-9Yg}`BJ%Lq1}paP+Cr2EtM20s5c%K&I54cB2rd~8 zz-4g7u#z+2s^Jp&9Jpp!O*jvpHCzE-0Pok$K+T>5Hw;(7^WdgowQ>QxXt)Mm0=EpS zU6#QY4bOsCz-_~7M?ycm^hZBVd>EMJ8orKljByu^)|+*jLw=MQ5|MqW@G~zlMAjRSM2V zw(D$JbWMI2@9CD@@g&`mzr7>cme2Et)R)3PqWkjLKcolpa^VMYc3PMt+RMD+3{jdj zN}EKl Date: Sun, 12 Jul 2015 15:19:41 +0200 Subject: [PATCH 3/3] catching the ValueError in the activity list when pressing enter because enter is not an integer --- README.md | 8 -------- tamagotchi.py | 19 +++++++++++-------- 2 files changed, 11 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index af987ab..4ad6fd9 100644 --- a/README.md +++ b/README.md @@ -7,18 +7,10 @@ Some interesting things I could add to the tamagotchi programme which shouldn't be too hard: -* ~~create a loop~~ -* ~~give it happiness~~ -* ~~give it points for hungriness~~ -* ~~add the guessing game and increase the happiness by one point when you finished the game~~ -* ~~create a list with things you can do~~ -* ~~pet it to increase happiness~~ * poke it to make it speak, pokes let it loose a happiness point -* ~~add max values depending on the status~~ * 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 -* ~~let it age~~ * 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. diff --git a/tamagotchi.py b/tamagotchi.py index 40412cb..b4b53b8 100644 --- a/tamagotchi.py +++ b/tamagotchi.py @@ -31,13 +31,16 @@ while pet_functions.is_alive(): print("What would you like to do?") print("1: Feeding, 2: Playing, 3: Stroke Pet, 4: Show Stats") # Start the chosen activity and go back to the activity selector. - chosen_activity = int(input("Choose the desired activity:")) - if chosen_activity == 1: - pet_functions.feeding() - elif chosen_activity == 2: - pet_functions.playing() - elif chosen_activity == 3: - pet_functions.stroking() - elif chosen_activity == 4: + try: + chosen_activity = int(input("Choose the desired activity:")) + if chosen_activity == 1: + pet_functions.feeding() + elif chosen_activity == 2: + pet_functions.playing() + elif chosen_activity == 3: + pet_functions.stroking() + elif chosen_activity == 4: + pet_functions.pet_stats() + except ValueError: pet_functions.pet_stats() print("Your pet died.")