java俄罗斯方块暂停、停止功能无法使用
privatevoidprocessPauseKey(intkey){switch(key){caseKeyEvent.VK_Q:System.exit(0);break...
private void processPauseKey(int key) {
switch (key) {
case KeyEvent.VK_Q:
System.exit(0);
break;
case KeyEvent.VK_C:
index = 0;
state = RUNNING;
break;
}
}
protected void processRunningKey(int key) {
switch (key) {
case KeyEvent.VK_Q:
System.exit(0);
break;
case KeyEvent.VK_RIGHT:
moveRightAction();
break;
case KeyEvent.VK_LEFT:
moveLeftAction();
break;
case KeyEvent.VK_UP:
current.rightRotate();
break;
case KeyEvent.VK_DOWN:
softDrop();
break;
case KeyEvent.VK_SPACE:
hardDrop();
break;
}
}
protected void processGameoverKey(int key) {
switch (key) {
case KeyEvent.VK_Q:
System.exit(0);
break;
case KeyEvent.VK_S:
this.lines = 0;
this.score = 0;
this.wall = new Cell[ROWS][COLS];
this.current = this.current.randomOne();
this.state = RUNNING;
this.index = 0;
break;
}
}
public void action() {
current = Shape.randomOne();
nextOne = Shape.randomOne();
state = RUNNING;
this.repaint();
this.addKeyListener(new KeyAdapter() {
public void KeyPressed(KeyEvent e) {
int key = e.getKeyCode();
switch (state) {
case GAME_OVER:
processGameoverKey(key);
case PAUSE:
processPauseKey(key);
case RUNNING:
processRunningKey(key);
}
repaint();
}
});
this.setFocusable(true);
this.requestFocus();
} 展开
switch (key) {
case KeyEvent.VK_Q:
System.exit(0);
break;
case KeyEvent.VK_C:
index = 0;
state = RUNNING;
break;
}
}
protected void processRunningKey(int key) {
switch (key) {
case KeyEvent.VK_Q:
System.exit(0);
break;
case KeyEvent.VK_RIGHT:
moveRightAction();
break;
case KeyEvent.VK_LEFT:
moveLeftAction();
break;
case KeyEvent.VK_UP:
current.rightRotate();
break;
case KeyEvent.VK_DOWN:
softDrop();
break;
case KeyEvent.VK_SPACE:
hardDrop();
break;
}
}
protected void processGameoverKey(int key) {
switch (key) {
case KeyEvent.VK_Q:
System.exit(0);
break;
case KeyEvent.VK_S:
this.lines = 0;
this.score = 0;
this.wall = new Cell[ROWS][COLS];
this.current = this.current.randomOne();
this.state = RUNNING;
this.index = 0;
break;
}
}
public void action() {
current = Shape.randomOne();
nextOne = Shape.randomOne();
state = RUNNING;
this.repaint();
this.addKeyListener(new KeyAdapter() {
public void KeyPressed(KeyEvent e) {
int key = e.getKeyCode();
switch (state) {
case GAME_OVER:
processGameoverKey(key);
case PAUSE:
processPauseKey(key);
case RUNNING:
processRunningKey(key);
}
repaint();
}
});
this.setFocusable(true);
this.requestFocus();
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询