コード例 #1
0
    @Override
    public void onButtonsEvent(WiimoteButtonsEvent arg0) {
      // TODO Auto-generated method stub
      if (arg0.isButtonAHeld()) canDraw = true;
      if (arg0.isButtonAJustReleased()) {
        canDraw = false;
        frameComponent.drawNewLine();
      }

      if (arg0.isButtonBJustPressed()) canErase = true;
      if (arg0.isButtonBJustReleased()) canErase = false;

      if (arg0.isButtonUpPressed()) {
        frameComponent.increasePointerWidth();
      }
      if (arg0.isButtonDownPressed()) {
        frameComponent.decreasePointerWidth();
      }

      if (arg0.isButtonRightJustPressed()) {
        frameComponent.changeUpColor();
        currColorLabel.setBackground(frameComponent.getCurrentColor());
        repaint();
      }
      if (arg0.isButtonLeftJustPressed()) {
        frameComponent.changeDownColor();
        currColorLabel.setBackground(frameComponent.getCurrentColor());
        repaint();
      }

      if (arg0.isButtonBHeld() && arg0.isButtonLeftHeld()) {
        frameComponent.undo();
        repaint();
      }
    }
コード例 #2
0
  @Override
  public void onButtonsEvent(WiimoteButtonsEvent arg0) {
    // Starts a new round if the current round is completed and the last button wasn't 1
    if (arg0.isButtonOnePressed() && lastPressed != arg0.getButtonsJustPressed()) {
      if (pressCounter != simon.size()) {
        for (Wiimote wiimote : wiimotes) {
          wiimote.activateRumble();
        }
        timer.start();
        simon.clear();
      } else {
        simon.add((int) (Math.random() * 4));
        currentSimon = 0;
        startSimon();
      }
      pressCounter = 0;
    }
    // checks if timer is running. If not running start Comparing of buttons to simon.
    if (!timer.isRunning()) {
      if (arg0.isButtonUpPressed()) {
        checkSimon(0);

      } else if (arg0.isButtonDownPressed()) {
        checkSimon(2);
      } else if (arg0.isButtonLeftPressed()) {
        checkSimon(1);
      } else if (arg0.isButtonRightPressed()) {
        checkSimon(3);
      } else {
        checkSimon(-1);
      }
      switch (arg0.getWiimoteId()) {
        case 1:
          player1++;
          break;
        case 2:
          player2++;
          break;
        case 3:
          player3++;
          break;
        case 4:
          player4++;
          break;
        default:
          break;
      }
    }
    // exits game if A&B are pressed together.
    if (arg0.isButtonAPressed() && arg0.isButtonBPressed()) {
      for (Wiimote wiimote : wiimotes) {
        wiimote.deactivateRumble();
      }
      System.exit(0);
    }
    // registers lastButtonPressed
    lastPressed = arg0.getButtonsJustPressed();
  }