예제 #1
0
파일: Invader.java 프로젝트: FJWR/robocode
 @Override
 protected void cbExtMessage(MessageEvent e) {
   Serializable event = e.getMessage();
   if (event instanceof InvaderEvent) {
     InvaderEvent ev = (InvaderEvent) event;
     if (ev.kind == 1) {
       firstPoint = new TimedPoint(ev.first, ctx.my.time);
     } else if (ev.kind == 2) {
       readyCount++;
     } else if (ev.kind == 3) {
       openFire();
     }
   } else {
     super.cbExtMessage(e);
   }
 }
  public void onMessageReceived(MessageEvent e) {
    System.out.println(
        "START at : " + getTime() + " onMessageReceived----------------------------");
    // メッセージを受け取った時
    System.out.println("receive Message");
    if (e.getMessage() instanceof String) {
      boolean flag = false;
      String raw = (String) e.getMessage();
      enemy_data = raw.split(", ", -1);
      Enemy_info enem = null;
      String nnn = enemy_data[0];

      if (raw.indexOf("Kill") != -1) {
        System.out.println("Receive kill instruction!!");
        for (Enemy_info temp : enes) {
          if (enemy_data[1].equals(temp.get_en_name())) {
            target_enemy = temp;
            enemy_detected = true;
          }
        }
      } else {
        try {
          for (Enemy_info temp : enes) {
            if (nnn.equals(temp.get_en_name())) {
              // スキャンした敵がLocal敵リストの中に存在する
              flag = true;
              enem = temp; // 参照のコピー
              // Local敵リストの情報をアップデート
              temp.updateInformation(
                  Double.parseDouble(enemy_data[1]),
                  Double.parseDouble(enemy_data[2]),
                  Double.parseDouble(enemy_data[3]),
                  Double.parseDouble(enemy_data[4]),
                  Double.parseDouble(enemy_data[5]),
                  Double.parseDouble(enemy_data[6]),
                  Double.parseDouble(enemy_data[7]),
                  Double.parseDouble(enemy_data[8]),
                  Double.parseDouble(enemy_data[9]));
              System.out.println("	update received Info");
            }
          }
          if (!flag) {
            // スキャンした敵がLocal敵リストの中に存在しない
            //// Local敵リストの情報を新規追加
            enem =
                new Enemy_info(
                    nnn,
                    Double.parseDouble(enemy_data[1]),
                    Double.parseDouble(enemy_data[2]),
                    Double.parseDouble(enemy_data[3]),
                    Double.parseDouble(enemy_data[4]),
                    Double.parseDouble(enemy_data[5]),
                    Double.parseDouble(enemy_data[6]),
                    Double.parseDouble(enemy_data[7]),
                    Double.parseDouble(enemy_data[8]),
                    Double.parseDouble(enemy_data[9]));
            enes.add(enem);
            System.out.println("	add received info");
          }
        } catch (ArrayIndexOutOfBoundsException e2) {
          System.out.println("ArrayIndexOutOfBoundsException");
          for (String n : enemy_data) {
            System.out.println(n);
          }
        }
        if (enemy_detected == false) {
          enemy_detected = true;
          target_enemy = enem;
        }
      }
    }
    System.out.println("target is " + target_enemy.get_en_name());
    System.out.println("enemy_detected = " + enemy_detected);
    System.out.println("END at : " + getTime() + " onMessageReceived----------------------------");
  }