CS 1110/1111 - Spring 2015 - Partner Projects

Partner Project 2: Game Project - Due: Wednesday, April 22, 11:00 AM

Games, in addition to being fun, are also a great way to practice many aspects of programming. This semester we’ll create a game similar to the 1982 classic Joust. In our version we’ll have the two players be oponents instead of allies: they’ll ride giant birds and try to knock one another off their birds. You can try it either by running JoustDemo.jar or by importing into Eclipse JoustDemoProject.zip. The a, s, k, and l keys control the birds.

You should work with one partner on this assignment. You should pick a partner in the Thursday, 2 April lab. Your partner must be in the same lab section as yourself – no exceptions!

Getting Started

Java comes with two different windowing libraries, and rather than teach you all of the ins and outs of these we’ve decided to give you some basic code that gets something on the screen.

  1. Make a new project for this assignment

  2. Download Bird.java and JoustScreen.java and copy them into the src folder of your new project.

  3. Download birdg.png, birdgf.png, birdgb.png, birdr.png, birdrf.png, and birdrb.png and copy them into your project but not into the src folder.

  4. Run JoustScreen. If it works you should see a red bird, a black rectangle, and three pieces of text in dark red, dark green, and dark blue, all on a light blue background. Pressing the A and keys should cause text to appear in the console.

  5. Read the existing code in Bird.java. Note the following:

    • There is one field, an array of BufferedImages that will be used to draw the bird. The contents of this array are described in the Bird constructor.
    • The Bird constructor currently does nothing but set up the array to hold three right-facing images (one with folded wings, one for forward flaps, one for backwards flaps) and three left-facing images. It used the makeFlipped static method to creat the left-facing images.
    • makeFlipped is a private static method for creating mirror images of images. It uses something called an AffineTranform to do its work.
    • draw is the method that displays the bird. It is given a Graphics object to do the actual drawing with. Try changing i, x, and y and see how the image changes when you run the program. Where is (0, 0)? Is up +x, −x, +y, or −y?
  6. Read the existing code in JoustScreen.java. Note the following:

    • Notice the line public class JoustScreen extends KeyAdapter implements ActionListener. Those extra bits (extends and implements) will be discussed in detail in CS 2110. How now, they tell Java this class understands how to rect to keys being pressed and timers ticking.

    • main is trivial: it simply creates a JoustScreen. The JoustScreen does all the work. main is also responsible for printing out all the extra features you implemented, one feature per line.

    • There are a few fields that take care of keeping track of the fact that we have a window that displays an image that we create programatically using a paintbrush and update several times a second using a timer.

    • The JoustScreen constructor sets up the existing fields. When you add fields of your own, add to the constructor too.

    • keyPressed is called by Java every time the user presses a key. actionPerformed is called by Java every time the timer ticks (in the code we gave you, once every 20 milliseconds = 50 times a second). You’ll eventually change both of these.

    • refreshScreen used this.paintbrush to draw the screen. It is called by Java anytime it needs to know what the screen looks like, which includes at least once after every tick of the clock and may be more often than that as parts of the screen are covered and uncovered by other widows. There’s a fair amount of code in refreshScreen to demonstrate how you can do various things. Play with that code, see if you can understand what each part is doing and how to make it do something else.


Your joust game should do the following:

  • Have two players, each with a Bird object, each one a different color or otherwise visually distinct
  • Have the a and s keys cause one player to flap, the k and l cause the other player to flap.
  • Have gravity
  • Have wind drag (birds slow down over time)
  • Keep the birds inside the screen
  • Have at least two obstacles that the birds cannot pass through
  • When birds collide, give the bird on top a point and teleport the bird on the bottom to the top of the screen
  • Keep score
  • Either (a) always have each bird’s image face towards its opponent or (b) always have each bird’s image facing in the direction it is moving

You should also include at least one of the following extra features:

  • Collisions where neither bird is clearly above the other cause birds to bounce off each other instead of scoring points
  • A “game over” mechanism once someone gets enough points
  • Moving obstacles
  • Computer-controlled bird of some kind (in addition to both player-controlled birds)
  • Birds visually flaps their wings when you press the flap keys
  • Prevent players from flapping again too soon after their last flap
  • Optional n-player mode for n > 2
  • A display of high scores, cumulative over all games on the computer. To earn credit, the high scores have to vary (e.g., if you always end when someone gets 10 points, a list of 10s isn’t enough) and should indicate where the most recent game lands in the list.
  • Something else cool (note: just using different images might be cool-ish, but it isn’t cool enough for credit)

You can get extra credit for adding 2 or 3 extras instead of just 1.

You must not have any static fields!

Design before Code

Don’t start with code. Start with design, then try out small stand-alone methods. Making a copy of your project in which to try something is a good idea.

We strongly encourage writing the UML Class Diagram for Bird and any other classes you might need. In doing so, a few ideas:

  • Where does score get stored? How many Bird objects are there, and where are they stored?

  • You want the bird positions to be doubles, not ints. Trust us.

  • Collisions can be tricky. There is a built-in class called Rectangle (which uses ints) that might help. It has a method intersects that can check if two rectangles intersect; it also has a method intersection that returns the overlap of two rectangles: in the image below, A.intersects(B) is true and A.intersection(B) is the green rectangle.


  • In general, your game should work by going one “frame” at a time. You advance from one frame to the next in the actionPerformed in JoustScreen method, which is automatically called by the gameTimer every 20 milliseconds (50 times a second). Some things to do once every frame:

    • Update each bird’s positions based on its speed
    • Apply gravity and drag
    • Detect and react to any bird-bird, bird-wall, or bird-obstacle collisions
  • In keyPressed you typically just update bird velocity (they flapped)

  • The refreshScreen method should only draw things, it shouldn’t modify bird state in any way.

What to submit:

Submit any files you created or edited (no need to submit files you don’t edit) at the project submission page. Either partner may submit.

You should submit any files you create and/or edit; you may write as many java files as you wish. You do not need to submit the .png files we gave you unless you edit them. If you use your own images, do upload them but also make sure it is legal to share them.

When you are done, fill out an evaluation of your partner. We take these very seriously. If a partner does not pull their weight, it will have an affect on their grade.

Partner Evaluation Form


We will not run any automatic tests. Well, we do, but just to check that your code compiles and has your id in each .java file; nothing more than that.

Partner groups CANNOT work together. We will be running your code through software comparion tools to detect sharing of code.

Partner Project 1: Email Hunt - Due: Friday, March 20, 11:00 AM

Please register with your partner on the lab submission page here.

Have you ever wondered how spammers get all their email addresses to send those lovely messages about foreign princes with banking troubles or the latest and greatest medication for… whatever?

We here in CS 1110 want to equip you with the skills to become a spammer yourself! Well, not really, but the techniques used to farm email addresses can be really useful!

The goal of this assignment is to write a program that will scan a web page and harvest as many email addresses as possible. Many of these email address will be obfuscated in some way. It’s up to you to get the computer to figure out how to recognize the obfuscation and return a good result!

Your grade will be based on how many (and what types) of email addresses you can find in the page. We will provide examples of most types of obfuscation, but not necessarily all. Some bonus points may be earned for some really tricky ones.

You should pick a partner to work with in the Thursday, February 26, lab (or at least before Spring Break). Your partner must be in the same lab section as you (or both in 1111) - no exceptions!

We will update this page with more info throughout the project.

Here are some examples to get you started (in the form “obfuscated email” => “what your program should interpret the email as”):

Here are some tips that might help:

You can read the entire web page into a single String to make it easier to search.

Single String
Scanner web = new Scanner(new URL(url).openStream());
String wholePage = "";
while(web.hasNextLine()) {
  wholePage += web.nextLine() + "\n";

If you want to find a particular character, wholePage.indexOf("@"); returns the first index where a @ appears. If you then do wholePage.indexOf("@", token+1); where token is the location of the first @, then this will return the location of the second @'

Other String methods you probably will want to look at:

  • indexOf, discussed in the previous paragraph

  • lastIndexOf, like indexOf but looks before instead of after the starting point

  • substring, useful for pulling out just one bit of a string

  • replace, which you used in POTD 11, useful for e.g., replacing at with @.

INPUT: Your program should ask the user for a URL where your program should look for emails.
We have a page https://cs1110.cs.virginia.edu/emails.html that has a set of example emails you should be able to find (and some that you can look for but we are not requiring).

OUTPUT: You program should output the list of email addresses to the console. To help the autograder, put one email per line and surround each email address in angle brackets (like <mst3k@virignia.edu>).

Example program run:

What web page should we search for email addresses? https://cs1110.cs.virginia.edu/emails.html
Found: <basic@virginia.edu>
Found: <link-only@virginia.edu>
Found: <multi-domain@cs.virginia.edu>
Found: <Mr.N0body@cand3lwick-burnERS.rentals>
Found: <a@b.ca>
Found: <no-at-sign@virginia.edu>
Found: <no-at-or-dot@virginia.edu>
Found: <first.last.name@cs.virginia.edu>
Found: <with-parenthesis@Virginia.EDU>
Found: <added-words1@virginia.edu>
Found: <added-words2@virginia.edu>
Found: <may.end@with-a-period.com>

Submission: Submit your file EmailFinder.java on the project submission page. You and your partner share the same upload space: a submission from one is a submission from the other.