For labs 3 and 4, you will work in groups to develop a flower bed
simulator. In this simulator, bees visit flowers for food bees attack and
slow down other bees, 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 high the flowers are. This simulation might be used by a
botanist to experiment with different mixes of bees and flowers. This lab
will give you experience with applying the basic object-oriented design
principles discussed in class (using the noun/verb method to identify
domain classes and operations and documenting responsibilities) to a new
problem.
In addition to the above requirements,
Your system must be a JavaFX application.
Design all windows so they are at most 600 pixels high and 800 pixels wide. This is important so we can grade your solutions on school laptops using the default resolution.
Time advances in the application by pressing the right arrow key; each keypress is to move the simulation forward one “tick” of time. You can implement other keys to do the same thing if you find it convenient, but you must implement the right arrow key. Consistency is important for grading. If you are not sure how to do this, ask for help!
Bees are to move a programmer-specified distance each tick. Select a distance, like 10 pixels, that allows bees to move reasonably quickly across the screen without having to press the key a ridiculous number of times.
Use Euclidean distance between the (approximate) centers of objects to determine when a bee hits a flower
or other bee.
Each bee is to have an energy level. The bee loses one or more energy points on each tick and dies if the energy level reaches zero. Balance the energy levels and amounts lost on each tick so that bees live indefinitely when there are a sufficient number of flowers but die from starvation when there are not enough flowers.
Allow the user to adjust the number of bees and flowers in the garden so it is straightforward to test 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.
The flower bed must include 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. You can experiment with different forms of this, but the behavior of both the one that provides energy and the one that drains it must change from visitor to visitor. For example, a flower could drain energy from one bee and give it to another, or a nectar-producing flower could take several cycles to regenerate its energy. You will need multiple instances of each type of flower. Do ensure that flowers that drain energy do have an impact (leading to shorter lives for bees unless they get that energy back from other flowers), but ensure that impact is not so great as to result in simply killing any bee that visits it.
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.
Another bee must have a different pattern such as flying in straight lines back and forth (covering the full garden) or moving in circles. Again, random movement is not interesting; follow some reasonable 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.
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. Like the bees, each must have an indicator of its status next to it. For example, if the flower must recharge before dispensing nectar to another bee, add a countdown indicator showing how long until the flower is recharged.
On your primary window (scene), include a box that displays a key 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.
Note that 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, note that 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. Each group member needs to check in interfaces to his or her classes early in the project, and each must complete an initial version of his or her 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.
Unless there is a documented issue, 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.
Be careful with names. The distributed, sample JavaFX code has the name BeeSimulator
; this name makes sense for that code, but not for your submission to this lab since you are implementing a full garden, not just a bee.
For lab 3, submit
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” (or master) branch.
Your instructor will publish additional submission requirements.
The full implementation will be due as lab 4.
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.