Computer Science APEA 15-100, Summer 2009
Lab 8
Read these instructions first!
- The homework collaboration policy does not apply to labs. In
labs, you may work alone or in small groups. And you may show each
other your code, and help each other in any manner. This is
encouraged, in fact!
- That said, the participation policy is still in effect -- you must
not only attend labs, but actually work during the labs. If you have
completed the assigned work, then you should either help others, if they
request it, or you should delve deeper into the assigned material.
But you must use the lab time exclusively to explore the material covered in
that lab.
- In particular, you may not use lab time to do your homework.
- There is nothing to submit for labs.
Note: You may use loops and conditionals now. You may not
use Java concepts we have not yet covered, including arrays or methods from any classes in java.util.* to solve these problems.
Also, you may only use the charAt and length methods from the String class. While they may be helpful, every problem here is solvable without them.
Also note: For each of these problems, you should write your own tests!
- Hw7 solutions (quickly)
- Experimental Math: Discovery
Finish all the "discovery" examples from
today's lecture notes. (Actually, just finish a couple during lab
time, leave the rest to the weekend to finish.)
- Stars
Using the star code from class, draw the flag of Panama (with stars, of
course).
- 2d Loops
Using two "for" loops, draw an 8x8 checkerboard.
- Checkerboard Animation
Animate your 2d loops checkerboard example so that a single checker
starts in the lower-left (which we will assume is a red square) and in turn
visits every red square on the board in whatever pattern suits you.
Try some variants on the pattern, too.
- Simple Game
In a file named Lab8SimpleGame.java, write this
Simple Game.
Note: If this applet does not run in your web browser, you can try running
this equivalent jar file:
simpleInvadersGame.jar
Note that you move the blue paddle with left/right keys, and fire with the
space bar. The red ball is fired randomly (though always downward).
You should use bounding boxes for all collision tests (this makes the
game a bit easier to implement). Play the game in order to determine the
rest of the design spec.
Note: you are not likely to finish this during today's lab session.
The remainder of this problem (and the rest of the lab!) should be completed
collaboratively over the weekend.
Also: you will have to use the page.drawString method and page.setFont
methods, such as this:
page.setFont(new Font("Arial",Font.BOLD,16));
page.drawString("Carpe diem", 50, 100);
The first line sets the font to use for subsequent text. The 16 is the
point-size of the font. If you don't want bold, you could replace
Font.BOLD with Font.PLAIN. The second line draws the string "Carpe
diem" so that the its left baseline (roughly its bottom-left) is at the
location (50,100). You are not expected to exactly locate strings
vertically (for now, close is close enough), so don't worry about where
exactly the baseline of the string is.
Carpe diem!