This assignment spans multiple labs. You will do just the initial design and write just a bare minimum of code for this lab. A more complete implementation will be required for the next lab. Both lab assignments will be done in teams of two (with teams of three as needed).
You have been asked to build a garden simulator for a botanist. In this simulator, bees visit flowers for food and flowers can drain energy. The garden will be shown from above with bees moving through the flower bed; there is no need to show how tall the flowers are. The intent is to deliver a system that the botanist could extend to support wider varieties of flowers and bees. This project will give you experience with identifying a problem domain and using this to build an implementation.
This section specifies the full requirements for your project. You will implement only a portion of these for this lab, but implement the rest for the next lab.
Your system must be a JavaFX application. The windows must be at most 700 pixels high and 1000 pixels wide. These limits ensure faculty can grade your solutions on school laptops at default resolutions.
You will implement various types of bees that move in specific patterns. Each bee moves forward one step for each “tick” of time. You can think of a tick as a particular number of seconds, but the precise duration does not matter. In your simulation, pressing the right arrow key moves the simulation forward one tick. It is required this be the right arrow key; having some students use other keys makes grading hard.
Bees are to move a programmer-specified distance each tick. Select a distance, such as 10 pixels, that allows bees to move reasonably quickly across the screen but not so fast that key behavior is unobservable.
Bees will land on simulated flowers whenever they pass within a certain
distance of the flower. Use Euclidean distance between the (approximate)
centers of objects to determine how close a bee is to a flower, and
assume a bee always lands on a flower if it the distance between the two
of them is less than a quarter of the bee’s image width. The goal
is that bees and flowers should interact only if they touch.
Bees have an energy level that decreases on each move. Bees should start at an energy level that would allow them to cross the screen multiple times if they lose one or two points on each move. If a bee reaches 0 energy, it dies and is removed from the screen. In the final implementation, all bees must eventually die.
The simulation will have a flower bed containing at least two types of flowers: one that provides a given number of units of energy (in the form of nectar) and one that drains energy from visitors. This behavior must change over time for at least one of the types of flowers; for example, you could have a type of flower ignore every other visitor or change how much nectar a flower gives. If a flower drains a bee of its energy, it will die.
Include at least two types of bees, with multiple instances of each.
Each bee must have a simple, distinct graphic along with a graphical and numerical display of its energy level. Display the energy level in two ways: as a number (which must be appropriately sized and colored to so as to be clearly visible) and as a health bar (a line showing how close the bee is to dying). The health information must be on the screen near to its bee and it must move with the bee. As in the checkers lab, all of the graphics related to a moving component can be maintained in the same class. The class can maintain each component individually or use a JavaFX Pane
class (such as VBox
in the provided sample code - see below). Talk to your instructor if you are unsure how to implement this.
When the program starts up, display 10 flowers and 5 bees. Provide a way for the user to adjust the number of bees and flowers in the garden so they can experiment with different population mixes. When there are very few flowers relative to the bees, the bees should die quickly. When there are many flowers, the bees should live a long time. It is expected that there would be support for up to dozens of bees and dozens of flowers of different types.
Flowers must also have simple, distinct graphics. In the cases of flowers that change their behavior over time, provide some type of graphic to indicate the status. It could be a simple +/- symbol, a countdown timer, or some other indicator showing the flower’s status. Do not include a health bar for flowers since they do not die.
A collection of JPEG images is being provided; you can use these for your bees and flowers or you can provide your own. In any case, you must have a window (or a part of a window) that has a legend showing which behaviors go with which flower and bee graphics. We need this for grading.
Your solution must include at least one interface or abstract class that the team writes.
You are not required to apply any design patterns, but you can if you wish. Be cautious, however; adding a design pattern involves more code, and this lab already has a number of complex elements. If you add a pattern, make sure you have at least one class that refers to that pattern; for example, FlowerBehavior or BeeMoveStrategy.
The above requirements give some flexibility on how bees and flowers behave. You can implement alternatives, but they must have behaviors that are at least as complex as the behavior described here. For example, the random movement bee tracks the target flower so that the flower does not change until the bee arrives. Do not include a “user-guided” bee; the goal is to encapsulate how different types of bees move, not to create a search-and-destroy game.
Each group member is expected to complete a fair share of the work in both labs. Each group member needs to check in interfaces to their classes early in the project, and each must complete an initial version of their portion before the next lab session. Failing to complete your portion will make it difficult for us to assign you to groups in future labs, making it difficult for you to satisfy course outcomes. An important part of this is to push your work to the shared git repository on a regular basis. Do not wait until the due date to start committing and pushing your work!
Document each file with who wrote that file. That person “owns” the file; others should not change it, with the possible exception of the JavaFX controller class.
Assuming all team members are contributing, all team members will receive the same grade on the lab. This means it is important that all members review the work to make sure all requirements are satisfied. Instructors do reserve the right to assign different grades to each member of a team when necessary.
The distributed code uses the package name garden
and has the start class
Main.java
. Do not change this. In addition, do not change the
locations of the .jpg
files; these locations must be consistent for grading.
As discussed above, you do not have to implement the full set of requirements for this lab. Instead, submit the following:
src
and .idea
folders but not .idea/workspace.xml
or .class
files. Be sure you have the standard, global gitignore file on your machine. If everything is checked in correctly, your instructor and teammate(s) will be able to open the project in IntelliJ without setting any additional configuration. Ask if you need help!The final, more complete implementation will be due as next week’s lab.
garden_jpgs.zip
: Images you can use for your flowers and bees.
bee_simulator.zip
: sample code illustrating placing an image on a panel and using arrow keys to move it around. In most cases, this is the code already given to you in the starter repository.
Your solution will differ from this in many ways, but key ones include capturing the location in domain level objects (rather than having “free floating” variables like beeXLocation
) and you will use the arrow key to move forward in the simulation rather than direct objects.