Language Robocode
| Date: | 04/20/05 |
| Author: | Peter Strömberg |
| URL: | n/a |
| Comments: | 1 |
| Info: | http://robowiki.dyndns.org/?PEZ |
| Score: |
package wiki.beer;
import robocode.*;
import java.awt.geom.Point2D;
// BeerPoet, one way to go about writing the 99-bottles-of-beer poem.
// By Peter Strömberg, http://robowiki.dyndns.org/?PEZ
// For more info on the poem: http://99-bottles-of-beer.ls-la.net/
//
// Run this robot in Robocode.
// Put it against 99 SittingDuck and open its output window.
public class BeerPoet extends AdvancedRobot {
private boolean hasStarted;
public void run() {
turnGunRightRadians(Double.POSITIVE_INFINITY);
}
public void onScannedRobot(ScannedRobotEvent e) {
if (!hasStarted) {
printBottles();
hasStarted = true;
}
setFire(3);
setTurnGunRightRadians(0 - getGunTurnRemainingRadians());
}
public void onRobotDeath(RobotDeathEvent e) {
printBottles();
}
private void printBottles() {
out.println(bottles());
if (getOthers() > 0) {
out.println("Take " + (getOthers() == 1 ? "it" : "one") +
" down, and pass it around");
}
else {
out.println("Now they are all gone");
}
}
private String bottles() {
return bottles(getOthers()) + " on the wall, " + bottles(getOthers());
}
private String bottles(int bottles) {
return (bottles == 0 ? "No" : "" + bottles) +
" bottle" + (bottles == 1 ? "" : "s") + " of beer";
}
}
Download Source | Write Comment
Download Source | Write Comment
Add Comment
Please provide a value for the fields Name,
Comment and Security Code.
This is a gravatar-friendly website.
E-mail addresses will never be shown.
Enter your e-mail address to use your gravatar.
Please don't post large portions of code here! Use the form to submit new examples or updates instead!
Comments