Exemplo n.º 1
0
  /** ターン終了時の処理 */
  private void endTurn() {
    //  ぶつかったときの処理
    //  1セルごとに検索

    for (int i = 0; i < 9; i++) { //  yについて
      for (int j = 0; j < 9; j++) { //  xについて
        ArrayList<Integer> unit0 = new ArrayList<Integer>();
        ArrayList<Integer> unit1 = new ArrayList<Integer>();
        //  同じ位置にいるものを追加
        for (int k = 0; k < 4; k++) {
          if (unitLocation[0][k].x == j && unitLocation[0][k].y == i) {
            unit0.add(k);
          }
          if (unitLocation[1][k].x == j && unitLocation[1][k].y == i) {
            unit1.add(k);
          }
        }
        //  重なったユニット同士でバトル
        int result = battleUnits(unit0, unit1);
        switch (result) {
          case 0: //  player0の勝利
            backUnits(unit1, 1);
            for (int var : unit1) {
              teamPoint[0] += 2;
            }
            break;
          case 1: //  player1の勝利
            backUnits(unit0, 0);
            for (int var : unit0) {
              teamPoint[1] += 2;
            }
            break;
          case 2: //  引き分
            backUnits(unit0, 0);
            backUnits(unit1, 1);
            break;
          default: //   元に戻す処理
            break;
        }
      }
    }

    //  ターン終了時にその位置にいて、タワーの所持者が異なる場合タワーを塗り替える
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 3; j++) {
        if (this.unitLocation[0][i].equals(towerPos[j]) && this.towerHold[j] != 0) {
          this.towerHold[j] = 0;
          // System.out.println("タワーを0に塗り替えた");
          //  ポイント加算
          this.teamPoint[0]++;
        } else if (this.unitLocation[1][i].equals(towerPos[j]) && this.towerHold[j] != 1) {
          this.towerHold[j] = 1;
          // System.out.println("タワーを1に塗り替えた");
          //  ポイント加算
          this.teamPoint[1]++;
        }
      }
    }

    //  タワー保持によるボーナス
    calcTowerPoint();
  }