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.
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!
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.
Make a new project for this assignment
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
←keys should cause text to appear in the console.
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
Birdconstructor 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
makeFlippedstatic method to creat the left-facing images.
makeFlippedis a private static method for creating mirror images of images. It uses something called an AffineTranform to do its work.
drawis the method that displays the bird. It is given a Graphics object to do the actual drawing with. Try changing
yand see how the image changes when you run the program. Where is (0, 0)? Is
up+x, −x, +y, or −y?
- There is one field, an array of
Read the existing code in
JoustScreen.java. Note the following:
Notice the line
public class JoustScreen extends KeyAdapter implements ActionListener. Those extra bits (
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.
mainis trivial: it simply creates a
JoustScreendoes all the work.
mainis 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.
JoustScreenconstructor sets up the existing fields. When you add fields of your own, add to the constructor too.
keyPressedis called by Java every time the user presses a key.
actionPerformedis 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.
this.paintbrushto 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
refreshScreento 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
Birdobject, each one a different color or otherwise visually distinct
- Have the
skeys cause one player to flap, the
lcause 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
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
Birdobjects are there, and where are they stored?
You want the bird positions to be
ints. Trust us.
Collisions can be tricky. There is a built-in class called
ints) that might help. It has a method
intersectsthat can check if two rectangles intersect; it also has a method
intersectionthat returns the overlap of two rectangles: in the image below,
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
JoustScreenmethod, 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
keyPressedyou typically just update bird velocity (they flapped)
refreshScreenmethod 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.
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
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”):
- mst3k@Virginia.EDU => mst3k@Virginia.EDU
- email@example.com => firstname.lastname@example.org
- mst3k at virginia.edu => email@example.com
- mst3k at virginia dot edu => firstname.lastname@example.org
Here are some tips that might help:
You can read the entire web page into a single String to make it easier to search.
1 2 3 4 5 6
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
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
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
Example program run:
What web page should we search for email addresses? https://cs1110.cs.virginia.edu/emails.html
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.