1 Introduction
Garden Gnome is a single-player simulator game where a player must take care of house plants for 15 days. The player must keep more than half their plants alive for this duration. Items are be rewarded throughout the days to assist the player, and are applied when needed. See Figure 1 for a sample game.
In Assignment 2, you will create an extensible object-oriented implementation of Garden Gnome which employs a text-based interface.
You are required to implement a collection of classes and methods as specified in Section 5 of this document. Your program’s output must match the expected output exactly; minor differences in output (such as white-space or casing) will cause tests to fail, resulting in zero marks for that test. Any changes to this document will be listed in a changelog at the end of the document.
Figure 1: A snippet from a functional game of Garden Gnome. Each room in the house is separated by walls (represented by #) and each room can have four plants eac represented by a single character.
2 Getting Started
Download a2.zip from Blackboard — this archive contains the necessary files to start this assignment.
Once extracted, the a2.zip archive will provide the following files/directories:
a2.py
The game engine. This is the only file you submit and modify. Do not make changes to any other files.
a2_support.py
Provided classes implementing functionality to render the text interface.
constants.py
Constants you may find helpful when writing your assignment. houses
A folder containing several text files of playable houses.
example_simulations
A folder containing example output from running the completed assignment.
3 Gameplay
The objective is to have more than half the plants alive at day 15. For example, if the game started with ten plants, six plants are required to be alive at day 15 to win the game.
Gameplay occurs according to the following steps:
- Prompt user with “Enter house file: ”. Presume the file exists at the location
given relative to where a2.py is saved. For instance, houses/house1.txt.
- Display house and prompt user with “Enter a move: ”. The list of valid moves
are given below. Assume invalid moves may be entered, but ignore them.
- Progress to next day when n is entered.
- Break on lose or win, otherwise go to step 2.
3
Figure 2: All available moves.
3.1 Room and position system
The room and position system used for the simulator is depicted in Figure 4. For example in the “Balcony” room there are always four possible positions to place plants, 0, 1, 2, and 3, from left to right, each room has 4 columns at different elevations. Positions are represented as a single int. Note that this is just an example; you must not assume that you will always have a Balcony room.
4 Class overview and relationships
• Hollow-arrowheads indicate inheritance (i.e. the “is-a” relationship).
• Dotted arrows indicates composition (i.e. the “has-a” relationship). An arrow arrow marked with −→ denotes that each instance of the class at the base of
5 Implementation
5.1 Model classes
This section outlines the model classes you must implement, along with their required methods. The classes are laid out in the order in which it is recommended you attempt them (with some exceptions that are discussed in the relevant sections). It is strongly recommended that you ensure a class is working via testing the implementation yourself before moving on to another class (particularly if that class is a superclass of the next class you will attempt).
Entity
(abstract class)
Abstract base class for any entity. Provides base functionality for all entities in the game.
get_class_name(self) -> str (method) Return the class name of this entity’s class.
get_id(self) -> str (method) Return the single character id of this entity’s class. See constants.py for the ID
value of all tiles and entities.
__str__(self) -> str (method) Return the string representation for this Entity.
__repr__(self) -> str (method) Return the text that would be required to make a new instance of this class that
Plant (class) Inherits from Entity
Plant is an Entity that is planted by the user. A plant has water and health points 7
(HP) which start at 10, age starting at 0, and no repellent. A plant’s drink rate and sun level are determined by the name of the plant See constants.py for the drink rate and sun level of all plants.
__init__(self, name: str) -> None (method) Setup the plant with a given plant name. See constants.py for the plant names.
Item (abstract class)
Inherits from Entity
Abstract subclass of Entity which provides base functionality for all items in the game.
apply(self, plant: Plant) -> None (abstract method) Applies the items effect, if any, to the given plant. Raise NotImplementedError.
Model (class)
This is the model class that the controller uses to understand and mutate the house state. The model keeps track of multiple Room instances and an inventory. The Model class must provide the interface through which the controller can request information about the house state, and request changes to the house state.
__init__(self, house_file: str) -> None (method)
GardenSim (class)
GardenSim is the controller class, which should maintain instances of the model and view, collect user input and facilitate communication between the model and view. The methods you must implement are outlined below, but you are strongly
encouraged to implement your own helper methods where possible.
__init__(self, house_file: str, view: View)
-> None (method)
6 Assessment and Marking Criteria
This assignment assesses course learning objectives:
- applyprogramconstructssuchasvariables,selection,iterationandsub-routines,
- apply basic object-oriented concepts such as classes, instances and methods,
- read and analyse code written by others,
- analyse a problem and design an algorithmic solution to the problem,
- read and analyse a design and be able to translate the design into a working program, and
- apply techniques for testing and debugging.
6.1 Marking Breakdown
Your total grade for this assessment piece will be a combination of your functionality and style marks. For this assignment, functionality and style have equal weighting, meaning you should be devoting at least as much time towards proper styling of your code as you do trying to make it functional.
6.2 Functionality Marking
Your program’s functionality will be marked out of a total of 50 marks. As in Assignment 1, your assignment will be put through a series of tests and your functionality mark will be proportional to the number of tests you pass. You will be given a subset
of the functionality tests before the due date for the assignment. You may receive partial marks within each class for partially working methods, or for implementing only a few classes.
6.3 Style Marking
The style of your assignment will be assessed by a tutor. Style will be marked according to the style rubric provided with the assignment. The style mark will also be out of 50.
The key consideration in marking your code style is whether the code is easy to understand. There are several aspects of code style that contribute to how easy it is to understand code. In this assignment, your code style will be assessed against the following criteria.
6.3.1 Readability
Program Structure Layout of code makes it easier to read and follow its logic.
This includes using whitespace to highlight blocks of logic. 26
Descriptive Identifier Names Variable, constant, function, class and method names clearly describe what they represent in the program’s logic. Do not use what
is called the Hungarian Notation for identifiers.
6.3.4 Algorithmic Logic
Single Instance of Logic Blocks of code should not be duplicated in your program. Any code that needs to be used multiple times should be implemented as a method or function.
Variable Scope Variables should be declared locally in the method or function in which they are needed. Attributes should be declared clearly within the __init__ method. Class variables are avoided, except where they simplify program logic. Global variables should not be used.