Android Open Source - AndroidSettlers Counter Offer






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;
/*from  ww  w  . jav  a 2s.  c  o  m*/
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;

public class CounterOffer extends Activity {

  private Hexagon.Type type;
  private int[] trade;
  private Player current, player;
  private int index;

  private static final int[] RESOURCES = { R.id.trade_res1, R.id.trade_res2,
      R.id.trade_res3, R.id.trade_res4, R.id.trade_res5 };

  private static final int[] OFFER = { R.id.trade_offer1, R.id.trade_offer2,
      R.id.trade_offer3, R.id.trade_offer4, R.id.trade_offer5 };

  @Override
  public void onCreate(Bundle bundle) {
    super.onCreate(bundle);

    Board board = ((Settlers) getApplicationContext()).getBoardInstance();

    Bundle extras = getIntent().getExtras();
    if (extras == null) {
      finish();
      return;
    }

    type = Hexagon.TYPES[extras.getInt(PlayerTrade.TYPE_KEY)];
    trade = extras.getIntArray(PlayerTrade.OFFER_KEY);
    player = board.getPlayer(extras.getInt(PlayerTrade.PLAYER_KEY));
    current = board.getCurrentPlayer();
    index = extras.getInt(PlayerTrade.INDEX_KEY);

    Log.d(getClass().getName(), player.getName() + " (index " + index
        + ") considering trade");

//    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.counteroffer);

    TextView wants = (TextView) findViewById(R.id.trade_player_wants);
    wants.setText(String.format(getString(R.string.trade_player_wants),
        getString(Hexagon.getTypeStringResource(type))));

    TextView playerOffer = (TextView) findViewById(R.id.trade_player_offer);
    playerOffer.setText(String.format(
        getString(R.string.trade_player_offer), current.getName()));

    for (int i = 0; i < RESOURCES.length; i++) {
      int count = player.getResources(Hexagon.TYPES[i]);

      TextView res = (TextView) findViewById(RESOURCES[i]);
      res.setText(Integer.toString(count));

      TextView offer = (TextView) findViewById(OFFER[i]);
      offer.setText(Integer.toString(trade[i]));
    }

    Button accept = (Button) findViewById(R.id.trade_accept);
    accept.setEnabled(player.getResources(type) > 0);
    accept.setOnClickListener(new OnClickListener() {
      @Override
      public void onClick(View v) {
        Intent intent = new Intent();
        intent.putExtra(PlayerTrade.INDEX_KEY, index);
        setResult(Activity.RESULT_OK, intent);
        finish();
      }
    });
  }
}




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