Question: Python Assignment: Create a Farm populated with Animals held in Fields that are linked together as described below. Each class should be contained in its
Python Assignment:
Create a Farm populated with Animals held in Fields that are linked together as described below. Each class should be contained in its own file. Here are the features for each of the classes:
The Farm should hold a reference to the initial Field that the visitor begins in. The Farm should have a __str__() method that prints off the number of fields and what is in each one.
Fields should contain a description property that contains a descriptive phrase about the Field itself.
Fields should contain a list of Animals contained in it as well as a maximum number of Animals it can contain.
Fields should include an add_animal(a, n) method to add n Animals to it. If none of the existing animals dislikes those animals, they can be added up the maximum. If the Animals are not allowed in the Field, the method should return 0, otherwise, return the number of Animals added (to the maximum).
Fields should include a del_animal(a, n) method. If that number of Animals are present, the list of Animals should be decreased by that many, and number of of Animals deleted should be returned. If there are not that number of Animals present, delete as many as possible, and return that number.
Fields can hold 20 animals.
Fields should support the __str__() method that prints off the descriptive phrase, and then concatenates a reference to the number of specific Animals contained in it.
Fields should have a dictionary of linked_fields. The key should be the name of the direction command used to visit the field; the value should be the Field object it leads to. For example, "north":GrainField1 or "long grass":VelociraptorPen1. Remember that these are 1 way links, so you will need to set each each traversable direction.
Fields should have a move_to() method that returns the Field object that results from entering a particular direction. It should also print off the Field that is being visited.
Animals should have a dislikes property that is a list, containing the class names of any type of animal it won't live in a field with.
Animals should have a descriptive phrase property. The __str__() method should return something compatible with how you set up the Field.
Create 6 subclasses of Animals, each inheriting from the Animal class. Each should dislike at least one other animal, and one must dislike more than one other animal.
When the exercise2.py file is ran, it should create a Farm with 20 fields. It's up to you how they are linked, but all Fields should be visitable. Then fill the Fields with Animals. All Animal types should be used, and all Fields should hold more than one type of Animal.
It should print the details of the current field and then the options for movement. Create the interface for visiting the Farm by adding something like this to your exercise2.py:
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
