public void msgNewOrder(WaiterAgent w, int tableNum, String order) {
    print("msgNewOrder() from Waiter " + w.getName());
    long timeFinish = -1;
    if (findFood(order).amount > 0) {
      timeFinish =
          (System.currentTimeMillis() + (long) ((menu.menuItems.get(order)) * Constants.SECOND));
      int previousInventoryAmount = inventory.get(order);
      inventory.put(order, previousInventoryAmount - 1);
      print("Number of items of type " + order + " left: " + inventory.get(order));

      Order incomingOrder = new Order(w, tableNum, order, timeFinish);
      orders.add(incomingOrder);
      Food f = findFood(order);
      f.amount--;
      if (f.amount <= f.low) {
        marketOrders.add(new MarketOrder(f.choice, f.capacity - f.amount));
        f.ordered = true;
      }
    } else {
      Order incomingOrder = new Order(w, tableNum, order, timeFinish);
      incomingOrder.state = OrderState.UnableToBeSupplied;
      menu.menuList.remove(order);
      orders.add(incomingOrder);
      Food f = findFood(order);
      marketOrders.add(new MarketOrder(f.choice, f.capacity - f.amount));
    }
    stateChanged();
  }
  public void deleteTransaction(Transaction transaction) {
    int transactionId = transaction.getTransactionId();
    int foodId = transaction.getFoodId();
    String deletedTime = transaction.getStrTimeStamp();

    SQLiteDatabase db_write = this.getWritableDatabase();
    db_write.delete(
        TABLE_TRANSACTION, TRANSACTION_ID + "=" + Integer.toString(transactionId), null);
    Log.d("deleteTransaction", "id=" + Integer.toString(transactionId));
    db_write.close();

    SQLiteDatabase db_read = this.getReadableDatabase();
    Cursor cursor =
        db_read.rawQuery(
            GET_LATEST_TRANSACTION_TIME_FOR_FOOD, new String[] {Integer.toString(foodId)});
    String lastTransactionTime;
    if (cursor.getCount() > 0) {
      cursor.moveToFirst();
      lastTransactionTime = cursor.getString(0);
    } else {
      lastTransactionTime = "";
    }
    db_read.close();

    Food food = getFood(foodId);
    food.setFrequency(food.getFrequency() - 1);
    food.setStrLastTransaction(lastTransactionTime);
    Log.d("INFO", food.toString());
    updateFood(foodId, food);
  }
 public void setQuantity(String name, int num) {
   for (Food food : foods) {
     if (food.choice.equals(name)) {
       food.amount = num;
     }
   }
 }
Beispiel #4
0
 private void addDish() {
   foodTimerDiff = (System.nanoTime() - foodTimer) / 1000000;
   if (foodTimerDiff > foodDelay) { // there will be a 88% chance the next dish will be food
     double chance = Math.random();
     int rail = (int) Math.round(Math.random() * 2);
     if (chance < foodprobability) {
       String food = foodList.get((int) (Math.random() * foodList.size()) % foodList.size());
       Food f = new Food(food, rail, foodValues.get(food));
       f.setPositionInRail(player.getx() + GamePanel.WIDTH + f.getWidth() / 2, rail);
       f.setCamera(camera);
       dishes.add(f);
     } else {
       String power = powerList.get((int) (Math.random() * powerList.size()) % powerList.size());
       Power p = new Power(power, rail);
       p.setPositionInRail(player.getx() + GamePanel.WIDTH + p.getWidth() / 2, rail);
       p.setCamera(camera);
       dishes.add(p);
     }
     foodTimer = System.nanoTime();
     if (difficulty == OptionsState.EASY)
       foodDelay = (long) (Math.random() * fooddelays[0]) + fooddelays[1];
     if (difficulty == OptionsState.NORMAL)
       foodDelay = (long) (Math.random() * fooddelays[2]) + fooddelays[3];
     if (difficulty == OptionsState.HARD)
       foodDelay = (long) (Math.random() * fooddelays[4]) + fooddelays[5];
   }
 }
 /**
  * Makes the player eat the specified food
  *
  * @param food - Specified food to eat
  */
 public void eat(Food food) {
   if (hasFood(food, 1)) {
     removeFood(food, 1);
     increaseHealth(food.getHealthRegenAmount());
   } else {
     Sys.print("You don't have any " + food.getName() + " to eat!");
   }
 }
Beispiel #6
0
 /**
  * eat food decrease hunger meter and increase in satiability
  *
  * @param food
  */
 public void eat(Food food) {
   // eat Meal or Snack; modifies happinessMeter and hungerMeter
   this.happinessMeter += food.getTastiness();
   this.hungerMeter -= food.getSatiability();
   this.size += food.getFat();
   if (this.hungerMeter <= 0) {
     this.hungerMeter = 0;
   }
 }
 public Food getFood(int id) {
   SQLiteDatabase db = this.getReadableDatabase();
   Cursor cursor =
       db.rawQuery(
           "SELECT  * FROM " + TABLE_FOODS + " WHERE " + FOOD_ID + " =? ",
           new String[] {Integer.toString(id)});
   if (cursor != null) cursor.moveToFirst();
   Food food = getFoodFromCursor(cursor);
   Log.d("getFood(" + id + ")", food.getFood_name());
   cursor.close();
   return food;
 }
Beispiel #8
0
    public void bindFood(Food food) {
      mFood = food;
      if (mFood == null) {
        Log.d("Imirire", "Got a null food object");
      } else {
        foodItemCheckBox.setChecked(mFood.isChecked());
        foodNameTextView.setText(mFood.getFoodName().toString());

        if (mFood.getGramCount() != 0.0) {
          gramInputField.setText(String.valueOf(mFood.getGramCount()));
        }
      }
    }
Beispiel #9
0
  /**
   * We have to handle cheese by itself because the barrel recipe manager doesnt take kindly to null
   * input items.
   */
  private boolean handleCheese() {
    ItemStack inIS = this.getInputStack();
    if (this.getSealed()
        && this.fluid != null
        && this.fluid.getFluid() == TFCFluids.MILKCURDLED
        && (inIS == null
            || inIS.getItem() instanceof IFood
                && ((IFood) inIS.getItem()).getFoodGroup() != EnumFoodGroup.Dairy
                && ((IFood) inIS.getItem()).isEdible(inIS)
                && Food.getWeight(inIS) <= 20.0f)) {
      recipe =
          new BarrelRecipe(
                  null,
                  new FluidStack(TFCFluids.MILKCURDLED, 10000),
                  ItemFoodTFC.createTag(new ItemStack(TFCItems.cheese, 1), 160),
                  null)
              .setMinTechLevel(0);
      if (!worldObj.isRemote) {
        int time = 0;
        if (sealtime > 0) time = (int) TFC_Time.getTotalHours() - sealtime;
        else if (unsealtime > 0) time = (int) TFC_Time.getTotalHours() - unsealtime;

        // Make sure that the recipe meets the time requirements
        if (time < recipe.sealTime) return true;
        float w = this.fluid.amount / 62.5f;

        ItemStack is = ItemFoodTFC.createTag(new ItemStack(TFCItems.cheese), w);

        if (inIS != null && inIS.getItem() instanceof IFood) {
          int[] profile = Food.getFoodTasteProfile(inIS);
          float ratio =
              Math.min(
                  (Food.getWeight(getInputStack()) - Food.getDecay(inIS))
                      / (Global.FOOD_MAX_WEIGHT / 8),
                  1.0f);
          Food.setSweetMod(is, (int) Math.floor(profile[INPUT_SLOT] * ratio));
          Food.setSourMod(is, (int) Math.floor(profile[1] * ratio));
          Food.setSaltyMod(is, (int) Math.floor(profile[2] * ratio));
          Food.setBitterMod(is, (int) Math.floor(profile[3] * ratio));
          Food.setSavoryMod(is, (int) Math.floor(profile[4] * ratio));
          Food.setInfusion(is, inIS.getItem().getUnlocalizedName());
          this.storage[INPUT_SLOT] = null;
        }

        this.actionEmpty();
        this.setInventorySlotContents(0, is);
      }
      return true;
    }
    return false;
  }
Beispiel #10
0
 private FoodProxy addToUserFoodsIfMissing(String source, Food f) {
   FoodDataSource allegedSource = Datasources.getSource(source);
   if (allegedSource != null) {
     FoodProxy f2 = allegedSource.getFoodProxy(f.getSourceUID());
     if (f2 != null) {
       if (f2.getFood().equals(f)) {
         return f2;
       }
     }
   }
   // TODO: scan all foods for identical matches first!
   Datasources.getUserFoods().addFood(f);
   return f.getProxy();
 }
  public static void main(String[] args) throws SAXException, IOException {

    // создание DOM-анализатора (Xerces)

    DOMParser parser = new DOMParser();
    parser.parse("test.xml");
    Document document = parser.getDocument();
    Element root = document.getDocumentElement();
    List<Food> menu = new ArrayList<Food>();

    NodeList foodNodes = root.getElementsByTagName("food");
    Food food = null;

    for (int i = 0; i < foodNodes.getLength(); i++) {
      food = new Food();
      Element foodElement = (Element) foodNodes.item(i);

      food.setId(Integer.parseInt(foodElement.getAttribute("id")));
      food.setName(getSingleChild(foodElement, "name").getTextContent().trim());
      food.setDescription(getSingleChild(foodElement, "description").getTextContent().trim());
      menu.add(food);
    }

    for (Food f : menu) {
      System.out.println(f.getName() + ", " + f.getId() + ", " + f.getDescription());
    }
  }
  public static void main(String[] args) {
    GoodsShip<Electronic> gs1 = new GoodsShip<Electronic>();
    gs1.boxing(new Electronic("배송시작"));
    Electronic e1 = (Electronic) gs1.unBoxing();
    e1.currentState();

    GoodsShip<Food> gs2 = new GoodsShip<Food>();
    gs2.boxing(new Food("배송중"));
    Food f1 = (Food) gs2.unBoxing();
    f1.currentState();

    //		GoodsShip<Food> gs3 = new GoodsShip<Food>();
    //		gs3.boxing("식품");
    //		Food f2 = (Food) gs3.unBoxing();
    //		f2.currentState();
  }
 private void deleteFoodAssociations(Accompaniment root) {
   List<Food> foods = foodDAO.listByAccompanimentId(root.getId());
   for (Food food : foods) {
     Collection<Accompaniment> accompaniments = accompanimentDAO.listByFoodId(food.getId());
     Collection<Accompaniment> retainAll = new ArrayList<Accompaniment>();
     for (Accompaniment accompaniment : accompaniments) {
       if (!accompaniment.getId().equals(root.getId())) {
         retainAll.add(accompaniment);
       }
     }
     accompaniments.retainAll(retainAll);
     food.setAccompaniments(new HashSet<Accompaniment>(accompaniments));
     foodDAO.update(food);
   }
   root.setFoods(null);
 }
 public void msgHereIsOrder(String choice, int amount, int id) {
   print("Received a delivery of " + amount + " " + choice + "'s from the market!");
   for (int i = 0; i < marketOrders.size(); i++) {
     MarketOrder mo = marketOrders.get(i);
     if (mo.id == id && mo.amount == amount) {
       Food f = findFood(mo.food);
       f.amount = amount;
       print("removing a market order whee");
       marketOrders.remove(mo);
     } else if (mo.food == choice && mo.amount != 0) {
       Food f = findFood(mo.food);
       f.amount = amount + mo.amount;
       mo.amount -= amount;
     }
   }
 }
  @Override
  public void execute(Hero hero, String action) {

    super.execute(hero, action);

    if (action.equals(AC_EAT)) {

      switch (Random.Int(5)) {
        case 0:
          GLog.w("Oh it's hot!");
          Buff.affect(hero, Burning.class).reignite(hero);
          break;
        case 1:
          GLog.w("You can't feel your legs!");
          Buff.prolong(hero, Roots.class, Paralysis.duration(hero));
          break;
        case 2:
          GLog.w("You are not feeling well.");
          Buff.affect(hero, Poison.class).set(Poison.durationFactor(hero) * hero.HT / 5);
          break;
        case 3:
          GLog.w("You are stuffed.");
          Buff.prolong(hero, Slow.class, Slow.duration(hero));
          break;
      }
    }
  }
 public void updateFood(int id, Food food) {
   Log.d("updateFood", food.getFood_name());
   SQLiteDatabase db = this.getWritableDatabase();
   ContentValues values = putFoodToContentValues(food);
   db.update(TABLE_FOODS, values, FOOD_ID + "=" + id, null);
   db.close();
 }
 /*
 Order(Cook cook, Food f, int amount) {
 	c = cook;
 	food = f;
 	f.orderamt = amount;
 	s = OrderState.pending;
 }*/
 Order(ItalianCook cook, Food f, int amount, int left) {
   c = cook;
   food = f;
   f.orderamt = amount;
   leftover = left;
   s = OrderState.pending;
 }
Beispiel #18
0
 /**
  * Checks if the player has a certain amount (or more) of a specified food
  *
  * @param food - Specified food
  * @param amount - Amount to check for
  * @return boolean
  */
 public boolean hasFood(Food food, int amount) {
   if (food.getStack() >= amount) {
     return true;
   } else {
     return false;
   }
 }
Beispiel #19
0
  @Override
  public void execute(Hero hero, String action) {

    super.execute(hero, action);

    if (action.equals(AC_EAT)) {

      switch (Random.Int(5)) {
        case 0:
          GLog.i("You see your hands turn invisible!");
          Buff.affect(hero, Invisibility.class, Invisibility.DURATION);
          break;
        case 1:
          GLog.i("You feel your skin hardens!");
          Buff.affect(hero, Barkskin.class).level(hero.HT / 4);
          break;
        case 2:
          GLog.i("Refreshing!");
          Buff.detach(hero, Poison.class);
          Buff.detach(hero, Cripple.class);
          Buff.detach(hero, Weakness.class);
          Buff.detach(hero, Bleeding.class);
          break;
        case 3:
          GLog.i("You feel better!");
          if (hero.HP < hero.HT) {
            hero.HP = Math.min(hero.HP + hero.HT / 4, hero.HT);
            hero.sprite.emitter().burst(Speck.factory(Speck.HEALING), 1);
          }
          break;
      }
    }
  }
  @Override
  public void paint(Graphics g) {
    for (int i = 0; i < 5; i++) {
      g.drawRect(i, i, 410 - 2 * i, 410 - 2 * i);
    }
    if (gameOver) {
      g.setColor(Color.RED);
      g.fillRect(0, 0, 410, 410);
      score.setBackground(Color.RED);
      score.setText("Your score is: " + (int) points);
      score.setSize(160, 20);
      score.setLocation(120, 50);

      record.setBackground(Color.RED);
      record.setSize(160, 20);
      record.setLocation(120, 80);

      tips.setBackground(Color.RED);
      tips.setSize(400, 20);
      tips.setLocation(0, 350);

    } else {
      map.paint(g);
      snake.paint(g);
      food.paint(g);
    }
  }
Beispiel #21
0
 private void collisionDetection() {
   for (int i = 0; i < dishes.size(); i++) {
     Dish d = dishes.get(i);
     if (player.eats(d)) {
       if (d instanceof Food) {
         Food f = (Food) d;
         player.changeCholesterol(f.getValue());
       }
       if (d instanceof Power) {
         Power p = (Power) d;
         player.setPower(p);
       }
       dishes.remove(i);
       i--;
     }
   }
 }
  public static void main(String[] args) {

    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.getEnvironment().setActiveProfiles("highschool");
    ctx.register(KindergartenConfig.class, HighschoolConfig.class);
    ctx.refresh();

    FoodProviderService foodProviderService =
        ctx.getBean("foodProviderService", FoodProviderService.class);
    List<Food> lunchSet = foodProviderService.provideLunchSet();

    for (Food food : lunchSet) {
      System.out.println("  Food: " + food.getName());
    }

    ctx.close();
  }
  // thread run
  @Override
  public void run() {
    // thread
    while (true) {
      snake.move(dt, this);

      if (snake.getHead() == food.getR()) {
        food.eat(snake, map);
        foodEaten++;
        points++;
      }

      if (foodEaten == 2) {
        dt += 1;
        foodEaten = 0;
      }

      if (gameOver != inerGO) {
        dt = 0;
        tips.setText(this.chooseTips());
        if (inerGO == true) {
          inerGO = false;
        } else {
          inerGO = true;
        }

        if (gameOver) {
          this.deathStuff();
        }
      }

      if (frogJump == 0) {
        food.jump();
        frogJump = 50;
      }
      frogJump--;

      repaint();
      try {
        Thread.sleep(rate);
      } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
      }
    }
  }
 public int addFood(Food food) {
   Log.d("addFood", food.getFood_name());
   SQLiteDatabase db = this.getWritableDatabase();
   ContentValues values = putFoodToContentValues(food);
   int id = (int) db.insert(TABLE_FOODS, null, values);
   db.close();
   return id;
 }
  public void addTransaction(int foodId, double proportion) {
    String currentTime = getCurrentTime();
    Log.d("addTransaction", Integer.toString(foodId));
    SQLiteDatabase db = this.getWritableDatabase();

    // add new food transaction
    ContentValues values = new ContentValues();
    values.put(FOOD_ID, foodId);
    values.put(COL_PROPORTION, proportion);
    values.put(COL_TIME, currentTime);
    db.insert(TABLE_TRANSACTION, null, values);
    db.close();

    // update food
    Food food = getFood(foodId);
    food.setFrequency(food.getFrequency() + 1);
    food.setStrLastTransaction(currentTime);
    Log.d(currentTime, food.toString());
    updateFood(foodId, food);
  }
Beispiel #26
0
  @Override
  public void careForInventorySlot(ItemStack is) {
    if (is != null) {
      HeatRegistry manager = HeatRegistry.getInstance();
      HeatIndex index = manager.findMatchingIndex(is);

      if (index != null) {
        float temp = TFC_ItemHeat.getTemp(is);
        if (fuelTimeLeft > 0 && is.getItem() instanceof ICookableFood) {
          float inc = Food.getCooked(is) + Math.min(fireTemp / 700, 2f);
          Food.setCooked(is, inc);
          temp = inc;
          if (Food.isCooked(is)) {
            int[] cookedTasteProfile = new int[] {0, 0, 0, 0, 0};
            Random r =
                new Random(
                    ((ICookableFood) is.getItem()).getFoodID()
                        + (((int) Food.getCooked(is) - 600) / 120));
            cookedTasteProfile[0] = r.nextInt(31) - 15;
            cookedTasteProfile[1] = r.nextInt(31) - 15;
            cookedTasteProfile[2] = r.nextInt(31) - 15;
            cookedTasteProfile[3] = r.nextInt(31) - 15;
            cookedTasteProfile[4] = r.nextInt(31) - 15;
            Food.setCookedProfile(is, cookedTasteProfile);
            Food.setFuelProfile(is, EnumFuelMaterial.getFuelProfile(fuelTasteProfile));
          }
        } else if (fireTemp > temp && index.hasOutput()) {
          temp += TFC_ItemHeat.getTempIncrease(is);
        } else temp -= TFC_ItemHeat.getTempDecrease(is);
        TFC_ItemHeat.setTemp(is, temp);
      }
    }
  }
    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
      // if we weren't given a view, inflate one
      if (null == convertView) {
        convertView = getActivity().getLayoutInflater().inflate(R.layout.food_item_list, null);
      }

      // configure the view for this Crime
      Food f = getItem(position);

      TextView foodNameTextView =
          (TextView) convertView.findViewById(R.id.food_item_name_text_view);
      foodNameTextView.setText(f.getTitle().toString());

      TextView foodQuantity = (TextView) convertView.findViewById(R.id.quantity_text_view);
      foodQuantity.setText(Integer.toString(f.getQuantity()));

      TextView foodCaloriesTextView = (TextView) convertView.findViewById(R.id.calories_text_view);
      foodCaloriesTextView.setText(Integer.toString(f.getCalories()));

      return convertView;
    }
Beispiel #28
0
  public void setup() {
    // System.out.printf( "==> GUIModel setup() called...\n" );

    super.setup(); // the super class does conceptual-model setup

    // NOTE: you may want to set these next two to 'true'
    // if you are on a windows machine.  that would tell repast
    // to by default send System.out and .err output to
    // a special repast output window.
    AbstractGUIController.CONSOLE_ERR = false;
    AbstractGUIController.CONSOLE_OUT = false;
    AbstractGUIController.UPDATE_PROBES = true;

    if (dsurf != null) dsurf.dispose();
    if (graph != null) graph.dispose();
    if (graphNbors != null) graphNbors.dispose();
    if (graphFood != null) graphFood.dispose();
    graph = null;
    dsurf = null;
    graphNbors = null;
    graphFood = null;

    // tell the Ant class we are in GUI mode.
    Ant.setupBugDrawing(this);
    Food.setupFoodDrawing(this);

    // init, setup and turn on the modelMinipulator stuff (in custom actions)
    modelManipulator.init();
    // one custom action to just print the bug list
    modelManipulator.addButton(
        "Print Bugs",
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            System.out.printf("printBugs...\n");

            printBugs();
          }
        });
    // another action:  reset all bugs probRandMove field
    // using the parameters that define the distribution to use
    modelManipulator.addButton(
        "Reset Bug probRandMove",
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {
            resetBugProbRandMove();
          }
        });

    if (rDebug > 0) System.out.printf("<== GUIModel setup() done.\n");
  }
Beispiel #29
0
  public static void main(String[] args) {
    FoodFactory myFoodFactory = new FoodFactory();
    Food myPizza = myFoodFactory.getFood("pizza");
    Food myCake = myFoodFactory.getFood("cake");
    Food myBurger = myFoodFactory.getFood("burger");

    System.out.println(myPizza.getType());
    System.out.println(myCake.getType());
    System.out.println(myBurger.getType());
  }
Beispiel #30
0
 public void addFood(int shopId, String shopName, String image, Food food) {
   HashMap<Food, Integer> fs;
   if (!foods.containsKey(shopId)) {
     fs = new HashMap<Food, Integer>();
     foods.put(shopId, fs);
   } else {
     fs = foods.get(shopId);
   }
   fs.put(food, food.getBuyCount());
   if (shopName != null && !shopNames.containsKey(shopId)) {
     shopNames.put(shopId, shopName);
   }
   if (image != null && !shopImages.containsKey(shopId)) {
     shopImages.put(shopId, image);
   }
 }