📄 fallingcow.java~
字号:
import objectdraw.*;import java.applet.*;import java.awt.*;// creates a falling cow imagepublic class FallingCow extends FallingObject{ private static final int COW_HEIGHT = 70; private static final int COW_WIDTH = 100; private static final int COW_PAUSE = 30; private static final int COW_WALK_SPEED = -3; private static final int COW_FALL_SPEED = 4; private DrawingCanvas canvas; // image for walking cow private Image cow; // be sure to import java.applet.awt private AudioClip moo; // Creates a falling purple cow public FallingCow(DrawingCanvas aCanvas, Image upsideDownCow, Image aCow, AudioClip aMoo, double x, int groundHeight) { // Create a generic falling object super (groundHeight - COW_HEIGHT, COW_FALL_SPEED); canvas = aCanvas; cow = aCow; moo = aMoo; // Specialize it to be an upside down cow. object = new VisibleImage(upsideDownCow, x, -COW_HEIGHT, canvas); // Start it falling start(); } protected void hitBottom() { // play moooing noise moo.play(); // let superclass do what it wants to super.hitBottom(); // make cow walk back to the left VisibleImage walkingCow = new VisibleImage(cow, object.getLocation(), canvas); while (walkingCow.getX() + COW_WIDTH > 0) { pause(COW_PAUSE); walkingCow.move(COW_WALK_SPEED, 0); } walkingCow.removeFromCanvas(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -