Example #1
0
 // checks if the button pressed is the same as the one in the simon arraylist of the current round
 // rumbles and ends round if wrong
 public void checkSimon(int button) {
   try {
     if (button == simon.get(pressCounter)) {
       changedColorLocation = simon.get(pressCounter) % 4;
       changedColor = colors.get(changedColorLocation);
       colors.set(changedColorLocation, Color.PINK);
       timer.start();
       pressCounter++;
     } else {
       for (Wiimote wiimote : wiimotes) {
         wiimote.activateRumble();
       }
       timer.start();
       simon.clear();
       pressCounter = 0;
       currentSimon = 0;
     }
   } catch (Exception e) {
     for (Wiimote wiimote : wiimotes) {
       wiimote.activateRumble();
     }
     timer.start();
     simon.clear();
     pressCounter = 0;
     currentSimon = 0;
   }
 }
Example #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();
  }
Example #3
0
 // Changes color back to the original one
 // Also stops timer and rumble if necesairy
 public void changeColorBack() {
   for (Wiimote wiimote : wiimotes) {
     wiimote.deactivateRumble();
   }
   colors.set(changedColorLocation, changedColor);
   if (simon.size() - 1 > currentSimon) {
     currentSimon++;
     startSimon();
   }
 }
Example #4
0
 public Tests(Wiimote wim) {
   wiimote = wim;
   wiimote.addWiiMoteEventListeners(this);
   try {
     robot = new Robot();
   } catch (AWTException e) {
     e.printStackTrace();
   }
 }
Example #5
0
 public void snake() throws InterruptedException {
   remote.setLeds(true, false, false, false);
   Thread.sleep(200);
   remote.setLeds(true, true, false, false);
   Thread.sleep(200);
   remote.setLeds(false, true, false, false);
   Thread.sleep(200);
   remote.setLeds(false, true, true, false);
   Thread.sleep(200);
   remote.setLeds(false, false, true, false);
   Thread.sleep(200);
   remote.setLeds(false, false, true, true);
   Thread.sleep(200);
   remote.setLeds(false, false, false, true);
   Thread.sleep(200);
   remote.setLeds(true, false, false, true);
   Thread.sleep(200);
 }
Example #6
0
  public WiiMoteTracker() {
    // adds button colors to array
    colors.add(Color.RED);
    colors.add(Color.BLUE);
    colors.add(Color.YELLOW);
    colors.add(Color.GREEN);

    // Searching for WiiRemotes
    wiimotes = WiiUseApiManager.getWiimotes(4, true);
    // checking if there are wii remotes connected. If so set led 2,3,4 on
    // else exit program
    int wiimoteNumber = 0;
    for (Wiimote wiimote : wiimotes) {
      switch (wiimoteNumber) {
        case 0:
          wiimote.setLeds(true, false, false, false);
          break;
        case 1:
          wiimote.setLeds(false, true, false, false);
          break;
        case 2:
          wiimote.setLeds(false, false, true, false);
          break;
        case 3:
          wiimote.setLeds(false, false, false, true);
          break;
      }
      wiimoteNumber++;
      wiimote.addWiiMoteEventListeners(this);
    }

    if (wiimotes == null) {
      System.out.println("No Wii Remotes found");
      System.exit(0);
    }

    // Timer which on tick changes the color of the rectangle back to the original one.
    ActionListener update =
        new ActionListener() {

          @Override
          public void actionPerformed(ActionEvent arg0) {
            timer.stop();
            changeColorBack();
          }
        };
    // time the color stays changed
    timer = new Timer(500, update);
  }
Example #7
0
  public void init() {
    Wiimote[] wiimotes = WiiUseApiManager.getWiimotes(1, true);
    remote = wiimotes[0];
    remote.activateIRTRacking();
    remote.activateMotionSensing();
    remote.addWiiMoteEventListeners(
        new WiimoteListener() {
          // REDUNDANT
          public void onStatusEvent(StatusEvent arg0) {}

          public void onNunchukRemovedEvent(NunchukRemovedEvent arg0) {}

          public void onNunchukInsertedEvent(NunchukInsertedEvent arg0) {}

          public void onMotionSensingEvent(MotionSensingEvent arg0) {}

          public void onIrEvent(IREvent arg0) {}

          public void onGuitarHeroRemovedEvent(GuitarHeroRemovedEvent arg0) {}

          public void onGuitarHeroInsertedEvent(GuitarHeroInsertedEvent arg0) {}

          public void onExpansionEvent(ExpansionEvent arg0) {}

          public void onDisconnectionEvent(DisconnectionEvent arg0) {}

          public void onClassicControllerRemovedEvent(ClassicControllerRemovedEvent arg0) {}

          public void onClassicControllerInsertedEvent(ClassicControllerInsertedEvent arg0) {}

          // NOT REDUNDANT
          public void onButtonsEvent(WiimoteButtonsEvent arg0) {
            if (arg0.isButtonUpJustReleased() && !GameLogic.getInstance().isDisplaying()) {
              ViewLogic.getInstance().selectUpwards();
            }
            if (arg0.isButtonDownJustReleased() && !GameLogic.getInstance().isDisplaying()) {
              ViewLogic.getInstance().selectDownwards();
            }
            if (arg0.isButtonLeftJustReleased() && !GameLogic.getInstance().isDisplaying()) {
              ViewLogic.getInstance().selectLeft();
            }
            if (arg0.isButtonRightJustReleased() && !GameLogic.getInstance().isDisplaying()) {
              ViewLogic.getInstance().selectRight();
            }
            if (arg0.isButtonOneJustReleased() && !GameLogic.getInstance().isPlaying()) {
              GameLogic.getInstance().generateNext();
              GameLogic.getInstance().highlightSequence();
              GameLogic.getInstance().togglePlaying();
            }
            if (arg0.isButtonAJustReleased()) {
              if (GameLogic.getInstance().isPlaying()) {
                boolean isCorrect = GameLogic.getInstance().checkInput();
                if (isCorrect) {
                  if (GameLogic.getInstance().getcurrentPoint() == 0) {
                    GameLogic.getInstance().generateNext();
                    GameLogic.getInstance().highlightSequence();
                  }
                } else {
                  remote.activateRumble();

                  try {
                    Thread.sleep(1500);
                  } catch (InterruptedException e) {
                  }
                  remote.deactivateRumble();
                  GameLogic.getInstance().reset();
                  GameLogic.getInstance().togglePlaying();
                }
              }
            }
            if (arg0.isButtonAHeld() && arg0.isButtonBHeld()) {
              System.exit(0);
            }
            if (arg0.isButtonAHeld()) aHeld = true;
            else aHeld = false;
          }
        });
  }
Example #8
0
  public void onButtonsEvent(ButtonsEvent e) {
    if (dump == DISPLAY_EACH_VALUE) {
      // System.out.println("*********** WIIMOTE ID : "+
      // e.getWiimoteId() + " **************");
      /* button ONE */
      if (e.isButtonOneJustPressed()) {
        System.out.println("button one pressed");
      }
      if (e.isButtonOneHeld()) {
        System.out.println("button one held");
      }
      if (e.isButtonOneJustReleased()) {
        System.out.println("button one released");
      }

      /* button TWO */
      if (e.isButtonTwoJustPressed()) {
        System.out.println("button two pressed");
      }
      if (e.isButtonTwoHeld()) {
        System.out.println("button two held");
      }
      if (e.isButtonTwoJustReleased()) {
        System.out.println("button two released");
      }

      /* button A */
      if (e.isButtonAJustPressed()) {
        System.out.println("button A pressed");
      }
      if (e.isButtonAHeld()) {
        System.out.println("button A held");
      }
      if (e.isButtonAJustReleased()) {
        System.out.println("button A released");
      }

      /* button B */
      if (e.isButtonBJustPressed()) {
        System.out.println("button B pressed");
      }
      if (e.isButtonBHeld()) {
        System.out.println("button B held");
      }
      if (e.isButtonBJustReleased()) {
        System.out.println("button B released");
      }

      /* button LEFT */
      if (e.isButtonLeftJustPressed()) {
        System.out.println("button Left pressed");
      }
      if (e.isButtonLeftHeld()) {
        System.out.println("button Left held");
      }
      if (e.isButtonLeftJustReleased()) {
        System.out.println("button Left released");
      }

      /* button RIGHT */
      if (e.isButtonRightJustPressed()) {
        System.out.println("button Right pressed");
      }
      if (e.isButtonRightHeld()) {
        System.out.println("button Right held");
      }
      if (e.isButtonRightJustReleased()) {
        System.out.println("button Right released");
      }

      /* button UP */
      if (e.isButtonUpJustPressed()) {
        System.out.println("button UP pressed");
      }
      if (e.isButtonUpHeld()) {
        System.out.println("button UP held");
      }
      if (e.isButtonUpJustReleased()) {
        System.out.println("button UP released");
      }

      /* button DOWN */
      if (e.isButtonDownJustPressed()) {
        System.out.println("button DOWN pressed");
      }
      if (e.isButtonDownHeld()) {
        System.out.println("button DOWN held");
      }
      if (e.isButtonDownJustReleased()) {
        System.out.println("button DOWN released");
      }

      /* button MINUS */
      if (e.isButtonMinusJustPressed()) {
        System.out.println("button MINUS pressed");
      }
      if (e.isButtonMinusHeld()) {
        System.out.println("button MINUS held");
      }
      if (e.isButtonMinusJustReleased()) {
        System.out.println("button MINUS released");
      }

      /* button PLUS */
      if (e.isButtonPlusJustPressed()) {
        System.out.println("button PLUS pressed");
      }
      if (e.isButtonPlusHeld()) {
        System.out.println("button PLUS held");
      }
      if (e.isButtonPlusJustReleased()) {
        System.out.println("button PLUS released");
      }

      /* button HOME */
      if (e.isButtonHomeJustPressed()) {
        System.out.println("button HOME pressed");
      }
      if (e.isButtonHomeHeld()) {
        System.out.println("button HOME held");
      }
      if (e.isButtonHomeJustReleased()) {
        System.out.println("button HOME released");
      }

      /* get status */
      if (e.isButtonUpJustPressed()) {
        wiimote.getStatus();
      }

      /* Activate rumble */
      if (e.isButtonOneJustPressed()) {
        System.out.println("Rumble Activated");
        wiimote.activateRumble();
      }
      if (e.isButtonTwoJustPressed()) {
        System.out.println("Rumble Deactivated");
        wiimote.deactivateRumble();
      }

      /* Activate IR Tracking */
      if (e.isButtonAJustPressed()) {
        System.out.println("IR Activated");
        wiimote.activateIRTRacking();
      }
      if (e.isButtonBJustPressed()) {
        System.out.println("IR Deactivated");
        wiimote.deactivateIRTRacking();
      }

      /* Activate Motion sensing */
      if (e.isButtonPlusJustPressed()) {
        System.out.println("Motion sensing Activated");
        wiimote.activateMotionSensing();
      }
      if (e.isButtonMinusJustPressed()) {
        System.out.println("Motion sensing Deactivated");
        wiimote.deactivateMotionSensing();
      }

      /* leave test */
      if (e.isButtonHomeJustPressed()) {
        System.out.println("LEAVING TEST");
        wiimote.disconnect();
      }

    } else if (dump == DUMP) {
      System.out.println(e);
      /* Activate all */
      if (e.isButtonAJustPressed()) {
        System.out.println("IR, rumble and motion sensing Activated");
        wiimote.activateIRTRacking();
        wiimote.activateMotionSensing();
        wiimote.activateRumble();
      }
      if (e.isButtonBJustPressed()) {
        System.out.println("IR, rumble and motion sensing Deactivated");
        wiimote.deactivateIRTRacking();
        wiimote.deactivateMotionSensing();
        wiimote.deactivateRumble();
      }

      /* leave test */
      if (e.isButtonHomeJustPressed()) {
        System.out.println("LEAVING TEST");
        wiimote.disconnect();
      }
    } else if (dump == MOVE_MOUSE) {
      /* Activate IR Tracking */
      if (e.isButtonOneJustPressed()) {
        System.out.println("IR Activated");
        wiimote.activateIRTRacking();
      }
      if (e.isButtonTwoJustPressed()) {
        System.out.println("IR Deactivated");
        wiimote.deactivateIRTRacking();
      }

      /* button A */
      if (e.isButtonAJustPressed()) {
        robot.mousePress(InputEvent.BUTTON1_MASK);
      }
      if (e.isButtonAJustReleased()) {
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
      }

      /* button B */
      if (e.isButtonBJustPressed()) {
        robot.mousePress(InputEvent.BUTTON2_MASK);
      }
      if (e.isButtonBJustReleased()) {
        robot.mouseRelease(InputEvent.BUTTON2_MASK);
      }

      /* leave test */
      if (e.isButtonHomeJustPressed()) {
        System.out.println("LEAVING TEST");
        wiimote.disconnect();
      }
    } else if (dump == TEST_LEDS) {
      wiimote.activateMotionSensing();
      if (e.isButtonUpJustPressed()) {
        wiimote.setLeds(true, false, false, false);
      }
      if (e.isButtonDownJustPressed()) {
        wiimote.setLeds(false, true, false, false);
      }
      if (e.isButtonLeftJustPressed()) {
        wiimote.setLeds(false, false, true, false);
      }
      if (e.isButtonRightJustPressed()) {
        wiimote.setLeds(false, false, false, true);
      }

      /* leave test */
      if (e.isButtonHomeJustPressed()) {
        System.out.println("LEAVING TEST");
        wiimote.disconnect();
      }
    }
  }