Package ch.sahits.game.openpatrician.model.product

Examples of ch.sahits.game.openpatrician.model.product.AmountablePrice


   * @return the available amount
   * @throws FontFormatException Error while creating a font
   * @throws IOException Error while reading a resource
   */
  private int drawAvailableAmount(Graphics2D g2d, ICity city,IWare ware,BufferedImage barrel, BufferedImage bale,int y) throws FontFormatException, IOException{
    AmountablePrice available = city.getWare(ware);
    int availableAmount = available.getAmount();
    int value = availableAmount; // amount available
    if (value>0){
      GlyphVector gv = opPainter.createGlyphVector(g2d, String.valueOf(value), 18);
      g2d.drawGlyphVector(gv, positions.xCity, y);
      // draw barrel or burden
View Full Code Here


   * @return the available amount
   * @throws FontFormatException Error while creating a font
   * @throws IOException Error while reading a resource
   */
  private int drawAvailableAmount(Graphics2D g2d, ICity city,IWare ware,BufferedImage barrel, BufferedImage bale,int y) throws FontFormatException, IOException{
    AmountablePrice available = city.getWare(ware);
    int availableAmount = available.getAmount();
    int value = availableAmount; // amount available
    int xPadding = positions.xCity;
    drawWareAmount(g2d, (EWare) ware, barrel, bale, y, value, xPadding);
    return availableAmount;

View Full Code Here

   * @return the available amount
   * @throws FontFormatException Error while creating a font
   * @throws IOException Error while reading a resource
   */
  private int drawAvailableAmount(Graphics2D g2d, ICity city, ITradingOffice office, IWare ware,BufferedImage barrel, BufferedImage bale,int y) throws FontFormatException, IOException{
    AmountablePrice available;
    switch (type) {
    case CITY_TO_SHIP:
    case CITY_TO_STORAGE:
      available = city.getWare(ware);
      break;
    default:
      available = office.getWare(ware);
      break;
    }
    int availableAmount = available.getAmount();
    int value = availableAmount; // amount available
    if (value>0){
      GlyphVector gv = opPainter.createGlyphVector(g2d, String.valueOf(value), 18);
      g2d.drawGlyphVector(gv, positions.xCity, y);
      // draw barrel or burden
View Full Code Here

    BufferedImage coin = loader.getImage("coin_icon");
    final int coinSpace = 3;
    final int coindWidth = coin.getWidth();
    final int maxPriceWidth = (int)opPainter.createGlyphVector(g2d, "00000", 18).getVisualBounds().getWidth();
    int xRight = positions.xPrice+10+maxPriceWidth+coinSpace+coindWidth;
    AmountablePrice amounable = getStoredAmount(ware, ship, office);
    int storedAmount =amounable.getAmount();
    int value = 0;
    if (storedAmount>0){
      value = amounable.getAVGPrice();
      GlyphVector gv = opPainter.createGlyphVector(g2d, String.valueOf(value), 18);
      int x = xRight-((int)gv.getVisualBounds().getWidth()+coinSpace+coindWidth);
      g2d.drawGlyphVector(gv, x, y);
      x = xRight-coindWidth;
      y -= (int) Math.ceil(gv.getVisualBounds().getHeight());
View Full Code Here

   * @param office Reference to the trading office
   * @return Amountable object for the ware
   */
  private AmountablePrice getStoredAmount(IWare ware, IShip ship,
      ITradingOffice office) {
    AmountablePrice amounable;
    switch (type) {
    case CITY_TO_SHIP:
    case STORAGE_TO_SHIP: // stored here means stored on the ship
      amounable = ship.getWare(ware);
      break;
View Full Code Here

   * @param y position of from the top
   * @throws FontFormatException Error while creating a font
   * @throws IOException Error while reading a resource
   */
  private void drawStoredAmount(Graphics2D g2d, IWare ware, IShip ship, ITradingOffice office, int y) throws FontFormatException, IOException{
    AmountablePrice amounable = getStoredAmount(ware, ship, office);
    int value = amounable.getAmount(); // differ between ship and convoi
    if (value>0){
      GlyphVector gv = opPainter.createGlyphVector(g2d, String.valueOf(value), 18);
      g2d.drawGlyphVector(gv, positions.xShip, y); // this value is dynamic
      // draw barrel or burden
    }
View Full Code Here

  @Override
  public int getStored() {
    int totalAmount = 0;
    EWare[] wares = EWare.values();
    for (EWare ware : wares) {
      AmountablePrice amount = getWare(ware);
      if (amount!=null){
        totalAmount += amount.getAmount()*ware.getSizeAsBarrels();
      }
    }
    return totalAmount;
  }
View Full Code Here

   * {@inheritDoc}
   */
  @Override
  public int move(IWare ware, int amount, int avgPrice) {
    synchronized (ware) { // There is still a problem with networked solution where the model of the city is replicated.
      AmountablePrice amounted = getWare(ware);
      if (amount<0 && containsWare(ware) && amounted!=null && -amount>amounted.getAmount()){ // remove more than is available
        amount = -amounted.getAmount();
      }
      if (amount<0 && !containsWare(ware)){
        amount = 0;
      }
      if (!containsWare(ware)){ // If the ware does not exist add it with amount 0
        new IllegalStateException("All wares should be initialized, allowed in test").printStackTrace();
      }
      if (amount>0){ // amount was bought
        amounted.add(amount, avgPrice);
      } else { // amount sold
        amounted.remove(amount);
      }
      return amount;
    }
  }
View Full Code Here

   */
  protected void addNewWare(IWare ware, int amount){
    if (containsWare(ware)){
      throw new IllegalStateException("Ware ("+ware.name()+") does already exist");
    }
    AmountablePrice amountable = new AmountablePrice();
    amountable.add(amount, 0);
    wares.put(ware, amountable);
  }
View Full Code Here

   */
  public AmountablePrice getWare(IWare ware) {
    if (!containsWare(ware)){
      addNewWare(ware,0);
    }
    AmountablePrice ret = wares.get(ware);
    return ret;
  }
View Full Code Here

TOP

Related Classes of ch.sahits.game.openpatrician.model.product.AmountablePrice

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.