This assignment spans two 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.
You have been asked to build a simple 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 that a botanist could start with this code and build a simulator that allows mixing different types of flowers and bees. The 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. Read through these so you have a full picture of the project
Your system must be a JavaFX application.
Design all windows so they are at most 700 pixels high and 1000 pixels wide. This is important so we can grade your solutions on school laptops using the default resolution.
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 it will not matter what the precise number is. 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 another key makes the assignment too hard to grade.
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 without having to press the key a ridiculous number of times.
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 the width of the bee’s image. 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. However, do not allow bees to go too far before reaching zero points (death for the bee); bees are not immortal.
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.
Include at least two types of bees, with multiple instances of each.
One of the bees must pick a flower at random and then move towards that flower. The bee will then move towards the flower until it reaches it, then a new flower is picked. Do not implement this as a bee that just moves randomly; no bee would move in that way. The logic of having a target flower that changes is important to the assignment. Allow this bee to encounter flowers along the way to the target (as described in the distance calculation above).
Another bee must have a different pattern such as flying straight to a flower, moving back and forth across the screen (covering the full garden), a spiral, or large zig zags. Again, random movement is not interesting; follow some reasonable pattern. This bee must not target a specific flower; it must simply follow a pattern.
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.
A collection of JPEG images is being provided; you can use these for your bees and flowers or you can provide your own.
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.
On your primary window (scene), include a box that displays a legend showing the types of flowers and bees (graphically) and briefly explaining the behavior of each. This is needed so instructors can verify the behavior.
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 in this writeup. 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!
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 place all .jpg
files at the top folder as shown with bee-1.jpg
. Yes, there is value in
using folders for these types of files, but this often results in code not
building for instructors. Do not change the project structure dramatically
so instructors can grade this assignment.
As discussed above, you do not have to implement the full set of requirements for this lab. Instead, submit the following:
A single PDF that includes all of the following:
An initial version of the system that builds using IntelliJ in a Git repository. At a minimum, your initial version must create a JavaFX form and display a bee or flower. Be sure to check in the full project, including both the 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!
Be sure any code you intend your instructor to grade is on the main branch. Using branches on a small project like this is not very useful.
Your instructor will publish additional submission requirements.
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. 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. But this code contains lots of elements that will be useful in your solution.