Computer Science 252
Problem Solving with Java

Spring 2016, The College of Saint Rose

Lab 8: Furious Fowl
Due: 11:59 PM, Friday, March 18, 2015

For this lab, you will be developing what I hope you will find to be the most interesting program so far: you will develop a "furious fowl" game (legally distinct from Angry Birds, I'm sure).

You may work alone or with a partner on this lab. Only one submission per group is needed.

Getting Set Up

Download the a starter project with partial implementations of some of the programs from here.

Create a document where you will record your answers to the lab questions. If you use plain text, call it "lab8.txt". If it's a Word document, you can call it whatever you'd like, but when you submit, be sure you convert it to a PDF document "lab8.pdf" before you submit it.

Working solutions to all programs can be downloaded here.


We saw a program that simulated acceleration due to gravity in the VanishingScribble example. The FallingLine ActiveObject there starts out moving very slowly but moves a bit faster (10% faster, to be precise) each time through its animation loop.

In the programs you will be writing for this lab, you will also be simulating gravity, but the objects on which gravity acts might be moving up and might be moving down. When moving up, the object slows down due to gravity. When moving down, the object speeds up. Many programmers when confronted with this task overthink the problem. To see one approach to this, study the animation loop in the run method of the BouncyBall class in the BallBounceAround example. Note that (other than the code that changes the color of the ball to shades of red when falling and shades of blue when rising) there is no distinction between upward or downward movement, or how gravity accelerates or decelerates the ball. It is achieved by adding a constant amount to the y speed each iteration. When the ball is going up (i.e., it has a negative y speed), this has the effect of slowing its upward motion. When the ball is going down, the effect is to speed its downward motion.

Practice Program

Since your main programming task this week involves an ActiveObject a bit different from the ones you've seen, we'll start with a practice program to create an ActiveObject that behaves similarly.

In the BallTossAround folder in the starter you downloaded, you will find a window controller class called BallTossAround that creates a FilledOval every time you press the mouse and passes that FilledOval to the constructor of an active object (which you will implement) that is responsible for moving that ball across the screen as if you "tossed" it upward to the right.

Most (all?) of the active objects we have seen so far are responsible for creating the graphical objects they animate. Here, though, the active object takes the object it animates as a parameter to the constructor.

Question 1: Ultimately, you will need to have the FilledOval that is created in the BallTossAround class moved by code in your ActiveObject's run method. What are the steps needed to make a reference to the FilledOval available in that run method? (2 points)

In addition to the reference to the FilledOval as described in the question above, your run method will also need to know about the canvas (or perhaps just its dimensions) so when the run method animates the ball, it can stop when the ball goes off the bottom or right of the canvas. Its run method should start the ball moving up and to the right, but the ball should be subject to "gravity" - its y speed should increase each time around the animation loop. So you should see the ball trace out a parabolic path. When the ball goes off the bounds of the canvas, the loop should stop and the ball should be removed from the canvas.

Practice Program: Complete the implementation of the BallTosser class. (6 points)

Question 2: Experiment with your program to try different values for the initial x and y speeds and acceleration due to gravity. What values work well to give the ball paths that look like each of the following? (2 points)

Furious Fowl

Your programming assignment is to implement a very simplified version of the popular Angry Birds game, where millions of people spend billions of combined hours launching birds at pigs. (Note that I am not judging or criticizing here, I am a recovering Angry Birds addict.) Since your program will have just one bird and one pig, maybe we could call it "Angry Bird". Better yet, we'll just call it "Furious Fowl". No sense drawing the attention of Rovio's lawyers.

The program stars with a bird sitting on a perch near the bottom left and a pig sitting somewhere near the bottom right of the canvas. To play, you press the mouse and drag around near the bird, resulting in a "sling" that follows your mouse around on one end but which remains anchored to the bird on the other. When you release the mouse, the angle of the sling determines a "launch vector" for the bird. The bird starts moving in the direction you launched him, and flies across the canvas, subject to acceleration due to gravity. The game ends in success if your bird bumps into the pig, or failure if your bird leaves the visible bounds of the canvas before bumping into the pig.

A few more details, hints, and other notes:

Bonus Opportunity

You can earn up to 5 points of bonus for enhancements to the programming assignment. Check with your instructor for point values for any enhancements you wish to attempt.

There are two examples posted on the Examples page showing how to play sounds in Java applets - you are welcome to include some sound effects as part of your extra credit for this lab.


Before 11:59 PM, Friday, March 18, 2015, submit your lab for grading. There are four things to do to complete the submission: (i) Copy your file with the answers to the lab questions into your project directory. Be sure to use the correct file name. If you prepared your answers in Word, export to a PDF file and submit that. (ii) Email a .7z or .zip file containing your project directory to terescoj AT (iii) If possible, demonstrate the execution of your programs for your instructor. (iv) Hand a printout of the Java files that make up the programming assignment (not practice programs) to your instructor. (2 business day grace period for printouts)


This assignment is worth 75 points, which are distributed as follows:

> FeatureValueScore
Lab Question 1 2
Lab Question 2 2
BallTosser moves ball 2
BallTosser gravity correct 2
BallTosser stops and is removed from canvas 2
FuriousFowl Correctness
Perch drawn 1
Bird placed initially on perch 2
Pig placed randomly in lower right portion of canvas 3
Sling appears when mouse press on bird (only) 3
Sling one end follows mouse, other at center of bird 2
Sling disappears on launch 1
Bird launched on release (only if sling visible) 4
Basic bird animation loop 3
Bird launch vector determined by sling angle 4
Bird animation subject to gravity 4
Bird stops on contact with pig 4
Bird stops when off visible portion of canvas 4
Message updates 4
Using image files for bird and pig 1
No unexpected behaviors or exceptions 5
Style, Design, and Efficiency
Appropriate comments 5
Good variable names 3
Appropriate variable declarations 3
Good use of constants 3
Appropriate formatting 1
Does not generate new objects unnecessarily 2
Good overall design and methods 3