Example #1
0
 public int isWon() {
   /*1 == lose, -1 == win*/
   int game_continue = 0;
   if (fortress.getHp() <= 0) {
     return 1;
   } else {
     for (Tank t : tanks) {
       if (t.getNumber_undamaged_cell() != 0) {
         return game_continue;
       }
     }
     return -1; // win
     //			for(int i =0; i<number_tanks;i++){
     //				if (tanks[i].getNumber_undamaged_cell()!=0){
     //					isAllTankDown = false;
     //				}
     //				if (isAllTankDown){
     //					return -1;
     //				}
     //			}
   }
 }
Example #2
0
  public int fireCannons(Cell cell, Tank[] tanks) {
    if (!cell.getHasBeenAttacked()) { // he cell has not been attacked, check if it is tank
      cell.setHasBeenAttacked(true);
      if (cell.getIsTank()) { // it is part of tank
        cell.setTankHit(true);
        for (Tank t : tanks) {
          if (t.getCells().contains(cell)) {
            t.setNumber_undamaged_cell(t.getNumber_undamaged_cell() - 1);
          }
        }
        return 1; // hit
      } else {

        return -1; // miss
      }

    } else { // the cell has been attacked, next check if it is tank and
      if (cell.isTankHit()) {
        return 0; // hit, but do nothing
      } else {
        return -1;
      }
    }
  }