Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package family.lacn;
- import java.math.BigInteger;
- import javax.security.auth.login.LoginException;
- import android.app.Activity;
- import android.content.SharedPreferences;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.EditText;
- import android.widget.TextView;
- import android.widget.Toast;
- public class LaCN extends Activity {
- /** Called when the activity is first created. */
- LaCN t = this;
- private BuyStuff bs = null;
- private String username = "";
- private String password = "";
- BigInteger gold = new BigInteger(0+"");
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- SharedPreferences preferences = getPreferences(MODE_PRIVATE);
- username = preferences.getString("username", "");
- password = preferences.getString("password", "");
- setContentView(R.layout.main);
- ((EditText)findViewById(R.id.username)).setText(username);
- ((EditText)findViewById(R.id.password)).setText(password);
- Button button = (Button) findViewById(R.id.button1);
- button.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- username = ((EditText)findViewById(R.id.username)).getText().toString();
- password = ((EditText)findViewById(R.id.password)).getText().toString();
- storeCredentials();
- try {
- bs = new BuyStuff(username, password);
- try
- {
- gold = bs.getGold();
- }
- catch (ArrayIndexOutOfBoundsException e)
- {
- throw new LoginException();
- }
- setContentView(R.layout.buying);
- Button buy = (Button) findViewById(R.id.buy);
- ((TextView)findViewById(R.id.gold)).setText("Gold: "+bs.getGold());
- buy.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- try {
- buyWeps();
- } catch (Exception e) {
- Toast.makeText(t, "Failed to buy! Restart app and try again. ", Toast.LENGTH_LONG);
- }
- }
- });
- bindButtons();
- } catch (LoginException e)
- {
- Toast.makeText(t, "Seems that the login info was not correct. ", Toast.LENGTH_LONG).show();
- } catch (Exception e) {
- Toast.makeText(t, "Uhoh, login failed!" + e.toString(), Toast.LENGTH_LONG).show();
- }
- }
- });
- }
- private int wepnametoint(String wepname)
- {
- if (wepname.toLowerCase().contains("stick")) return 69;
- if (wepname.toLowerCase().contains("chariot")) return 72;
- if (wepname.toLowerCase().contains("missile")) return 70;
- if (wepname.toLowerCase().contains("dragonskin")) return 51;
- if (wepname.toLowerCase().contains("shield")) return 71;
- if (wepname.toLowerCase().contains("nunchaka")) return 75;
- if (wepname.toLowerCase().contains("tower")) return 74;
- else
- return 69;
- }
- private int getValue(String wep)
- {
- if (wep.toLowerCase().contains("stick")) return 100;
- if (wep.toLowerCase().contains("chariot")) return 450000;
- if (wep.toLowerCase().contains("missile")) return 1000000;
- if (wep.toLowerCase().contains("dragonskin")) return 200000;
- if (wep.toLowerCase().contains("nunchaka")) return 1000000;
- if (wep.toLowerCase().contains("tower")) return 1000000;
- if (wep.toLowerCase().contains("shield")) return 1000000;
- else
- return 1000000;
- }
- protected void onPause() {
- super.onPause();
- storeCredentials();
- }
- private void storeCredentials()
- {
- SharedPreferences preferences = getPreferences(MODE_PRIVATE);
- SharedPreferences.Editor editor = preferences.edit();
- editor.putString("username", username);
- editor.putString("password", password);
- editor.commit();
- }
- private void buyWeps() {
- try {
- if (!((EditText)findViewById(R.id.stickamount)).getText().toString().equals("0"))
- bs.buyWep(wepnametoint("stick"), Integer.parseInt(((EditText)findViewById(R.id.stickamount)).getText().toString()), t);
- if (!((EditText)findViewById(R.id.chariotamount)).getText().toString().equals("0"))
- bs.buyWep(wepnametoint("chariot"), Integer.parseInt(((EditText)findViewById(R.id.chariotamount)).getText().toString()), t);
- if (!((EditText)findViewById(R.id.bpmamount)).getText().toString().equals("0"))
- bs.buyWep(wepnametoint("missile"), Integer.parseInt(((EditText)findViewById(R.id.bpmamount)).getText().toString()), t);
- if (!((EditText)findViewById(R.id.dsamount)).getText().toString().equals("0"))
- bs.buyWep(wepnametoint("dragonskin"), Integer.parseInt(((EditText)findViewById(R.id.dsamount)).getText().toString()), t);
- if (!((EditText)findViewById(R.id.nunchakuamount)).getText().toString().equals("0"))
- bs.buyWep(wepnametoint("nunchaka"), Integer.parseInt(((EditText)findViewById(R.id.nunchakuamount)).getText().toString()), t);
- if (!((EditText)findViewById(R.id.lttoweramount)).getText().toString().equals("0"))
- bs.buyWep(wepnametoint("tower"), Integer.parseInt(((EditText)findViewById(R.id.lttoweramount)).getText().toString()), t);
- if (!((EditText)findViewById(R.id.isamount)).getText().toString().equals("0"))
- bs.buyWep(wepnametoint("shield"), Integer.parseInt(((EditText)findViewById(R.id.isamount)).getText().toString()), t);
- } catch (Exception e) {
- Toast.makeText(t, "Failed to buy! Restart app and try again. ", Toast.LENGTH_LONG);
- }
- }
- private void bindButtons()
- {
- Button stick = (Button) findViewById(R.id.stick);
- stick.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- resetFields();
- ((EditText)findViewById(R.id.stickamount)).setText(gold.divide(new BigInteger(getValue("stick")+""))+"");
- }
- }
- );
- Button chariot = (Button) findViewById(R.id.chariot);
- chariot.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- resetFields();
- ((EditText)findViewById(R.id.chariotamount)).setText(gold.divide(new BigInteger(getValue("chariot")+""))+"");
- }}
- );
- Button missile = (Button) findViewById(R.id.bpm);
- missile.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- resetFields();
- ((EditText)findViewById(R.id.bpmamount)).setText(gold.divide(new BigInteger(getValue("missile")+""))+"");
- }}
- );
- Button dragonskin = (Button) findViewById(R.id.ds);
- dragonskin.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- resetFields();
- ((EditText)findViewById(R.id.dsamount)).setText(gold.divide(new BigInteger(getValue("dragonskin")+""))+"");
- }}
- );
- Button nunchaka = (Button) findViewById(R.id.nun);
- nunchaka.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- resetFields();
- ((EditText)findViewById(R.id.nunchakuamount)).setText(gold.divide(new BigInteger(getValue("nunchaka")+""))+"");
- }}
- );
- Button lt = (Button) findViewById(R.id.lt);
- lt.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- resetFields();
- ((EditText)findViewById(R.id.lttoweramount)).setText(gold.divide(new BigInteger(getValue("tower")+""))+"");
- }}
- );
- Button shield = (Button) findViewById(R.id.is);
- shield.setOnClickListener(new View.OnClickListener() {
- public void onClick(View v) {
- resetFields();
- ((EditText)findViewById(R.id.isamount)).setText(gold.divide(new BigInteger(getValue("shield")+""))+"");
- }}
- );
- }
- private void resetFields() {
- ((EditText)findViewById(R.id.stickamount)).setText(0+"");
- ((EditText)findViewById(R.id.chariotamount)).setText(0+"");
- ((EditText)findViewById(R.id.bpmamount)).setText(0+"");
- ((EditText)findViewById(R.id.nunchakuamount)).setText(0+"");
- ((EditText)findViewById(R.id.lttoweramount)).setText(0+"");
- ((EditText)findViewById(R.id.isamount)).setText(0+"");
- ((EditText)findViewById(R.id.dsamount)).setText(0+"");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement