예제 #1
0
 private void moveCursor(int inc) {
   if (isMoveSelected()) {
     int newIndex = moveIndex + inc;
     if (newIndex >= moves.size()) {
       newIndex = 0;
     }
     if (newIndex < 0) {
       newIndex = moves.size() - 1;
     }
     setCursor(newIndex);
   }
 }
예제 #2
0
 private Move getSelectedMove() {
   if (isMoveSelected()) {
     return (Move) moves.elementAt(moveIndex);
   } else {
     return null;
   }
 }
예제 #3
0
 public void stateChanged(State state) {
   BoardGame game = (BoardGame) getGame();
   if ((state == game.STATE_THINKING) && (game.getCurrentPlayer() == this)) {
     it.reset(this, game.getBoard());
     while (it.hasMoreElements()) {
       moves.addElement(it.nextElement());
     }
     if (isMoveAvailable()) {
       setCursor(0);
     }
   }
 }
예제 #4
0
 public void gameAction(int action) {
   BoardGame game = (BoardGame) getGame();
   if ((game.getCurrentPlayer() == this)
       && (game.getState() == game.STATE_THINKING)
       && (getSelectedMove() != null)) {
     switch (action) {
       case Canvas.FIRE:
         game.queueMove(getSelectedMove());
         moves.removeAllElements();
         break;
       case Canvas.LEFT:
       case Canvas.UP:
         moveCursor(-1);
         break;
       case Canvas.DOWN:
       case Canvas.RIGHT:
         moveCursor(1);
         break;
     }
   }
 }
예제 #5
0
 private boolean isMoveAvailable() {
   return moves.size() > 0;
 }