Computer Science 252
Problem Solving with Java

Fall 2014, The College of Saint Rose

Lab 5: Furious Fowl
Due: 11:59 PM, Friday, October 17, 2014

This week, 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 "lab5.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 "lab5.pdf" before you submit it.

Working solutions to all programs can be downloaded here.

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.

Demo

A working solution for the program will appear below. Click inside the applet to interact with it.



Practice Program: Complete the implementation of the BallTosser class. (8 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:

Demo

A working solution for the program will appear below. Click inside the applet to interact with it.



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.

Submitting

Before 11:59 PM, Friday, October 17, 2014, submit your lab for grading. There are three things you need 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) Upload a copy of your lab (a .7z or .zip file containing your project directory) using Submission Box under assignment "Lab5". (iii) Demonstrate the execution of your programs for your instructor. (2 business day grace period for demos).

Grading

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

> FeatureValueScore
Lab Question 1 2
BallTosser moves ball 3
BallTosser gravity correct 2
BallTosser stops and is removed from canvas 3
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
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
Bonus

Total

70