📄 powerup.java
字号:
package com.brackeen.javagamebook.tilegame.sprites;
import java.lang.reflect.Constructor;
import com.brackeen.javagamebook.graphics.*;
/**
A PowerUp class is a Sprite that the player can pick up.
*/
public abstract class PowerUp extends Sprite {
public PowerUp(Animation anim) {
super(anim);
}
public Object clone() {
// use reflection to create the correct subclass
Constructor constructor = getClass().getConstructors()[0];
try {
return constructor.newInstance(
new Object[] {(Animation)anim.clone()});
}
catch (Exception ex) {
// should never happen
ex.printStackTrace();
return null;
}
}
/**
A Star PowerUp. Gives the player points.
*/
public static class Star extends PowerUp {
public Star(Animation anim) {
super(anim);
}
}
/**
A Music PowerUp. Changes the game music.
*/
public static class Music extends PowerUp {
public Music(Animation anim) {
super(anim);
}
}
/**
A Goal PowerUp. Advances to the next map.
*/
public static class Goal extends PowerUp {
public Goal(Animation anim) {
super(anim);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -