Example #1
0
 @Override
 public Offer pickOffer(Offer[] aoffCurrentOffers) {
   System.out.println(
       "Player #" + intPlayerIndex + " (" + strClassName + "), your turn to pick a offer from: ");
   for (int intOfferIndex = 0; intOfferIndex < aoffCurrentOffers.length; intOfferIndex++) {
     if (aoffCurrentOffers[intOfferIndex].getOfferLive()
         && aoffCurrentOffers[intOfferIndex].getOfferedByIndex() != intPlayerIndex) {
       System.out.println(
           "Offer #" + intOfferIndex + ": " + aoffCurrentOffers[intOfferIndex].toString());
     }
   }
   System.out.println("(You have " + Game.arrayToString(aintInHand) + ") ");
   String strPickedOffer = Game.scnInput.nextLine();
   int intPickedOffer = Integer.parseInt(strPickedOffer);
   if (intPickedOffer >= 0 && intPickedOffer < aoffCurrentOffers.length) {
     if (aoffCurrentOffers[intPickedOffer].getOfferLive()) {
       int[] aintOffer = aoffCurrentOffers[intPickedOffer].getOffer();
       int[] aintDesire = aoffCurrentOffers[intPickedOffer].getDesire();
       for (int intColorIndex = 0; intColorIndex < intColorNum; intColorIndex++) {
         aintInHand[intColorIndex] += aintOffer[intColorIndex] - aintDesire[intColorIndex];
       }
       return aoffCurrentOffers[intPickedOffer];
     }
   }
   return null;
 }
Example #2
0
  public void eat(int[] aintTempEat) {
    // let the manual player know what's in hand
    System.out.println(
        "Player #"
            + intPlayerIndex
            + " ("
            + strClassName
            + "), You have: "
            + Game.arrayToString(aintInHand));

    // ask for action
    //		Scanner scnInput = new Scanner( System.in );
    System.out.println("What do you eat? (" + intColorNum + " colors)");
    String strEat = Game.scnInput.nextLine();
    String[] astrEat = strEat.split(",");
    for (int intColorIndex = 0; intColorIndex < intColorNum; intColorIndex++) {
      int intEatCurrentColorNum = Integer.parseInt(astrEat[intColorIndex]);
      if (intEatCurrentColorNum > aintInHand[intColorIndex]) {
        System.out.println(
            "You eat more than you have. Take it out of your mouth!"); // need more code to make it
                                                                       // more robust
      } else {
        aintInHand[intColorIndex] -= intEatCurrentColorNum;
      }
      aintTempEat[intColorIndex] = intEatCurrentColorNum;
    }
  }