From c622d3ba31ea96f5c3c00e100a81c6e4c15a7fd1 Mon Sep 17 00:00:00 2001 From: ph Date: Wed, 17 Jul 2024 23:32:12 +0200 Subject: [PATCH] adds brewing files --- src/brewing/brew_potions.py | 26 +++++++++ src/brewing/containers.py | 6 +++ src/brewing/cooking.py | 50 +++++++++++++++++ src/brewing/ingredients.py | 5 ++ src/brewing/inspection.py | 103 ++++++++++++++++++++++++++++++++++++ src/brewing/potion_class.py | 46 ++++++++++++++++ 6 files changed, 236 insertions(+) create mode 100644 src/brewing/brew_potions.py create mode 100644 src/brewing/containers.py create mode 100644 src/brewing/cooking.py create mode 100644 src/brewing/ingredients.py create mode 100644 src/brewing/inspection.py create mode 100644 src/brewing/potion_class.py diff --git a/src/brewing/brew_potions.py b/src/brewing/brew_potions.py new file mode 100644 index 0000000..0c9a67b --- /dev/null +++ b/src/brewing/brew_potions.py @@ -0,0 +1,26 @@ +from src.brewing import potion_class +from src.brewing import containers +from src.brewing import cooking +from src.brewing import inspection + +def make_example_potion(student_name="ASPP student"): + my_potion = potion_class.Potion(student_name=student_name) + # Set up your old kettle and light an eternal flame underneath it. + my_potion.setup(container=containers.old_kettle) + # Simmer for 5 hours. + cooking.simmer(my_potion, duration=5) + print(f"You successfully ran make_example_potion, {student_name}, well done :).") + return my_potion + + +def make_python_expert_potion(student_name): + print("I am a Python Expert") + # todo: write this function! + return + + +if __name__ == "__main__": + my_name = 'ASPP student' + my_potion = make_example_potion(student_name=my_name) + # Let Snape inspect the potion + inspection.inspection_by_Snape(potion=my_potion, target_potion='example_potion') diff --git a/src/brewing/containers.py b/src/brewing/containers.py new file mode 100644 index 0000000..d355480 --- /dev/null +++ b/src/brewing/containers.py @@ -0,0 +1,6 @@ +# containers +pewter_cauldron = 'pewter_cauldron' +copper_cauldron = 'copper_cauldron' +martini_glass = 'martini_glass' +old_kettle = 'old_kettle' +raki_bottle = 'raki_bottle' diff --git a/src/brewing/cooking.py b/src/brewing/cooking.py new file mode 100644 index 0000000..d675b3e --- /dev/null +++ b/src/brewing/cooking.py @@ -0,0 +1,50 @@ +# heat sources +fire = 'fire' +eternal_flame = 'eternal_flame' +breathe_on_cauldron = 'breathe_on_cauldron' + + +def stir(potion, direction): + """Stirs the potion. + + Updates colour in the class instance. + + Parameters + ---------- + potion : Potion instance + The potion to be stirred. + direction : {'clockwise', 'anti-clockwise'} str + The direction in which the potions is to be stirred + """ + if direction == "clockwise": + potion.colour = "vomit-yellow" + print('NO!! Your potion turns vomit-yellow. Did you stir in the right direction?') + elif direction == "anti-clockwise": + potion.colour = "newt-green" + print('Your potion turns a lovely newt-green.') + else: + print("What are you doing to your potion??") + print("You need to stir, not distribute the contents on the floor!") + return + + +def simmer(potion, duration): + """Cooks the potion. + + Updates simmer_duration and cooked attributes in the class instance. + + Parameters + ---------- + potion : Potion instance + The potion to be cooked. + duration : int + How long to cook the potion for [hours]. + """ + potion.simmer_duration = duration + if duration < 2: + print('Are you sure you are cooking the potion enough? Your ingredients look a bit raw...') + elif duration > 5: + print('Oops, you have fallen asleep at your desk! Are you sure you want to simmer this long?') + else: + potion.cooked = True + return diff --git a/src/brewing/ingredients.py b/src/brewing/ingredients.py new file mode 100644 index 0000000..12511b6 --- /dev/null +++ b/src/brewing/ingredients.py @@ -0,0 +1,5 @@ +# ingredients +snake_skin = 'snake_skin' +fish_eyes = 'fish_eyes' +unicorn_hair = 'unicorn_hair' +tea_leaves = 'tea_leaves' diff --git a/src/brewing/inspection.py b/src/brewing/inspection.py new file mode 100644 index 0000000..412365f --- /dev/null +++ b/src/brewing/inspection.py @@ -0,0 +1,103 @@ +import time + + +def inspection_by_Snape(potion, target_potion='python_expert'): + """Checks if potion was brewed correctly. + + Prints narration of inspection process - read to see if potion passed inspection. + Snape checks container, heat_source, ingredients, and whether potion was cooked. + If something is wrong, function returns at that point. + + Parameters + ---------- + potion : obj + Instance of Potion (class from potion_class). + target_potion: str, optional + Name of potion to be checked by Snape. Currently possible potions are 'python expert', 'example_potion' + """ + + print('-------------------------------') + if not potion: + print(f'"There is no potion I can inspect!"') + print(f' (Tip: are you actually returning a proper potion and passing it to Snape?)') + return + + print(f'A sour looking Snape walks towards you to inspect your {target_potion} potion.') + print(f'"What do we have here, {potion.student_name}...?"') + print_delay_dots() + + # set variables for each potion that need to be checked + if target_potion == 'python_expert': + expected_container = 'pewter_cauldron' + expected_heat_source = 'fire' + elif target_potion == 'example_potion': + expected_container = 'old_kettle' + expected_heat_source = 'eternal_flame' + else: + print(f'"What is this, {potion.student_name}? This is not the name of an existing potion, check your spelling!"') + print(f' (Target potion was not recognised, please check your spelling.)') + return + + # check that correct setup was used + if potion.container == expected_container and potion.heat_source == expected_heat_source: + print(f'You have used the correct setup, Snape cannot complain - he looks even more sour.') + else: + print(f'Snape smirks and remarks "You have used the wrong cauldron or heat, {potion.student_name}!" \n' + f'With a flick of his wand he vanishes the potion. \n' + f'"I am taking 10 points from Ravenclaw, {potion.student_name}. Start again!"') + return + + print_delay_dots() + + # set variables for each potion that need to be checked + if target_potion == 'python_expert': + expected_ingredients = ['fish_eyes', 'tea_leaves', 'unicorn_hair'] + expected_cooked = True + expected_simmer_duration = 2 + elif target_potion == 'example_potion': + expected_ingredients = [] + expected_cooked = True + expected_simmer_duration = 5 + else: + print(f'"What is this, {potion.student_name}? This is not the name of an existing potion, check your spelling!"') + print(f' (Target potion was not recognised, please check your spelling.)') + return + + # check if all ingredients are there + if sorted(potion.ingredients) == expected_ingredients: + print(f'You have used the correct ingredients, Snape cannot complain - his face darkens.') + else: + print(f'Snape smirks and remarks "You have used the wrong ingredients, {potion.student_name}!" \n' + f'With a flick of his wand he vanishes the potion. \n' + f'"I am taking 10 points from Gryffindor, {potion.student_name}. Start again!"') + return + + print_delay_dots() + + # check that potion is cooked + if potion.cooked == expected_cooked and potion.simmer_duration == expected_simmer_duration: + print(f'The potion is cooked properly, Snape cannot complain - he is looking annyoyed now.') + else: + if potion.simmer_duration < expected_simmer_duration: + print(f'Snape smirks and remarks "Your potion is undercooked!" \n') + elif potion.simmer_duration > expected_simmer_duration: + print(f'Snape smirks and remarks "Your potion is overcooked!" \n') + print(f'With a flick of his wand he vanishes the potion. \n' + f'"I am taking 10 points from Hufflepuff, {potion.student_name}. Start again!"') + return + + print_delay_dots() + + print(f'Snape mutters "You got away this time, {potion.student_name}!", since there is nothing wrong with ' + f'your {target_potion} potion.') + print_delay_dots() + print(f'You pack your bags and leave as fast as you can to have a butterbeer at the lake!') + + return + + + +def print_delay_dots(dur=0.5, number=2): + for i in range(number): + time.sleep(dur) + print('.') diff --git a/src/brewing/potion_class.py b/src/brewing/potion_class.py new file mode 100644 index 0000000..ce8aa09 --- /dev/null +++ b/src/brewing/potion_class.py @@ -0,0 +1,46 @@ +class Potion: + + def __init__(self, student_name): + """This is a class for brewing potions.""" + self.colour = 'there-is-no-potion-so-the-potion-has-no-color' + self.cooked = False + self.container = None + self.heat_source = None + self.ingredients = [] + self.simmer_duration = -1 + self.student_name = student_name + + def setup(self, container=None, heat_source=None): + """Add a container and/or heat_source to the potion. + + Updates container and heat_source attributes in the class instance. + + Parameters + ---------- + container : str, optional + The name of the container to brew the potion in. + heat_source : str, optional + The name of the heat source used to cook the potions + """ + if container == None: + print(f'You have not specified a container - where do you think you will brew your potion?') + if heat_source == None: + print(f'You have not specified a heat source - how will you cook the potion?') + self.container = container + self.heat_source = heat_source + + def add_ingredients(self, ingredients=None): + """Add ingredients to the potion. + + Updates ingredients and colour attributes in the class instance. + + Parameters + ---------- + ingredients : array_like, optional + A list of ingredients (str) to add to the potion. + """ + if ingredients is None: + print(f'You have added no ingredients - have you spilt them on the floor again?') + else: + self.ingredients = ingredients + self.colour = "transparent"