SE 2811, Lab 3:
Designing a Garden
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. This 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.
Requirements
In addition to the above requirements,
- Your system must be a JavaFX application.
- Design all windows so they are 700 pixels high or less and 900 pixels
wide or less. 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 others 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. If your solution is annoying to test, it will be annoying to grade!
- 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 do live a
reasonable amount of time, long enough to see them run into other objects
but not so long that it is difficult to verify that bees can die from
starvation.
- Allow the user to adjust the number of flowers in the garden so it is
straightforward to test what happens when there are very few flowers (the
bees should die quickly) and there are very many flowers (the bees should
live a long time).
- Bees also lose energy when they run into each other. The
specifics of this are up to the team, but at least one bee needs to lose
energy when there is a collision.
- 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
diagonals. 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. Note you
can use JavaFX
Pane
classes (such
as VBox
in the provided sample code - see below) to put
a status indicator under a bee. 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. 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 nector to another bee, add
a count-down 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.
Process and design constraints
- Your solution must include at least one interface or abstract class
that the team writes.
- You are not required to apply any design patterns.
- Do not use
pow
to square numbers; it is very inefficient for
this because it uses natural logs. Simply multiply instead. Note
that Point2D
has a distance method, and this class might
be useful for other reasons as well.
- 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 implement a "user-guided" bee as part of this lab; 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.
Lab 3 Submission
For lab 3, submit
- A domain-level class diagram, drawn using EA, as defined by
the domain-level UML Standards
document. Be sure to include either attributes or methods (or both) for
every class, and be sure that all classes are associated with at least
one other. Review a draft of diagram with your instructor by
the end of the lab period to ensure you have the correct elements and structure.
- Warning: JavaFX elements such as controllers and menus
are not domain classes! Domain classes capture objects that
(say) a botanist would know about.
- A detailed list of bee requirements, describing the behavior of
each class of bees. Document this behavior as a collection of user
stories, where the user is a botanist or a beekeeper attempting to observe the simulated
behavior. Remember the story format: As a ______, I would like to
_____ because _____. The first blank is a type of user, the second
is an action, and the third is a reason. For example, "As a beekeeper, I
would like to know how long all of the bees survive so I know I can
ensure we plant enough flowers for the number of bees we intend to keep."
The reason is important because understanding goals is important to
ensure you meant the user's need.
- A (single) PDF listing all domain classes, including the
responsibility (or responsibilities) for each, and documenting which
(single) team member will implement that class. The quality of your
responsibilities will be an important part of your grade. These should be
written using the pattern "The XXX class is responsible to...."
You can use tools such as MSWord and Google Docs to create the PDF.
- An initial version of the system that builds using IntelliJ in a
Git repository. Your
instructor will give directions on creating the
repository. At a minimum, your system must create a JavaFX
form and display a bee or flower. Note the package name must reflect the
assignment; using "bee_simulator" does not make sense because this
assignment does more than simulate bees. Be sure to check in the
full project, including both the
src
and .idea
folders but not .idea/workspace.xml
or .class
files.
Your instructor and teammate(s) should be able to open the project in IntelliJ
from your repository. Ask if you need help!
- Be sure any code you intend your instructor to grade is on the
"main" (or master) branch. There is no value in using git branches on a
short assignment such as this one.
The full implementation will be due as lab 4.
Support Files
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.