コード例 #1
0
 // Action Listener interface method
 public void actionPerformed(ActionEvent event) {
   Object target = event.getSource();
   if (target == sineButton) {
     // System.out.println ("AE1 JButton sineButton selected");
   } else if (target == squareButton) {
     // System.out.println ("AE2 JButton squareButton selected");
   } else if (target == sawtoothButton) {
     // System.out.println ("AE3 JButton sawtoothButton selected");
   } else if (target == triangleButton) {
     // System.out.println ("AE4 JButton triangleButton selected");
   } else if (target == exitButton) {
     // System.out.println ("AE5 JButton exitButton selected");
     System.exit(0);
   } else {
   } // if
 } // actionPerformed ()
コード例 #2
0
  public void actionPerformed(ActionEvent a) {
    Object source = a.getSource();

    if (scene == OVERWORLD) {
      if (source == moveTimer) {
        if (moveUp && !moveDown) player.moveUp();
        else if (!moveUp && moveDown) player.moveDown();

        if (moveLeft && !moveRight) player.moveLeft();
        else if (!moveLeft && moveRight) player.moveRight();
      }

      if (source == itemsButton) itemsButton.setText("ITEMS!");
      else if (source == equipButton) equipButton.setText("EQUIPMENT!");
      else if (source == skillsButton) skillsButton.setText("SKILLS");
      else if (source == settingsButton) settingsButton.setText("SETTINGS");
      else if (source == statusButton) statusButton.setText("STATUS");
      else if (source == dataButton) dataButton.setText("DATA");
    }
    if (scene == BATTLE) {
      if (source == moveTimer) {
        // Spell Movement
        for (int spellNum = 0; spellNum < spellsThrown.size(); spellNum++) {
          Spell spell = spellsThrown.get(spellNum);
          spell.move();
          if (spell.spellHit()) {
            enemies.get(spell.getTarget()).takeDamage(spell.getDamage());
            enemies.get(spell.getTarget()).statusPresent(spell.getEffect());
            spellsThrown.remove(spellNum);
            checkEnemyPresence();
          }
        }

        for (int enemyLoop = 0; enemyLoop < enemies.size(); enemyLoop++) {
          Enemy enemy = enemies.get(enemyLoop);
          for (int spellNum = 0; spellNum < enemy.spellsThrown.size(); spellNum++) {
            Spell spell = enemy.spellsThrown.get(spellNum);
            spell.move();
            if (spell.spellHit()) {
              player.takeDamage(spell.getDamage());
              enemy.spellsThrown.remove(spellNum);
              checkAllyPresence();
            }
          }
        }
      }
      if (source == staminaTimer) {
        // Stamina Regeneration
        player.staminaGain(16);
        // Enemy Attacks
        int enemyLoop;
        for (enemyLoop = 0; enemyLoop < enemies.size(); enemyLoop++) {
          enemies.get(enemyLoop).attack(player.centerX(), player.centerY(), 12);
        }
      }
    }
    repaint();

    // To check collision
    if (scene == OVERWORLD) {
      for (int loop = 0; loop < enemies.size(); loop++) {
        Enemy enemy = enemies.get(loop);
        if (enemy.hitbox().intersects(player.hitbox())) {
          player.combatChange(true);
          enemy.combatChange(true);
          battleBegin();
        }
      }
    }
  }