Queer European MD passionate about IT
Ver código fonte

Update Mission882Solutions.ipynb

acstrahl 1 ano atrás
pai
commit
5cd5ae62af
1 arquivos alterados com 78 adições e 24 exclusões
  1. 78 24
      Mission882Solutions.ipynb

+ 78 - 24
Mission882Solutions.ipynb

@@ -17,6 +17,13 @@
     "- Foraging: Look for new seeds to expand your plant collection."
    ]
   },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "Let's start by importing the `random` library so we can include some unpredictability for elements in the game."
+   ]
+  },
   {
    "cell_type": "code",
    "execution_count": 1,
@@ -30,7 +37,20 @@
    "cell_type": "markdown",
    "metadata": {},
    "source": [
-    "### The Plant Class"
+    "## The Plant Class"
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "### Creating the Plant Class and Attributes\n",
+    "This class represents the base `Plant` in the garden, with attributes to define the plant's `name`, the amount of fruits or vegetables that can be harvested from a mature plant as `harvest_yield`, the growth stages this plant goes through, the current growth stage, and whether or not the plant is currently `harvestable`.\n",
+    "\n",
+    "### Adding Methods to the Plant Class\n",
+    "The Plant class has two methods: `grow` and `harvest`.\n",
+    "- `grow()`: updates the plant's `current_growth_stage` attribute if it is not already on the final growth stage. If the plant is ready for harvest, this method also updates the `harvestable` attribute to `True`.\n",
+    "- `harvest()`: Sets the `harvestable` attribute to `False` and returns the `harvest_yield`. The remainder of harvest-related actions will happen in the `Gardener` class"
    ]
   },
   {
@@ -68,7 +88,8 @@
    "cell_type": "markdown",
    "metadata": {},
    "source": [
-    "### Plant Subclasses"
+    "## Define Specific Plant Types\n",
+    "Plant subclasses will be the heart of the game, representing as many plants as we want to create subclasses for. Below, we can see that the `Tomato` subclass inherits everything from `Plant`, but `Lettuce` and `Carrot` override the inherited `growth_stages` attribute because these types of plant do not flower or fruit before they are \"harvest-ready.\""
    ]
   },
   {
@@ -96,7 +117,11 @@
    "cell_type": "markdown",
    "metadata": {},
    "source": [
-    "### Select Item Helper Function"
+    "## Selecting Inventory Items\n",
+    "This is a helper function that will go through a dictionary or list, display the keys or list items to the user as a numbered list, and then prompt the user to select an item by number. The function returns the corresponding item.\n",
+    "\n",
+    "### Continuous Prompting for Selecting Items\n",
+    "An important aspect of this helper function is its ability to continuously prompt users until they select valid input. This helps account for input errors and ensures that users provide valid selections."
    ]
   },
   {
@@ -139,7 +164,22 @@
    "cell_type": "markdown",
    "metadata": {},
    "source": [
-    "### The Gardener Class"
+    "## Defining the Gardener Class\n",
+    "The `Gardener` class models the player, who can plant, tend, harvest, and forage plants. The class has three attributes:\n",
+    "- `name` represents the gardener's name\n",
+    "- `planted_plants` is a list of any plants the gardener has currently planted\n",
+    "- `inventory` is a dictionary where the keys are the item names and the values are the quantity of the item.\n",
+    "\n",
+    "We have also created a `plant_dict` before the `__init__` method to connect each plant subclass to a string so that it is easier to instantiate new objects for each type.\n",
+    "\n",
+    "### Extending the Gardener Class Functionality\n",
+    "The `Gardener` class has four methods:\n",
+    "- `plant()`: This method allows the gardener to plant a plant from their inventory. It prompts the user to select a plant from their inventory, then adds the plant to the `planted_plants` list and removes it from the `inventory` dictionary.\n",
+    "- `tend()`: This method allows the gardener to tend to their plants. It prompts the user to select a plant from their planted plants, then calls the `grow()` method on that plant.\n",
+    "- `harvest()`: This method allows the gardener to harvest a plant. It prompts the user to select a plant from their planted plants, then calls the `harvest()` method on that plant. It then adds the harvest yield to the gardener's inventory.\n",
+    "\n",
+    "### Introducing Randomness: Foraging for Seeds\n",
+    "The `forage()` method allows the gardener to forage for seeds. It randomly selects a plant type from the `plant_dict` and adds it to the gardener's inventory."
    ]
   },
   {
@@ -205,7 +245,18 @@
    "cell_type": "markdown",
    "metadata": {},
    "source": [
-    "### Defining Game-Level Variables"
+    "## Setting Up the Main Game Loop\n",
+    "The main game loop will be the core of the game, where the player can choose what actions to take. The loop will continue until the player chooses to quit the game."
+   ]
+  },
+  {
+   "cell_type": "markdown",
+   "metadata": {},
+   "source": [
+    "### Setting Game-Level Variables\n",
+    "We will need to set up some variabels to keep track of contants in the game. `all_plant_types` is a list of all the plant types we have created. `valid_commands` is a list of all the commands the player can use. There is also a `gardener_name` variable that collects the player's name and a `gardener` variable that will be used to instantiate the `Gardener` class.\n",
+    "\n",
+    "There is also print statements that welcome the player to the game and explain the commands."
    ]
   },
   {
@@ -215,14 +266,23 @@
    "outputs": [],
    "source": [
     "all_plant_types = [\"tomato\", \"lettuce\", \"carrot\"]\n",
-    "valid_commands = [\"plant\", \"tend\", \"harvest\", \"forage\", \"help\", \"quit\"]"
+    "valid_commands = [\"plant\", \"tend\", \"harvest\", \"forage\", \"help\", \"quit\"]\n",
+    "\n",
+    "# Print welcome message\n",
+    "print(\"Welcome to the garden! You will act as a virtual gardener.\\nForage for new seeds, plant them, and then watch them grow!\\nStart by entering your name.\")\n",
+    "\n",
+    "# Create gardener\n",
+    "gardener_name = input(\"What is your name? \")\n",
+    "print(f\"Welcome, {gardener_name}! Let's get gardening!\\nType 'help' for a list of commands.\")\n",
+    "gardener = Gardener(gardener_name)"
    ]
   },
   {
    "cell_type": "markdown",
    "metadata": {},
    "source": [
-    "### Main Game Loop"
+    "### The Main Game Loop\n",
+    "The main game loop will continue until the player chooses to quit the game. The loop will prompt the player to enter a command, then call the appropriate method on the `Gardener` class."
    ]
   },
   {
@@ -240,7 +300,7 @@
      ]
     },
     {
-     "name": "stdin",
+     "name": "stdout",
      "output_type": "stream",
      "text": [
       "What is your name?  Jane Doe\n"
@@ -255,7 +315,7 @@
      ]
     },
     {
-     "name": "stdin",
+     "name": "stdout",
      "output_type": "stream",
      "text": [
       "What would you like to do?  help\n"
@@ -275,7 +335,7 @@
      ]
     },
     {
-     "name": "stdin",
+     "name": "stdout",
      "output_type": "stream",
      "text": [
       "What would you like to do?  forage\n"
@@ -289,7 +349,7 @@
      ]
     },
     {
-     "name": "stdin",
+     "name": "stdout",
      "output_type": "stream",
      "text": [
       "What would you like to do?  plant\n"
@@ -303,7 +363,7 @@
      ]
     },
     {
-     "name": "stdin",
+     "name": "stdout",
      "output_type": "stream",
      "text": [
       "Select an item:  1\n"
@@ -317,7 +377,7 @@
      ]
     },
     {
-     "name": "stdin",
+     "name": "stdout",
      "output_type": "stream",
      "text": [
       "What would you like to do?  tend\n"
@@ -331,7 +391,7 @@
      ]
     },
     {
-     "name": "stdin",
+     "name": "stdout",
      "output_type": "stream",
      "text": [
       "What would you like to do?  tend\n"
@@ -345,7 +405,7 @@
      ]
     },
     {
-     "name": "stdin",
+     "name": "stdout",
      "output_type": "stream",
      "text": [
       "What would you like to do?  tend\n"
@@ -359,7 +419,7 @@
      ]
     },
     {
-     "name": "stdin",
+     "name": "stdout",
      "output_type": "stream",
      "text": [
       "What would you like to do?  harvest\n"
@@ -373,7 +433,7 @@
      ]
     },
     {
-     "name": "stdin",
+     "name": "stdout",
      "output_type": "stream",
      "text": [
       "Select an item:  1\n"
@@ -387,7 +447,7 @@
      ]
     },
     {
-     "name": "stdin",
+     "name": "stdout",
      "output_type": "stream",
      "text": [
       "What would you like to do?  quit\n"
@@ -402,13 +462,7 @@
     }
    ],
    "source": [
-    "# Print welcome message\n",
-    "print(\"Welcome to the garden! You will act as a virtual gardener.\\nForage for new seeds, plant them, and then watch them grow!\\nStart by entering your name.\")\n",
     "\n",
-    "# Create gardener\n",
-    "gardener_name = input(\"What is your name? \")\n",
-    "print(f\"Welcome, {gardener_name}! Let's get gardening!\\nType 'help' for a list of commands.\")\n",
-    "gardener = Gardener(gardener_name)\n",
     "\n",
     "# Main game loop\n",
     "while True:\n",