Untitled
unknown
plain_text
a year ago
4.2 kB
2
Indexable
Never
package fi.lappeensuksi.projekti.Activities; import static fi.lappeensuksi.projekti.R.id.battleTextView; import androidx.appcompat.app.AppCompatActivity; import android.os.Bundle; import android.widget.EditText; import android.widget.TextView; import fi.lappeensuksi.projekti.Classes.Storage; import fi.lappeensuksi.projekti.Lutemons.Lutemon; import fi.lappeensuksi.projekti.R; public class BattleArenaActivity extends AppCompatActivity { private Storage storage; TextView battleText; EditText id1; EditText id2; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_battle_arena); id1 = findViewById(R.id.edit1ID); id2 = findViewById(R.id.edit2ID); String stringID1 =id1.getText().toString(); String stringID2 =id2.getText().toString(); int ID1=Integer.valueOf(stringID1); int ID2=Integer.valueOf(stringID2); storage = Storage.getInstance(); Lutemon lutemon1 = storage.getLutemonById(storage.getBattleLutemons(), ID1); Lutemon lutemon2 = storage.getLutemonById(storage.getBattleLutemons(), ID2); String battlestring =""; int random; boolean exit = false; while (!exit) { random=(int)Math.random()*3; battlestring=battlestring+("1: " + lutemon1.getColor() + "(" + lutemon1.getName() + ") att: " + lutemon1.getAttack() + "; def: " + lutemon1.getDefence() + "; exp: " + lutemon1.getExperience() + "; health: " + lutemon1.getHealth() + "/" + lutemon1.getMaxHealth()+"\n"); battlestring=battlestring+("2: " + lutemon2.getColor() + "(" + lutemon2.getName() + ") att: " + lutemon2.getAttack() + "; def: " + lutemon2.getDefence() + "; exp: " + lutemon2.getExperience() + "; health: " + lutemon2.getHealth() + "/" + lutemon2.getMaxHealth()+"\n"); battlestring=battlestring+(lutemon1.getColor() + "(" + lutemon1.getName() + ") Attacks " + lutemon2.getColor() + "(" + lutemon2.getName() + ")\n"); lutemon2.health = lutemon2.getHealth() - lutemon1.getAttack()-random + lutemon2.getDefence(); if (lutemon2.getHealth() > 0) { battlestring=battlestring+(lutemon2.getColor() + "(" + lutemon2.getName() + ") manages to escape death.\n\n"); } else { battlestring=battlestring+(lutemon2.getColor() + "(" + lutemon2.getName() + ") gets killed.\nThe battle is over."); exit = true; storage.getBattleLutemons().remove(lutemon2); storage.getAllLutemons().remove(lutemon2); break; } random=(int)Math.random()*3; battlestring=battlestring+("2: " + lutemon2.getColor() + "(" + lutemon2.getName() + ") att: " + lutemon2.getAttack() + "; def: " + lutemon2.getDefence() + "; exp: " + lutemon2.getExperience() + "; health: " + lutemon2.getHealth() + "/" + lutemon2.getMaxHealth()+"\n"); battlestring=battlestring+("1: " + lutemon1.getColor() + "(" + lutemon1.getName() + ") att: " + lutemon1.getAttack() + "; def: " + lutemon1.getDefence() + "; exp: " + lutemon1.getExperience() + "; health: " + lutemon1.getHealth() + "/" + lutemon1.getMaxHealth()+"\n"); battlestring=battlestring+(lutemon2.getColor() + "(" + lutemon2.getName() + ") Attacks " + lutemon1.getColor() + "(" + lutemon1.getName() + ")\n"); lutemon1.health = lutemon1.getHealth() - lutemon2.getAttack()-random + lutemon1.getDefence(); if (lutemon2.getHealth() > 0) { battlestring=battlestring+(lutemon1.getColor() + "(" + lutemon1.getName() + ") manages to escape death.\n\n"); } else { battlestring=battlestring+(lutemon1.getColor() + "(" + lutemon1.getName() + ") gets killed.\nThe battle is over."); exit = true; storage.getBattleLutemons().remove(lutemon1); storage.getAllLutemons().remove(lutemon1); } } battleText=findViewById(R.id.battleTextView); battleText.setText(battlestring); } }