Android Open Source - AndroidSettlers Trader






From Project

Back to project page AndroidSettlers.

License

The source code is released under:

GNU General Public License

If you think the Android project AndroidSettlers listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package com.settlers.hd;
//w  w  w.  j ava 2s. com
import com.settlers.hd.Hexagon.Type;

public class Trader {

  public static final int NUM_TRADER = 9;
  
  public enum Position {
    NORTH, SOUTH, NORTHEAST, NORTHWEST, SOUTHEAST, SOUTHWEST
  }
  
  private static final Position[] POSITION_LIST = {
    Position.NORTH, Position.NORTHWEST, Position.NORTHEAST, 
    Position.NORTHWEST, Position.NORTHEAST, Position.SOUTHWEST, 
    Position.SOUTHEAST, Position.SOUTH, Position.SOUTH 
  };

  private Type type;
  private Position position;
  private int index;

  public Trader(Type type, int index) {
    this.type = type;
    this.index = index;
    position = POSITION_LIST[index];
  }
  
  public void setType(Type type) {
    this.type = type;
  }

  public Type getType() {
    return type;
  }
  
  public Position getPosition() {
    return position;
  }
  
  public int getIndex() {
    return index;
  }
  
  public static Trader[] initialize() {

    // mark all traders as unassigned
    Trader[] trader = new Trader[NUM_TRADER];
    boolean[] usedTrader = new boolean[NUM_TRADER];
    for (int i = 0; i < NUM_TRADER; i++)
      usedTrader[i] = false;

    // for each trader type (one of each resource, 4 any 3:1 traders)
    for (int i = 0; i < NUM_TRADER; i++) {
      while (true) {
        // pick a random unassigned trader
        int pick = (int) (Math.random() * NUM_TRADER);
        if (!usedTrader[pick]) {
          Type type;
          if (i >= Hexagon.TYPES.length)
            type = Type.ANY;
          else
            type = Type.values()[i];

          trader[pick] = new Trader(type, pick);
          usedTrader[pick] = true;
          break;
        }
      }
    }
    
    return trader;
  }
  
  public static Trader[] initialize(Type[] types) {
    Trader[] trader = new Trader[NUM_TRADER];
    for (int i = 0; i < trader.length; i++)
      trader[i] = new Trader(types[i], i);
    
    return trader;
  }
}




Java Source Code List

com.settlers.hd.AcceptTrade.java
com.settlers.hd.AutomatedPlayer.java
com.settlers.hd.BalancedAI.java
com.settlers.hd.Board.java
com.settlers.hd.CounterOffer.java
com.settlers.hd.Discard.java
com.settlers.hd.Edge.java
com.settlers.hd.GameActivity.java
com.settlers.hd.GameRenderer.java
com.settlers.hd.GameView.java
com.settlers.hd.Geometry.java
com.settlers.hd.Hexagon.java
com.settlers.hd.LocalGame.java
com.settlers.hd.Main.java
com.settlers.hd.PlayerTrade.java
com.settlers.hd.Player.java
com.settlers.hd.Reference.java
com.settlers.hd.ResourceView.java
com.settlers.hd.Rules.java
com.settlers.hd.Settings.java
com.settlers.hd.Settlers.java
com.settlers.hd.Square.java
com.settlers.hd.Stats.java
com.settlers.hd.Status.java
com.settlers.hd.TextureManager.java
com.settlers.hd.Trader.java
com.settlers.hd.UIButton.java
com.settlers.hd.Vertex.java