From ae77fcb86cfe921a6d08d5567c4368dd51dea0e3 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Wed, 8 Jul 2015 18:34:21 +0200 Subject: [PATCH 1/3] making the readme a bit more readable. --- README.md | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index b8facd0..d7b6b10 100644 --- a/README.md +++ b/README.md @@ -22,17 +22,18 @@ 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 ## 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. I'll have to ask reddit how to do it. From 02ced24cba3350c9d31ae8997076a3bf7d7bb403 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Thu, 9 Jul 2015 00:15:36 +0200 Subject: [PATCH 2/3] adding a stroking function --- README.md | 27 ++++++++++++++++++++++----- pet_functions.py | 9 +++++++++ pet_variables.py | 22 ---------------------- tamagotchi.py | 41 ----------------------------------------- 4 files changed, 31 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index d7b6b10..c22c070 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 @@ -35,13 +35,30 @@ file otherwise it's not clear why they are needed. 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/pet_functions.py b/pet_functions.py index 3da37e3..d818fc7 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,16 @@ 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("You're stroking the back of your pet gently.") + print("It makes comforting noises and leans against your hand.") + 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..e69de29 100644 --- a/pet_variables.py +++ b/pet_variables.py @@ -1,22 +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 - -# 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 diff --git a/tamagotchi.py b/tamagotchi.py index a232490..e69de29 100644 --- a/tamagotchi.py +++ b/tamagotchi.py @@ -1,41 +0,0 @@ -# import the threading module -import threading -# import the pets_variables -import pet_variables -# a module which includes various custom functions -import pet_functions - - -# Beginning of the main routine which makes up the actual game. - -# thread which runs in the background to cause hunger, etc -t = threading.Thread(target=pet_functions.decrease_stats) -t.start() -# Only starts if the pet is still alive. -while pet_functions.is_alive(): - if not pet_variables.beginning_finished: - # Let the player choose his pet and skip the beginning from then on. - pet_functions.beginning() - pet_variables.beginning_finished = True - print() - print() - 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.") - # checks if the pet has reached a new life stage and updates it accordingly - pet_functions.aging() - print() - # Each round print the pets stats so that the player can see them. - pet_functions.pet_stats() - print() - # Present the player with activities to choose from - print("What would you like to do?") - print("1: Feeding, 2: Playing, 3: 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.pet_stats() -print("Your pet died.") From 128db7946b44a2f4e9b8bc99ba3bec3f4d9b67e1 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Thu, 9 Jul 2015 00:19:44 +0200 Subject: [PATCH 3/3] fix a sync bug --- pet_variables.py | 23 +++++++++++++++++++++++ tamagotchi.py | 43 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 66 insertions(+) diff --git a/pet_variables.py b/pet_variables.py index e69de29..354c103 100644 --- a/pet_variables.py +++ b/pet_variables.py @@ -0,0 +1,23 @@ +# 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 + +# 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 diff --git a/tamagotchi.py b/tamagotchi.py index e69de29..9528506 100644 --- a/tamagotchi.py +++ b/tamagotchi.py @@ -0,0 +1,43 @@ +# import the threading module +import threading +# import the pets_variables +import pet_variables +# a module which includes various custom functions +import pet_functions + + +# Beginning of the main routine which makes up the actual game. + +# thread which runs in the background to cause hunger, etc +t = threading.Thread(target=pet_functions.decrease_stats) +t.start() +# Only starts if the pet is still alive. +while pet_functions.is_alive(): + if not pet_variables.beginning_finished: + # Let the player choose his pet and skip the beginning from then on. + pet_functions.beginning() + pet_variables.beginning_finished = True + print() + print() + 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.") + # checks if the pet has reached a new life stage and updates it accordingly + pet_functions.aging() + print() + # Each round print the pets stats so that the player can see them. + pet_functions.pet_stats() + print() + # Present the player with activities to choose from + print("What would you like to do?") + print("1: Feeding, 2: Playing, 3: 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: + pet_functions.pet_stats() +print("Your pet died.")