📄
字号:
mediator.fairySetNextDirection(Fairy.DIR_WEST);
break;
case KeyEvent.VK_RIGHT :
station.unPause();
mediator.fairySetNextDirection(Fairy.DIR_EAST);
break;
case KeyEvent.VK_UP :
station.unPause();
mediator.fairySetNextDirection(Fairy.DIR_NORTH);
break;
case KeyEvent.VK_DOWN :
station.unPause();
mediator.fairySetNextDirection(Fairy.DIR_SOUTH);
break;
case KeyEvent.VK_S:
start();
break;
case KeyEvent.VK_P:
station.pause();
break;
case KeyEvent.VK_H:
station.pauseAndShowHelp();
break;
case KeyEvent.VK_N:
//for debug
System.out.println("VK_N");
try {
station.nextStation();
} catch(Exception ex) { ex.printStackTrace(); }
break;
default :
}
}
public void keyReleased(KeyEvent e) {
switch(e.getKeyCode()) {
case KeyEvent.VK_LEFT :
case KeyEvent.VK_RIGHT :
case KeyEvent.VK_UP :
case KeyEvent.VK_DOWN :
mediator.fairyResetNextDirection();
break;
default :
}
}
});
//this.paintAll(this.getGraphics());
}
/** 游戏事件监听者 */
class GameListenerImpl extends GameListener {
private boolean hasLifeInc = false;
public void objectEat(GameEvent e) {
//System.out.println("eatbean");
Object source = e.getSource();
if(source == null) return;
if(source instanceof Room)
//score += ((Room)source).POINT;
score += 10;
if((score >= SysParam.SCORE_TO_ADD_LIFE) && !hasLifeInc) {
mediator.beep();
life++; //奖励,生命值加1
hasLifeInc = true;
}
}
public void actorEat(GameEvent e) {
Object source = e.getSource();
if(source == null) return;
if(source instanceof Fairy) {
if(Debug.ON) Debug.println("objectEat() Fairy被杀");
if(life > 0) {
station.continuePlay();
//mediator.setPaused(false);
} else {
//Game Over
if(Debug.ON) Debug.println("Game Over");
try {
//station.demo();
station.gameOver();
} catch(Exception ex) {}
}
} else if(source instanceof Sprite) {
if(Debug.ON) Debug.println("objectEat() Sprite被杀");
}
}
public void stationDone(GameEvent e) {
//Mission Done
try {
if(!station.nextStation()) {
//All Mission Done
station.allMissionDone();
}
} catch(Exception ex) {};
}
}
/** 标准屏幕事件监听者,以实时更新显示分数/生命值等信息 */
class ScreenListenerImpl implements ScreenListener {
Color c = Color.white;
Font font = new Font("宋体", Font.BOLD, 12);
public void update(ScreenEvent se) {
OffScreen offScr = (OffScreen)se.getSource();
int h = mediator.getMapHeight();
if(offScr != null) {
updateGeneralInfo(offScr, h);
}
}
}
/** 显示帮助信息 */
class ScreenListenerImplHelp implements ScreenListener {
Color c = Color.yellow;
Font font = new Font("宋体", Font.BOLD, 13);
public void update(ScreenEvent se) {
OffScreen offScr = (OffScreen)se.getSource();
int h = mediator.getMapHeight();
if(offScr != null) {
offScr.setColor(c);
offScr.setFont(font);
int baseX = 130, baseY = 80;
offScr.drawString("吃豆子Ver1.0", baseX, baseY);
offScr.drawString("\"s\"-开始游戏", baseX-10, baseY=baseY+20);
offScr.drawString("\"p\"-暂停游戏", baseX-10, baseY=baseY+20);
offScr.drawString("\"方向键\"-返回游戏,控制精灵", baseX-10, baseY=baseY+
20);
baseX = 80; baseY = 220;
offScr.setColor(Color.white);
offScr.drawString("---------------------------------", 50, baseY);
offScr.drawString("程序: \"nothing\"", baseX, baseY=baseY+15);
offScr.drawString("美工: \"olive\"", baseX, baseY=baseY+15);
offScr.drawString("Raindrop Studio 2002.3", baseX+20, baseY=baseY+15);
offScr.drawString("Email: chinaren_gc@chinaren.com", baseX+20, baseY=bas
eY+15);
updateGeneralInfo(offScr, h);
}
}
}
/** 显示暂停信息 */
class ScreenListenerImplPause implements ScreenListener {
Color c = Color.yellow;
Font font = new Font("宋体", Font.BOLD, 14);
public void update(ScreenEvent se) {
OffScreen offScr = (OffScreen)se.getSource();
int h = mediator.getMapHeight();
if(offScr != null) {
offScr.setColor(c);
offScr.setFont(font);
offScr.drawString("第" + station.stationNum + "关", 140, 100);
offScr.drawString("暂 停", 130, 120);
offScr.drawString("\"方向键\"返回游戏", 130, 140);
updateGeneralInfo(offScr, h);
}
}
}
/** 通关时显示相关信息 */
class ScreenListenerImplAllMisnDone implements ScreenListener {
Color c = Color.yellow;
Font font = new Font("宋体", Font.BOLD, 16);
public void update(ScreenEvent se) {
OffScreen offScr = (OffScreen)se.getSource();
int h = mediator.getMapHeight();
if(offScr != null) {
offScr.setColor(c);
offScr.setFont(font);
offScr.drawString("大侠您通关了!", 100, 120);
offScr.drawString("签个名吧:)", 120, 160);
updateGeneralInfo(offScr, h);
}
}
}
/** GameOver时显示相关信息 */
class ScreenListenerImplGameOver implements ScreenListener {
Color c = Color.yellow;
Font font = new Font("宋体", Font.BOLD, 20);
public void update(ScreenEvent se) {
OffScreen offScr = (OffScreen)se.getSource();
int h = mediator.getMapHeight();
if(offScr != null) {
offScr.setColor(c);
offScr.setFont(font);
offScr.drawString("Game Over", 130, 120);
Font font = new Font("宋体", Font.BOLD, 14);
offScr.setFont(font);
offScr.drawString("\"s\"-重玩", 140, 160);
updateGeneralInfo(offScr, h);
}
}
}
private void updateGeneralInfo(OffScreen offScr, int h) {
offScr.clearRect(0, h+2,
offScr.getWidth(), offScr.getHeight() - h);
h = h + 20;
offScr.setColor(Color.white);
offScr.setFont(new Font("宋体", Font.BOLD, 12));
offScr.drawString("生命: " + Integer.toString(life), 10, h);
offScr.drawString("得分: " + Integer.toString(score), 120, h);
offScr.drawString("关卡: " + Integer.toString(station.getStationNum()), 28
0, h);
offScr.drawString("\"h\"-帮助 [Raindrop Studio]", 140, h+14);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -