# **Fruit Ninja**
:::danger
<b>Assignment Release: Tuesday, October 1st, 2024
Early Handin: October 6th, 2024
Regular Handin: October 8th, 2024
Late Handin: October 10th, 2024</b>
:::
Watch the demo [here](https://youtu.be/HKs-krfclSs)!
# Assignment Roadmap
:::info
[Silly Premise](#Silly-Premise)
[Collaboration Policy Reminder](#Collaboration-Policy-Reminder)
[New Concepts Covered](#New-Concepts-Covered)
[Helpful Resources](#Helpful-Resources)
[Installing Stencil Code](#Installing-Stencil-Code)
[Grading](#Grading)
### **[FUNCTIONALITY](#Functionality)**
[Coding Incrementally](#Coding-Incrementally)
[Compiling and Running Your Code](#Compiling-and-Running-Your-Code)
[Suggested Order for Incremental Coding](#Suggested-Order-for-Incremental-Coding)
[Saving Your Work on GitHub](#Saving-Your-Work-on-GitHub)
[Minimum Functionality Requirements](#Minimum-Functionality-Requirements)
[Full Functionality Requirements](#Full-Functionality-Requirements)
### **[IMPLEMENTATION](#Implementation)**
[Support Code](#Support-Code)
[Switch Statements](#Switch-Statements)
[Constants](#Constants)
### **[DESIGN](#Design)**
[Design Questions](#Design-Questions)
### **[STYLE](#Style)**
### **[HANDING IN](#Handing-In)**
[README](#README)
[Handin](#Handin)
:::
## Silly Premise
Sokka wants to prove himself as a swordfighter worthy of wielding a legendary sword, forged from meteorite ore. His master, Piando, says he's not ready. To Sokka's dismay, Piando starts throwing fruits and bombs at him as a "training excercise." Help Sokka code a magic sword that draws upon the elemental energies of the fruits to change color! That will really impress Piando!
Reference: Avatar the Last Airbender, Nickelodeon

## Collaboration Policy Reminder
If you ever have questions about [the collaboration policy](https://docs.google.com/document/d/10rbbd0Y6s1JUzPe8VmoWcL_Mz26XczX-i7p2LUFa9vc/edit?usp=sharing), refer to the collaboration policy or ask a TA!

## New Concepts Covered
* Polymorphism
* Interfaces
* Inheritance
* If Statements
* Switch Statements
## Helpful Resources
* This handout!
* [FruitNinja JavaDocs](https://cs.brown.edu/courses/csci0150/javadocs/cs15/prj/fruitNinjaSupport/package-summary.html)
* [FruitNinja JavaDocs Diagnostic](https://docs.google.com/forms/d/1XMyQdz3qKmckTATTGHPlz0U6Z6Y-_ehiJ5ko5QLIMTA/edit)
* [FruitNinja Help Slides](https://docs.google.com/presentation/d/1EJSTW7kfP6b-QaWvsQIoa80l4AeFYEdcc4bFP1W-ruQ/edit#slide=id.p3)
* [FruitNinja Demo](https://youtu.be/HKs-krfclSs)
* [Interfaces Lecture](https://cs.brown.edu/courses/cs015/lecture/pdf/CS15.Lecture_6_Interfaces_and_Polymorphism.9.24.24.pdf), [Inheritance Lecture](https://cs.brown.edu/courses/cs015/lecture/pdf/CS15.Lecture_7_Inheritance_and_Polymorphism.9.26.24.pdf), and [Math & Making Decisions Lecture](https://cs.brown.edu/courses/cs015/lecture/pdf/CS15.Lecture_8_Math_and_Making_Decisions.10.1.24.pdf)
* [Polymorphism Conceptual Review Video](https://www.youtube.com/watch?v=hIPZZWe8nsE)
* [Style Guide](https://docs.google.com/document/d/1olSJxbrhuIystA_kVbmKu4V8JfN7HE-eDzM5blkoeFw/edit#heading=h.b1nvuu1nggmv), [GitHub Guide](https://docs.google.com/document/d/1tSxfUIn-Ro6Pr1X4y21BbYKdsiK-nlWW3pGDfyh7SQ8/edit), [Understanding Support Code Handout](https://docs.google.com/document/d/1mWR-huHi6PqizbFlghQrRXGnyJRZaClu_pkY7PFQYqY/edit#heading=h.ac49hi2p43ww), [README Guide](https://docs.google.com/document/d/1QJPit-_8ZC3r4l_f5F3ydMK34-NchBYgwtm0c21iwsU/edit), and [Class & Inheritance/Interface Diagrams Guide](https://docs.google.com/document/d/1LZV1M75gozJuU7jouTmusjw2B4fjLPOCSh9feQ3sDXM/edit#heading=h.n64vzvb7650b)
* [Conceptual TA Hours, Debugging TA Hours](https://cs.brown.edu/courses/cs015/) (starting 10/1), and [Ed](https://edstem.org/us/courses/63887/discussion/)
## Installing Stencil Code
Click **[here](https://classroom.github.com/a/3jty4uPe)** to get the stencil from GitHub — refer to the [CS15 GitHub Guide](https://docs.google.com/document/d/1tSxfUIn-Ro6Pr1X4y21BbYKdsiK-nlWW3pGDfyh7SQ8/edit) for help with GitHub and GitHub Classroom. Once you have the URL of your personal GitHub repository, open the IntelliJ terminal. Move into your local **`src/`** folder, then use the command **`git clone <URL>`**
Once you’ve cloned your personal repository from GitHub, you’ll need to rename your local folder from **`fruitninja-<yourGitHubLogin>`** to just **`fruitninja`**. You will have issues running your code until you make the change.
## Grading
The grade for this assignment will be determined by [functionality](#Functionality) (50%), [design](#Design) (38%), [style](#Style) (12%). See each of those sections for more details of this grading breakdown. An ‘A’ project would meet mostly all [full functionality](#Full-Functionality-Requirements) requirements with good design and style.
---
# Functionality
Before you read this section, make sure you watch the [demo](https://youtu.be/HKs-krfclSs)! Doing so will make understanding the assignment much easier. Your Fruit Ninja will look like this when you are done.
Your assignment is to write a program that displays the CS15 version of a game of FruitNinja with a blade, bombs and four types of fruit.
* You should have a blade and it should have a name to go along with your fun and cool project.
* Apples, lemons, pears, peaches and bombs should randomly be launched up as the game progresses. These fruits should be washed and ripened when they are launched.
* You should be able to chop all of these with your blade.
* When a fruit is chopped, the score should increase according to the fruit that you chopped. (Each type of fruit should have a different score). There should also be a splash after it has been chopped.
* When a fruit is chopped, the blade should change visually based on what fruit was chopped.
* When an apple is chopped, the blade should become mirrored horizontally
* When a lemon is chopped, the blade should become glittery
* When a pear is chopped the blade should turn green
* When a peach is chopped, the blade should get a wooden handle.
* When a bomb is chopped, it should explode and the game should end. Chopping a bomb should not increase the score.
* When a bomb is chopped, the blade should return to the original blade with no visual modifications
* You should keep track of the score.
To do this, you need to initialize the **`CS15ScoreController`** and have each fruit or bomb keep track of how many points it should be worth when chopped, then passing that value into the appropriate method. You will then use the score controller to update the score throughout the game.
## Coding Incrementally
After you’ve watched the demo, *++thoroughly read this handout and the [Javadocs](https://cs.brown.edu/courses/csci0150/javadocs/cs15/prj/fruitNinjaSupport/package-summary.html) in full++* to make sure you understand the project design. Then, *++complete the [Fruit Ninja JavaDocs Diagnostic](https://docs.google.com/forms/d/1XMyQdz3qKmckTATTGHPlz0U6Z6Y-_ehiJ5ko5QLIMTA/edit)++* to assess your understanding of the support and stencil classes you’ll need to use for this project. Once you’re ready, start coding! It is important to code **incrementally**, meaning you completely accomplish one logical task before moving on to the next one.
### Compiling and Running Your Code
Most importantly, incremental coding means that you **run your code after each step** to ensure it’s working as you want it to! To run the program you must first **`cd`** (change directory) into **`src/fruitninja`** directory, then compile as you normally would by running **`javac *.java`** in your shell. Then **`cd ..`** and run your program by typing **`java fruitninja.App`**
### Suggested Order for Incremental Coding
**Step 1.** Run the stencil code and **complete the [Fruit Ninja JavaDocs Diagnostic](https://docs.google.com/forms/d/1XMyQdz3qKmckTATTGHPlz0U6Z6Y-_ehiJ5ko5QLIMTA/edit)**
**Step 2.** Start by making the **`Game`** and **`CS15ScoreController`** show up in the frame. **We highly recommend getting these to show up on the screen before doing anything else.**
**Step 3.** Set up the fruit and generate them in launchItem(). Make sure the fruits are washed and ripened when they are launched.
* Note: **`launchItem()`** will only generate your fruits *offscreen*. To see them move onto and across the screen, make sure to update their position in the **`updateChoppable`** method. You might have to change the parameter type of **`updateChoppable`** to do this!
* Be sure to start the game (check out **`CS15FruitNinjaGame`** in the Javadocs) or else **`updateChoppable`** won’t be called!
**Step 4.** Get bombs to appear as well.
* What could the parameter type of `updateChoppable` become to handle both fruits and bombs?
**Step 5.** Get the blade to appear on the screen and implement the fruit and bombs’ chopping behavior in the **`updateChoppable`** method.
* You’ll want to check if the blade intersects the fruit or bomb that’s passed in. What should happen when a fruit is chopped vs. when a bomb is chopped?
**Step 6.** Increment the score each time a Fruit is chopped.
### Saving Your Work on GitHub
Refer to the [CS15 GitHub Guide](https://docs.google.com/document/d/1tSxfUIn-Ro6Pr1X4y21BbYKdsiK-nlWW3pGDfyh7SQ8/edit) for more detailed instructions on how to save snapshots of your work to GitHub. We recommend doing this around once an hour to make sure you’re maintaining a copy of your code. Here is a summary:
1. Move into the **`fruitninja`** directory
2. **`git add -A`**
3. <b>`git commit -m “<some descriptive message>”`</b>
4. <b>`git push`</b>
5. Repeat!
## *Minimum Functionality Requirements*
MF Policy Summary: *In order to pass CS15, you will have to meet minimum functionality requirements for all projects. If you don’t meet them the first time around, you may hand the project in again until you succeed, but you will keep your original grade. MF requirements are not the same as the requirements for full credit on the project. You should attempt the full requirements on every project to keep pace with the course material. An ‘A’ project would meet all of the requirements enumerated in the assignment specification section of the handout and have good design and code style.*
To meet minimum functionality for FruitNinja:
* The game must have a blade that the user can move
* Bombs and at least one type of fruit must launch into the game
* Bombs and at least one type of fruit must react to being “chopped” when the blade contacts them
## Full Functionality Requirements
Beyond the minimum functionality requirements, the rest of the functionality grade will depend on the following criteria:
* Bombs and all four types of fruit launch into the game
* The bombs and all four types of fruit should react to being “chopped” when the blade contacts them (exploding for bombs, splashing and becoming transparent for fruit)
* The blade should change visually each time a fruit is chopped (mirrored for apple, glitter for lemon, green for pear, wooden for peach)
* The game’s score should be updated each time a fruit is chopped. Each type of fruit should have a unique score value
* No minor bugs
---
# Implementation
## Support Code and Javadocs
In Tic Tac Toe, we provided you with two support code interfaces, and you had to write classes from scratch that implemented those interfaces. For Fruit Ninja, we’re providing you with three abstract classes, each of which should have subclasses that inherit from them. We’ve provided you with a **`Game`** class that inherits from **`CS15FruitNinjaGame`** as an example. You are responsible for writing classes that inherit from the other two abstract support classes.
Check out which support classes are abstract to get a feel for the kinds of classes you’ll need to write on your own. *Remember that you cannot directly instantiate an abstract class but you can instantiate a concrete subclass of an abstract class!*
You can read the Javadocs in full [here](https://cs.brown.edu/courses/csci0150/javadocs/cs15/prj/fruitNinjaSupport/package-summary.html). **The Javadocs contain information that you cannot find in this handout — you will have much trouble implementing this project if you haven’t thoroughly read the Javadocs. When in doubt, first check the handout, then the Javadocs.** Make sure to complete the [Fruit Ninja JavaDocs Diagnostic](https://docs.google.com/forms/d/1XMyQdz3qKmckTATTGHPlz0U6Z6Y-_ehiJ5ko5QLIMTA/edit) to assess your understanding of all the support and stencil classes involved in this project. You should be able to answer all questions correctly prior to beginning to code.
## Switch Statements
Be sure to review the lecture slides on switch statements in the Math and Making Decisions lecture! You will need to use a switch statement to randomly launch fruit and bombs onto the screen during your game of FruitNinja. Remember, the objects appearing on the screen need to be random and you might find the **`Math.random()`** method in the Javadocs helpful for generating a random number!
## Constants
The support code’s [Constants](https://cs.brown.edu/courses/csci0150/javadocs/cs15/prj/fruitNinjaSupport/Constants.html) class contains static variables you’ll likely find useful in this project. For example, to get the filepath to the Apple image, you can use the static String variable **`APPLE_PATH`**. Remember that static variables and methods are accessed with the name of its class followed by its name. In this case, **`Constants.APPLE_PATH`**.
---
# Design
## Design Questions
Here are some design questions to keep in mind while planning your design for the project:
* What do your fruits have in common with each other? What do your fruits **not** have in common with each other?
* What common actions happen to fruit and bombs and how should they react? (*Hint:* Maybe it’s time to write a short interface? Fruits and Bombs are both **`Choppable`** but different things should happen when they move and are chopped...)
* In general, how do we model *capabilities* and properties in Object-Oriented Programming?
Make sure you are not writing repetitive code! Your objects should be generic enough to make adding a different fruit very easy. You might have to alter parts of the program’s design and make modifications to code you’ve already written as you work. However, the more time you spend on the design phase ***before you begin coding***, the fewer changes you will have to make later.
Like Pong and Tic Tac Toe, you’ll need to create a ++class diagram++ that represents the design of this program and submit it in your final submission. You’ll also need to submit an ++inheritance/interface diagram++. Be sure to add your diagrams as a **.pdf**, **.jpg/.jpeg**, or **.png** to your GitHub repository. **<font color="#ff0000">If you submit a different file format, it may be unsupported by Gradescope so you will receive no credit for the diagram.</font>**
These diagrams will be factored into the “design” portion of the grade. Check out the [Class & Inheritance/Interface Diagrams Guide](https://docs.google.com/document/d/1LZV1M75gozJuU7jouTmusjw2B4fjLPOCSh9feQ3sDXM/edit#heading=h.n64vzvb7650b) for help.
---
# Style
Refer to the ++[CS15 Style Guide](https://docs.google.com/document/d/1olSJxbrhuIystA_kVbmKu4V8JfN7HE-eDzM5blkoeFw/edit#heading=h.b1nvuu1nggmv)++ for the specific style guidelines along which your code will be graded for the “style” portion.
# Handing In
## README
In CS15, you’re **++required to hand in a README file++** (must be named README) that documents any notable design choices or known bugs in your program. Remember that clear, detailed, and concise READMEs best allow your TAs to understand your thought process, helping them better understand your project as well.
You are expected to create your own README file. Please refer to the [README guide](https://docs.google.com/document/d/1QJPit-_8ZC3r4l_f5F3ydMK34-NchBYgwtm0c21iwsU/edit) for information on how to create a README, what information your README should contain, and how you must format it.
At the bottom of your README, add the approximate number of hours you spent on this homework. This will be used only to average how long the homeworks are taking students this semester, and it is completely anonymous.
## Handin
To hand in your assignment, follow these steps:
1. In a terminal, move into the **`fruitninja`** folder as if you were about to compile your code
2. Type the command **`rm *.class`** (Mac) or **`del *.class`** (Windows)
a. This will remove the **`.class`** files that are created when compiling so that your submission only includes **`.java`** code files.
3. Add your diagrams to your repository
a. Drag and drop or upload your class and inheritance/interface diagrams to your **`fruitninja`** folder
4. [Add, commit, and push your code to GitHub](#Saving-Your-Work-on-GitHub)
5. In the submission for Fruit Ninja on Gradescope, click on GitHub
6. Select your **fruitninja** repository and the **main** branch
7. Upload! Double check that you have uploaded to Gradescope properly and your diagrams appear on the submission.
You can submit as many times as you want prior to the deadline, and only your most recent handin will be graded. If you handin before the deadline and again after the deadline, the submission *will* be counted as late.
**<font color="#ff0000">Please do not include any identifying information on your hand-in (name, login, Banner ID) as we grade anonymously. Including identifying information will result in a deduction from your assignment. </font>**
This assignment was updated this year to improve your CS15 learning experience! If you have any feedback for us, please fill out our student opinion form [here](https://forms.gle/YBYFnQjfQ67iRJnW7).