Advertisement
Guest User

Untitled

a guest
Aug 8th, 2017
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.49 KB | None | 0 0
  1. package family.lacn;
  2.  
  3.  
  4.  
  5. import java.math.BigInteger;
  6.  
  7. import javax.security.auth.login.LoginException;
  8.  
  9.  
  10. import android.app.Activity;
  11. import android.content.SharedPreferences;
  12. import android.os.Bundle;
  13. import android.view.View;
  14. import android.widget.Button;
  15. import android.widget.EditText;
  16. import android.widget.TextView;
  17. import android.widget.Toast;
  18.  
  19. public class LaCN extends Activity {
  20. /** Called when the activity is first created. */
  21. LaCN t = this;
  22. private BuyStuff bs = null;
  23. private String username = "";
  24. private String password = "";
  25. BigInteger gold = new BigInteger(0+"");
  26. public void onCreate(Bundle savedInstanceState) {
  27. super.onCreate(savedInstanceState);
  28.  
  29. SharedPreferences preferences = getPreferences(MODE_PRIVATE);
  30. username = preferences.getString("username", "");
  31. password = preferences.getString("password", "");
  32.  
  33. setContentView(R.layout.main);
  34. ((EditText)findViewById(R.id.username)).setText(username);
  35. ((EditText)findViewById(R.id.password)).setText(password);
  36.  
  37. Button button = (Button) findViewById(R.id.button1);
  38. button.setOnClickListener(new View.OnClickListener() {
  39. public void onClick(View v) {
  40. username = ((EditText)findViewById(R.id.username)).getText().toString();
  41. password = ((EditText)findViewById(R.id.password)).getText().toString();
  42. storeCredentials();
  43.  
  44. try {
  45. bs = new BuyStuff(username, password);
  46. try
  47. {
  48. gold = bs.getGold();
  49. }
  50. catch (ArrayIndexOutOfBoundsException e)
  51. {
  52. throw new LoginException();
  53. }
  54. setContentView(R.layout.buying);
  55. Button buy = (Button) findViewById(R.id.buy);
  56. ((TextView)findViewById(R.id.gold)).setText("Gold: "+bs.getGold());
  57. buy.setOnClickListener(new View.OnClickListener() {
  58. public void onClick(View v) {
  59. try {
  60. buyWeps();
  61. } catch (Exception e) {
  62. Toast.makeText(t, "Failed to buy! Restart app and try again. ", Toast.LENGTH_LONG);
  63. }
  64. }
  65. });
  66. bindButtons();
  67. } catch (LoginException e)
  68. {
  69. Toast.makeText(t, "Seems that the login info was not correct. ", Toast.LENGTH_LONG).show();
  70. } catch (Exception e) {
  71. Toast.makeText(t, "Uhoh, login failed!" + e.toString(), Toast.LENGTH_LONG).show();
  72. }
  73. }
  74. });
  75.  
  76. }
  77.  
  78. private int wepnametoint(String wepname)
  79. {
  80. if (wepname.toLowerCase().contains("stick")) return 69;
  81. if (wepname.toLowerCase().contains("chariot")) return 72;
  82. if (wepname.toLowerCase().contains("missile")) return 70;
  83. if (wepname.toLowerCase().contains("dragonskin")) return 51;
  84. if (wepname.toLowerCase().contains("shield")) return 71;
  85. if (wepname.toLowerCase().contains("nunchaka")) return 75;
  86. if (wepname.toLowerCase().contains("tower")) return 74;
  87. else
  88. return 69;
  89. }
  90. private int getValue(String wep)
  91. {
  92. if (wep.toLowerCase().contains("stick")) return 100;
  93. if (wep.toLowerCase().contains("chariot")) return 450000;
  94. if (wep.toLowerCase().contains("missile")) return 1000000;
  95. if (wep.toLowerCase().contains("dragonskin")) return 200000;
  96. if (wep.toLowerCase().contains("nunchaka")) return 1000000;
  97. if (wep.toLowerCase().contains("tower")) return 1000000;
  98. if (wep.toLowerCase().contains("shield")) return 1000000;
  99. else
  100. return 1000000;
  101. }
  102.  
  103. protected void onPause() {
  104. super.onPause();
  105. storeCredentials();
  106. }
  107. private void storeCredentials()
  108. {
  109. SharedPreferences preferences = getPreferences(MODE_PRIVATE);
  110. SharedPreferences.Editor editor = preferences.edit();
  111. editor.putString("username", username);
  112. editor.putString("password", password);
  113. editor.commit();
  114. }
  115.  
  116. private void buyWeps() {
  117. try {
  118. if (!((EditText)findViewById(R.id.stickamount)).getText().toString().equals("0"))
  119. bs.buyWep(wepnametoint("stick"), Integer.parseInt(((EditText)findViewById(R.id.stickamount)).getText().toString()), t);
  120. if (!((EditText)findViewById(R.id.chariotamount)).getText().toString().equals("0"))
  121. bs.buyWep(wepnametoint("chariot"), Integer.parseInt(((EditText)findViewById(R.id.chariotamount)).getText().toString()), t);
  122. if (!((EditText)findViewById(R.id.bpmamount)).getText().toString().equals("0"))
  123. bs.buyWep(wepnametoint("missile"), Integer.parseInt(((EditText)findViewById(R.id.bpmamount)).getText().toString()), t);
  124. if (!((EditText)findViewById(R.id.dsamount)).getText().toString().equals("0"))
  125. bs.buyWep(wepnametoint("dragonskin"), Integer.parseInt(((EditText)findViewById(R.id.dsamount)).getText().toString()), t);
  126. if (!((EditText)findViewById(R.id.nunchakuamount)).getText().toString().equals("0"))
  127. bs.buyWep(wepnametoint("nunchaka"), Integer.parseInt(((EditText)findViewById(R.id.nunchakuamount)).getText().toString()), t);
  128. if (!((EditText)findViewById(R.id.lttoweramount)).getText().toString().equals("0"))
  129. bs.buyWep(wepnametoint("tower"), Integer.parseInt(((EditText)findViewById(R.id.lttoweramount)).getText().toString()), t);
  130. if (!((EditText)findViewById(R.id.isamount)).getText().toString().equals("0"))
  131. bs.buyWep(wepnametoint("shield"), Integer.parseInt(((EditText)findViewById(R.id.isamount)).getText().toString()), t);
  132. } catch (Exception e) {
  133. Toast.makeText(t, "Failed to buy! Restart app and try again. ", Toast.LENGTH_LONG);
  134. }
  135. }
  136.  
  137. private void bindButtons()
  138. {
  139. Button stick = (Button) findViewById(R.id.stick);
  140. stick.setOnClickListener(new View.OnClickListener() {
  141. public void onClick(View v) {
  142. resetFields();
  143. ((EditText)findViewById(R.id.stickamount)).setText(gold.divide(new BigInteger(getValue("stick")+""))+"");
  144. }
  145. }
  146. );
  147. Button chariot = (Button) findViewById(R.id.chariot);
  148. chariot.setOnClickListener(new View.OnClickListener() {
  149. public void onClick(View v) {
  150. resetFields();
  151. ((EditText)findViewById(R.id.chariotamount)).setText(gold.divide(new BigInteger(getValue("chariot")+""))+"");
  152. }}
  153. );
  154. Button missile = (Button) findViewById(R.id.bpm);
  155. missile.setOnClickListener(new View.OnClickListener() {
  156. public void onClick(View v) {
  157. resetFields();
  158. ((EditText)findViewById(R.id.bpmamount)).setText(gold.divide(new BigInteger(getValue("missile")+""))+"");
  159. }}
  160. );
  161. Button dragonskin = (Button) findViewById(R.id.ds);
  162. dragonskin.setOnClickListener(new View.OnClickListener() {
  163. public void onClick(View v) {
  164. resetFields();
  165. ((EditText)findViewById(R.id.dsamount)).setText(gold.divide(new BigInteger(getValue("dragonskin")+""))+"");
  166. }}
  167. );
  168. Button nunchaka = (Button) findViewById(R.id.nun);
  169. nunchaka.setOnClickListener(new View.OnClickListener() {
  170. public void onClick(View v) {
  171. resetFields();
  172. ((EditText)findViewById(R.id.nunchakuamount)).setText(gold.divide(new BigInteger(getValue("nunchaka")+""))+"");
  173. }}
  174. );
  175. Button lt = (Button) findViewById(R.id.lt);
  176. lt.setOnClickListener(new View.OnClickListener() {
  177. public void onClick(View v) {
  178. resetFields();
  179. ((EditText)findViewById(R.id.lttoweramount)).setText(gold.divide(new BigInteger(getValue("tower")+""))+"");
  180. }}
  181. );
  182. Button shield = (Button) findViewById(R.id.is);
  183. shield.setOnClickListener(new View.OnClickListener() {
  184. public void onClick(View v) {
  185. resetFields();
  186. ((EditText)findViewById(R.id.isamount)).setText(gold.divide(new BigInteger(getValue("shield")+""))+"");
  187. }}
  188. );
  189. }
  190.  
  191. private void resetFields() {
  192. ((EditText)findViewById(R.id.stickamount)).setText(0+"");
  193. ((EditText)findViewById(R.id.chariotamount)).setText(0+"");
  194. ((EditText)findViewById(R.id.bpmamount)).setText(0+"");
  195. ((EditText)findViewById(R.id.nunchakuamount)).setText(0+"");
  196. ((EditText)findViewById(R.id.lttoweramount)).setText(0+"");
  197. ((EditText)findViewById(R.id.isamount)).setText(0+"");
  198. ((EditText)findViewById(R.id.dsamount)).setText(0+"");
  199. }
  200. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement