public void pokemon3(View view) { fragment.sendPokeMessage("0" + "2" + ":action"); if (userPokemon.getHealth() <= 0) { // Health = zero means you came here after your opponent attacked userSwitch(2); readyUp(); } else { // you voluntarily chose to switch pokemon userMove = -3; launchText("Waiting On Opponent..."); } }
@Override protected void onCreate(Bundle savedInstanceState) { messageReceived = new AtomicBoolean(false); messageReceived.getAndSet(false); super.onCreate(savedInstanceState); setContentView(R.layout.activity_main_battle); // ConnectivityManager connMgr = (ConnectivityManager) // getSystemService(Context.CONNECTIVITY_SERVICE); // NetworkInfo networkInfo = connMgr.getActiveNetworkInfo(); fragment = new BluetoothChatFragment(); fragment.copy(MainActivity.fragment, 1); if (savedInstanceState == null) { FragmentTransaction transaction = getSupportFragmentManager().beginTransaction(); transaction.replace(R.id.game_content_fragment, fragment); transaction.commit(); } firstTime = true; Intent intent = getIntent(); String OtherPokemon = intent.getStringExtra(MainActivity.GAME_START); String gameType = intent.getStringExtra(MainActivity.GAME_TYPE); // Initialize Globals currentAttack = -1; MainText = (TextView) findViewById(R.id.MainText); UserName = (TextView) findViewById(R.id.UserName); UserHealth = (ProgressBar) findViewById(R.id.UserHealth); UserImage = (ImageView) findViewById(R.id.UserImage); EnemyName = (TextView) findViewById(R.id.EnemyName); EnemyHealth = (ProgressBar) findViewById(R.id.EnemyHealth); EnemyImage = (ImageView) findViewById(R.id.EnemyImage); SwitchButton = (Button) findViewById(R.id.SwitchButton); FightButton = (Button) findViewById(R.id.FightButton); SurrenderButton = (Button) findViewById(R.id.SurrenderButton); ReadyButton = (Button) findViewById(R.id.ReadyButton); Attack1 = (Button) findViewById(R.id.Attack1); Attack2 = (Button) findViewById(R.id.Attack2); Attack3 = (Button) findViewById(R.id.Attack3); Pokemon1 = (Button) findViewById(R.id.Pokemon1); Pokemon2 = (Button) findViewById(R.id.Pokemon2); Pokemon3 = (Button) findViewById(R.id.Pokemon3); cancelAttack = (Button) findViewById(R.id.CancelAttack); rn = new Random(); PopUp = (TextView) findViewById(R.id.PopUp); PopUp2 = (TextView) findViewById(R.id.PopUp2); PopUp3 = (TextView) findViewById(R.id.PopUp3); PopUp4 = (TextView) findViewById(R.id.PopUp4); PopUp5 = (TextView) findViewById(R.id.PopUp5); CloseWindow = true; EnemyName.setText("Waiting"); int pokemonPassedByMain[] = intent.getIntArrayExtra(MainActivity.GAME_POKEMON); user = new Player(); for (int i : pokemonPassedByMain) { user.addPokemon(i); } yourRandom = (int) (Math.random() * 50000); userPokemon = user.getPokemonTeam().get(0); fragment.sendPokeMessage( user.getPokemonNums() + ":set" + gameType.substring(0, 6) + yourRandom); // enemy = new Player(); SwitchButton.setVisibility(View.INVISIBLE); SurrenderButton.setVisibility(View.INVISIBLE); FightButton.setVisibility(View.INVISIBLE); UserHealth.setMax(userPokemon.getStats().getMaxHP()); UserHealth.setProgress(userPokemon.getHealth()); UserImage.setImageResource(userPokemon.backPicture); UserName.setText(userPokemon.getName()); if (OtherPokemon.contains(":set")) { firstTime = false; // TODO:: Edit this code to be expandable (to be able to change the number of pokemon more // easily) enemyFirst = (int) Integer.parseInt(OtherPokemon.substring(0, 2)); enemySecond = (int) Integer.parseInt(OtherPokemon.substring(2, 4)); enemyThird = (int) Integer.parseInt(OtherPokemon.substring(4, 6)); theirRandom = (int) Integer.parseInt(OtherPokemon.substring(16)); enemy = new Player(enemyFirst, enemySecond, enemyThird); enemyPokemon = enemy.getPokemonTeam().get(0); EnemyHealth.setMax(enemyPokemon.getStats().getMaxHP()); EnemyHealth.setProgress(enemyPokemon.getHealth()); EnemyImage.setImageResource(enemyPokemon.frontPicture); EnemyName.setText(enemyPokemon.getName()); readyUp(); } else { launchText4("Waiting for opponent"); } }
public void attack3(View view) { userMove = 2; fragment.sendPokeMessage("1" + userMove + ":action"); launchText("Waiting on Opponent..."); }