Beispiel #1
0
  private boolean handleCommodityArea(Player player, List<Integer> c) {
    if (player.getPawnLeft() < 1 || c.size() == 7) {
      return false;
    }

    if (nPlayers == 2) {
      if (getOtherThan(c, player.getId()) > 0) {
        return false;
      }
      c.add(player.getId());
      player.putPawn();
      return true;
    } else if (nPlayers == 3) {
      if (getOtherThan(c, player.getId()) > 1) {
        return false;
      }
      c.add(player.getId());
      player.putPawn();
      return true;
    } else {
      c.add(player.getId());
      player.putPawn();
      return true;
    }
  }
Beispiel #2
0
 public boolean putPawn(Player player, int areaId) {
   switch (areaId) {
     case TouchAreas.FOOD_ID:
       if (player.getPawnLeft() > 1) {
         foodArea.add(player.getId());
         player.putPawn();
         return true;
       } else {
         return false;
       }
     case TouchAreas.WOOD_ID:
       return handleCommodityArea(player, woodArea);
     case TouchAreas.COPPER_ID:
       handleCommodityArea(player, copperArea);
     case TouchAreas.GOLD_ID:
       handleCommodityArea(player, goldArea);
     case TouchAreas.HUT_ID:
       if (hutArea == -1 && player.getPawnLeft() > 2) {
         hutArea = player.getId();
         player.putPawn();
         player.putPawn();
         return true;
       } else {
         return false;
       }
     case TouchAreas.FARM_ID:
       if (farmArea == -1 && player.getPawnLeft() > 1) {
         farmArea = player.getId();
         player.putPawn();
         return true;
       } else {
         return false;
       }
     case TouchAreas.FACTORY_ID:
       if (factoryArea == -1 && player.getPawnLeft() > 1) {
         factoryArea = player.getId();
         player.putPawn();
         return true;
       } else {
         return false;
       }
     case TouchAreas.BUILDING_1_ID:
       if (buildingAreas[0] == -1 && player.getPawnLeft() > 1) {
         buildingAreas[0] = player.getId();
         player.putPawn();
         return true;
       } else {
         return false;
       }
     case TouchAreas.BUILDING_2_ID:
       if (buildingAreas[1] == -1 && player.getPawnLeft() > 1) {
         buildingAreas[1] = player.getId();
         player.putPawn();
         return true;
       } else {
         return false;
       }
     case TouchAreas.BUILDING_3_ID:
       if (buildingAreas[2] == -1 && player.getPawnLeft() > 1) {
         buildingAreas[2] = player.getId();
         player.putPawn();
         return true;
       } else {
         return false;
       }
     case TouchAreas.BUILDING_4_ID:
       if (buildingAreas[3] == -1 && player.getPawnLeft() > 1) {
         buildingAreas[3] = player.getId();
         player.putPawn();
         return true;
       } else {
         return false;
       }
     case TouchAreas.CIVILIZATION_1_ID:
       if (civilisationAreas[0] == -1 && player.getPawnLeft() > 1) {
         civilisationAreas[0] = player.getId();
         player.putPawn();
         return true;
       } else {
         return false;
       }
     case TouchAreas.CIVILIZATION_2_ID:
       if (civilisationAreas[1] == -1 && player.getPawnLeft() > 1) {
         civilisationAreas[1] = player.getId();
         player.putPawn();
         return true;
       } else {
         return false;
       }
     case TouchAreas.CIVILIZATION_3_ID:
       if (civilisationAreas[2] == -1 && player.getPawnLeft() > 1) {
         civilisationAreas[2] = player.getId();
         player.putPawn();
         return true;
       } else {
         return false;
       }
     case TouchAreas.CIVILIZATION_4_ID:
       if (civilisationAreas[3] == -1 && player.getPawnLeft() > 1) {
         civilisationAreas[3] = player.getId();
         player.putPawn();
         return true;
       } else {
         return false;
       }
     default:
       return false;
   }
 }
Beispiel #3
0
 public int removePawns(Player player, int areaId) {
   int cpt = 0;
   List<Integer> tmp = new ArrayList<Integer>();
   switch (areaId) {
     case TouchAreas.FOOD_ID:
       for (Integer i : foodArea) {
         if (i != player.getId()) {
           tmp.add(i);
         } else {
           cpt++;
         }
       }
       foodArea = tmp;
       player.removePawns(cpt);
       return cpt;
     case TouchAreas.WOOD_ID:
       for (Integer i : woodArea) {
         if (i != player.getId()) {
           tmp.add(i);
         } else {
           cpt++;
         }
       }
       woodArea = tmp;
       player.removePawns(cpt);
       return cpt;
     case TouchAreas.COPPER_ID:
       for (Integer i : copperArea) {
         if (i != player.getId()) {
           tmp.add(i);
         } else {
           cpt++;
         }
       }
       copperArea = tmp;
       player.removePawns(cpt);
       return cpt;
     case TouchAreas.GOLD_ID:
       for (Integer i : goldArea) {
         if (i != player.getId()) {
           tmp.add(i);
         } else {
           cpt++;
         }
       }
       goldArea = tmp;
       player.removePawns(cpt);
       return cpt;
     case TouchAreas.STONE_ID:
       for (Integer i : goldArea) {
         if (i != player.getId()) {
           tmp.add(i);
         } else {
           cpt++;
         }
       }
       stoneArea = tmp;
       player.removePawns(cpt);
       return cpt;
       // TODO: gérer le nombre de pions dans le village en fonction du
       // nombre de joueurs
     case TouchAreas.HUT_ID:
       if (hutArea == player.getId()) {
         hutArea = -1;
         player.removePawns(2);
         return 2;
       } else {
         return 0;
       }
     case TouchAreas.FARM_ID:
       if (farmArea == player.getId()) {
         farmArea = -1;
         player.removePawns(1);
         return 1;
       } else {
         return 0;
       }
     case TouchAreas.FACTORY_ID:
       if (factoryArea == player.getId()) {
         factoryArea = -1;
         player.removePawns(1);
         return 1;
       } else {
         return 0;
       }
     case TouchAreas.BUILDING_1_ID:
       if (buildingAreas[0] == player.getId()) {
         buildingAreas[0] = -1;
         player.removePawns(1);
         return 0;
       } else {
         return -1;
       }
     case TouchAreas.BUILDING_2_ID:
       if (buildingAreas[1] == player.getId()) {
         buildingAreas[1] = -1;
         player.removePawns(1);
         return 1;
       } else {
         return 0;
       }
     case TouchAreas.BUILDING_3_ID:
       if (buildingAreas[2] == player.getId()) {
         buildingAreas[2] = -1;
         player.removePawns(1);
         return 1;
       } else {
         return 0;
       }
     case TouchAreas.BUILDING_4_ID:
       if (buildingAreas[3] == player.getId()) {
         buildingAreas[3] = -1;
         player.removePawns(1);
         return 1;
       } else {
         return 0;
       }
     case TouchAreas.CIVILIZATION_1_ID:
       if (civilisationAreas[0] == player.getId()) {
         civilisationAreas[0] = -1;
         player.removePawns(1);
         return 1;
       } else {
         return 0;
       }
     case TouchAreas.CIVILIZATION_2_ID:
       if (civilisationAreas[1] == player.getId()) {
         civilisationAreas[1] = -1;
         player.removePawns(1);
         return 1;
       } else {
         return 0;
       }
     case TouchAreas.CIVILIZATION_3_ID:
       if (civilisationAreas[2] == player.getId()) {
         civilisationAreas[2] = -1;
         player.removePawns(1);
         return 1;
       } else {
         return 0;
       }
     case TouchAreas.CIVILIZATION_4_ID:
       if (civilisationAreas[3] == player.getId()) {
         civilisationAreas[3] = -1;
         player.removePawns(1);
         return 1;
       } else {
         return 0;
       }
     default:
       return 0;
   }
 }