→This assignment is due by Friday, June 09, 2023, 11:59 PM.←
→ As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must follow the course collaboration policy and be cited in the comment header block for the assignment.←
→ Do not forget to complete the following labs with this set: L4A,
L4B
←
→ Do not forget to complete zyBooks Assignment 4 for this set.←
· Instructions · Rubric · Best Practices · Submission Process · Submission Contents ·
Concepts
You are going to create magic bouncing balls to watch as they move around the screen.
Class Creation
For this assignment you must first create a class calledBubble
. The
Bubble
class needs to have the following private data members to store
information:
- a
CircleShape
which will be used to draw the Bubble - two
double
s to store the X and Y direction respectively the Bubble should move (call themxDir
andyDir
)
Be sure to have the necessary getters and setters for your private data
members and/or you may make non-default constructors as you deem necessary to
set initial values on your
Bubble
class.
Draw It!
In ourmain()
, before we get to the draw loop we want to make our
Bubble
object. We want only one instance to exist in memory. If we
made the object inside the draw loop, then every iteration of the draw loop a
new object would be created.
Next inside our draw loop, after we've cleared the window and before we display the window, we need to draw
the bubble. Add a public method to the Bubble
class called draw()
that accepts an
SFML RenderWindow
object by reference. The function then draws the CircleShape
member of the class.
At this point, run your program and you should see a white circle. Perfect! Let's continue.
Move It!
We need to add another public member function called updatePosition()
. This function needs to add the direction values
to the position of the CircleShape
.
When we create our
Bubble
object, we need to make sure its direction values are set to non-zero
values. Do this now, we suggest using values in the range of [0, 0.2]
for xDir & yDir
respectively. (Note: feel free to tweak these values up/down if it moves too slow/fast.)
Now in our draw loop, after we've checked the
events we will check the time. If the elapsed time has eclipsed 1/60th of a second, then call
updatePosition()
on the object.
Run your program. It should be moving now. Oh no! It went off the screen. Let's keep it in view.
Bop It!
The last part of the bubble is have it bounce around the window.
Recall that the position for a
CircleShape
corresponds to the upper left corner of a square enclosing the circle.
We need to check if any of the edges of our circle move outside the
window. We can check this by seeing if the position becomes less than
zero (to correspond to the left or top of our window) OR if the position
plus the diameter is greater than the width or height of our window (to
correspond to the right or bottom of our window). If any of these
conditions occur, then we simply need to reverse the corresponding
direction of our bubble to simulate a bounce. Once we've checked
all four sides, we're contained!
Modify Bubble::updatePosition()
so that it accepts
the window width and height as parameters. Now after moving the bubble,
check if the bubble went over a wall. If it did, move the bubble backwards
and then reverse the necessary direction.
We recommend to start with the right wall first, then bottom, then left, then top. Get them working one at a time and keep adding to your code.
Run the program and watch it stay within the window. Excellent.
Bubbles Bubbles Everywhere
We want to replace our single
Bubble
object with a
vector
of
Bubble
s. Before your draw loop, create a vector
of five bubbles initially. Give each
bubble a random starting position between 100
and 400
for X and Y and a
random direction for X and Y in the range [-0.1667, 0.1667]
. Additionally, give each Bubble
a random radius between 10 and 50. Lastly, give each Bubble a random color so we can tell them
apart.
Inside our draw loop, we now need to draw all the Bubbles in our vector. After our event handling, we'll then need to update the positions of all the Bubbles in our vector. You should now see five Bubbles bouncing around the window. Excellent. Let's have the user interact.
Pop-A-Bubble
When the user clicks the left mouse button, we want to create a new bubble positioned at the location where the user clicked. This new bubble should have the same random starting properties that our original bubbles did. After the user clicks the first time, we should see six bubbles moving around the window. A second click, seven bubbles. And so forth as the user continues to click.
We may get to the point where there are too many Bubbles on the screen. If the user presses the D key, then we want to delete the last bubble that was added to the window. Obviously if there are no Bubbles in the window, then pressing D should do nothing.
If the user starts your program, clicks twice, then presses D three times, we should be seeing four bubbles on the screen.
UI Design
As a final step to make the program more user friendly, if the user presses the Q or Escape key, automatically close the window.
Best Practices To Follow
· Code Style · Code Correctness · Code Structure · Dynamic Memory Management · Software Engineering Design Principles ·
Code Style
The following set of guidelines ensure all code in this class will be written in a similar and consistent manner, allowing any reader to understand the program's intent and contents.
- One clear and consistent coding style used (such as K&R, 1TBS, or Allman).
- Course naming scheme is followed for variable, function, class, and other identifiers. See the course style guide for more specifics.
- Code is self-documenting. Variables sensibly named, function names descriptive of their purpose.
Code Correctness
The following set of guidelines ensure all programs written in this class behave properly without side effects.
- Code compiles and links without any errors or warnings.
- Program runs without any run time errors. Exceptions are properly caught, user input is validated appropriately, and program exits successfully without error.
- Use
const
wherever possible:- If you declare a variable and that variable is never modified, that variable should be
const
. - If your function takes a parameter and does not modify that parameter, that parameter should be
const
. - If a member function does not modify the callee, that member function should be
const
. - If you are pointing at a value that does not change, the pointer should point at a constant value (e.g.
const T*
). - If the pointer itself is never modified, the pointer should be a constant pointer (e.g.
T* const
). - If the pointer itself is never modified AND the value pointed at does not change, the pointer should be a constant pointer AND the pointer should point at a constant value (e.g.
const T* const
).
- If you declare a variable and that variable is never modified, that variable should be
Code Structure
The following set of guidelines ensure all programs written in this class are done in an abstracted, modular, extendable, and flexible manner.
- Do not use global variables unless absolutely necessary. Instead, encapsulate them and design your interfaces effectively. If there is no way around using a global variable, be prepared to defend and justify its usage.
- Program flow uses structural blocks (conditionals/loops) effectively, appropriately, and efficiently.
- Keep your headers clean. Put the absolute minimum required in your headers for your interface to be used.
Anything that can go in a source file should. Do not
#include
any system headers in your .h files that are not absolutely required in that file specifically. Do not addusing namespace
in headers. - Use header guards correctly and appropriately.
- Place templated class and function definitions in a
*.hpp
file. - Place static class and function definitions in abstracted
*.h
and*.cpp
files. - Place each class and structure in their own files as appropriate based on their makeup.
Dynamic Memory Management
The following set of guidelines ensure all programs written in this class behave properly without side effects.
- Implement the Big-3 as appropriate.
- Do not leak memory. Every allocation using
new
needs to have a correspondingdelete
.
Software Engineering Design Principles
The following set of guidelines ensure all program components written in this class are done in an abstracted, modular, extendable, and flexible manner.
- Follow and apply the following design principles:
- Write Once, Use Many / Write Once, Read Many (WORM) / Don't Repeat Yourself (DRY): Use loops, functions, classes, and
const
as appropriate. - Encapsulate what varies: Use functions and classes as appropriate. Identify the aspects that vary and separate them from what stays the same.
- Favor composition over inheritance.
- Program to an interface, not an implementation & SOLID Principles: When using object-oriented inheritance & polymorphism, do the following:
- No variable should hold a reference to a concrete class.
- No class should derive from a concrete class.
- No method should override an implemented method from any of its base classes.
- Use appropriate inheritance access. Only expose necessary members to derived classes and/or publicly.
- Use
virtual
andoverride
as appropriate. Mark members asfinal
wherever possible and/or appropriate on derived classes.
- Write Once, Use Many / Write Once, Read Many (WORM) / Don't Repeat Yourself (DRY): Use loops, functions, classes, and
Grading Rubric
Your submission will be graded according to the following rubric.
Points | Requirement Description |
10 | All labs completed and submitted L4A, L4B |
+3 | L4B Extra Credit |
10 | Bubble class created, structured, and implemented correctly. Appropriate member fields and member functions specified. |
4 | Bubbles move on screen. |
4 | Bubbles bounce off each wall without getting stuck on the wall. |
4 | Bubbles can be added and deleted without error. |
4 | Bubbles added at mouse location. |
4 | Bubble properties randomized. |
3 | Window can be closed by user. |
5 | Best practices are followed:
|
0 | Submission structured appropriately. Submissions structured improperly will receive deductions. |
48 | Total Points |
→This assignment is due by Friday, June 09, 2023, 11:59 PM.←
→ As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must follow the course collaboration policy and be cited in the comment header block for the assignment.←
→ Do not forget to complete the following labs with this set: L4A,
L4B
←
→ Do not forget to complete zyBooks Assignment 4 for this set.←
Submission
Always, always, ALWAYS update the header comments at the top of your main.cpp file. And if you ever get stuck, remember that there is LOTS of help available.
It is critical that you follow these steps when submitting homework.
If you do not follow these instructions, your assignment will receive a major deduction. Why all the fuss? Because we have several hundred of these assignments to grade, and we use computer tools to automate as much of the process as possible. If you deviate from these instructions, our grading tools will not work.
Submission Instructions
Here are step-by-step instructions for submitting your homework properly:
-
Make sure you have the appropriate comment header block at the top of every source code file for this set. The header
block should include the following information at a minimum.
Be sure to fill in the appropriate information, including:/* CSCI 200: Assignment 4: A4 - SFML: Bubble Bobble
* * Author: XXXX (INSERT_NAME) * Resources used (Office Hours, Tutoring, Other Students, etc & in what capacity): * // list here any outside assistance you used/received while following the * // CS@Mines Collaboration Policy and the Mines Academic Code of Honor * * XXXXXXXX (MORE_COMPLETE_DESCRIPTION_HERE) */- Assignment number
- Assignment title
- Your name
- If you received any type of assistance (office hours - whose, tutoring - when), then list where/what/who gave you the assistance and describe the assistance received
- A description of the assignment task and what the code in this file accomplishes.
Additionally, update theMakefile
for A4 to generate a target executable namedA4
.
- File and folder names are extremely important in this process.
Please double-check carefully, to ensure things are named correctly.
- The top-level folder of your project must be named
Set4
- Inside
Set4
, create 3 sub-folders that are required for this Set. The name of each sub-folder is defined in that Set (e.g.L4A
,L4B
, andA4
). - Copy your files into the subdirectories of
Set4
(steps 2-3), zip thisSet4
folder (steps 4-5), and then submit the zipped file (steps 6-11) to Canvas. - For example, when you zip/submit
Set4
, there will be 3 sub-folders calledL4A
,L4B
, andA4
inside theSet4
folder, and each of these sub-folders will have the associated files.
- The top-level folder of your project must be named
- Using Windows Explorer (not to be confused with Internet Explorer), find the files
named
main.cpp, Makefile, *.h, *.hpp, *.cpp
.
STOP: Are you really sure you are viewing the correct assignment's folder? - Now, for A4, right click on
main.cpp, Makefile, *.h, *.hpp, *.cpp
to copy the files. Then, return to theSet4/A4
folder and right click to paste the files. In other words, put a copy of your homework'smain.cpp, Makefile, *.h, *.hpp, *.cpp
source code into theSet4/A4
folder.
Follow the same steps for each lab to put a copy of each lab's deliverable into theSet4/L4
folders. Do this process forSet4/L4A
(Warehouse.h, Warehouse.cpp
),Set4/L4B
(main.cpp, Makefile, data/*
).
STOP: Are you sure yourSet4
folder now has all your code to submit?
The structure of the submission is as follows:- Set4/
- A4/
- main.cpp
- Makefile
- *.h
- *.hpp
- *.cpp
- L4A/
- Warehouse.h
- Warehouse.cpp
- L4B/
- main.cpp
- Makefile
- data/*
- A4/
*
only if present and appropriate to the implementation.
- Set4/
- Now, right-click on the
"Set4"
folder.- In the pop-up menu that opens, move the mouse
"Send to..."
and expand the sub-menu. - In the sub-menu that opens, select
"Compressed (zipped) folder"
.
STOP: Are you really sure you are zipping aSet4
folder with sub-folders that each contain amain.cpp
file in it?
- In the pop-up menu that opens, move the mouse
- After the previous step, you should now see a
"Set4.zip"
file.
- Now visit the Canvas page for this course
and click the
"Assignments"
button in the sidebar.
- Find Set4, click on it, find the
"Submit Assignment"
area, and then click the"Choose File"
button.
- Find the
"Set4.zip"
file created earlier and click the"Open"
button.
STOP: Are you really sure you are selecting the right homework assignment? Are you double-sure?
- WAIT! There's one more super-important step. Click on the blue
"Submit Assignment"
button to submit your homework.
- No, really, make sure you click the
"Submit Assignment"
button to actually submit your homework. Clicking the"Choose File"
button in the previous step kind of makes it feel like you're done, but you must click the Submit button as well! And you must allow the file time to upload before you turn off your computer!
- Canvas should say "Submitted!". Click "Submission Details" and you can download the zip file you just submitted. In other words, verify you submitted what you think you submitted!
In summary, you must zip the "Set4"
folder
and only the "Set4"
folder, this zip folder must have several sub-folders, you must name all these folders correctly, you must submit the correct zip file for this
homework, and you must click the "Submit Assignment"
button. Not doing these steps is like bringing your
homework to class but forgetting to hand it in. No concessions will be made for
incorrectly submitted work. If you incorrectly submit your homework, we will not be able to
give you full credit. And that makes us unhappy.
→This assignment is due by Friday, June 09, 2023, 11:59 PM.←
→ As with all assignments, this must be an individual effort and cannot be pair programmed. Any debugging assistance must follow the course collaboration policy and be cited in the comment header block for the assignment.←
→ Do not forget to complete the following labs with this set: L4A,
L4B
←
→ Do not forget to complete zyBooks Assignment 4 for this set.←