私は、数を合計するために使用しているoncheckboxclickedsに関連付けられたスイッチケースの全ラインを持っています。
何もしていないように見える最後のケースを除いて、ラインのすべてのケースが美しく機能し、その理由がわかりません。
これは、最後まで問題なく機能します。
package com.example.blazingboltcalculator;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
import android.widget.CheckBox;
import android.widget.TextView;
public class MainActivity extends Activity {
int attack=11;
int damage=3;
int flankAttack;
int pbs;
int justice;
int destruction;
int bane;
int DF;
int GMW;
int heroism;
int deadly;
int attackTotal;
int damageTotal;
String flames="";
String baneDice="";
String keen="";
String diceTotal;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void onCheckboxClicked(View v) {
// Is the view now checked?
boolean checked = ((CheckBox) v).isChecked();
// Check which checkbox was clicked
switch(v.getId()) {
case R.id.checkBox1:
if (checked)
{
flankAttack=2;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
else
{
flankAttack=0;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
break;
case R.id.checkBox2:
if (checked)
{
pbs=1;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
else
{
pbs=0;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
break;
case R.id.checkBox3:
if (checked)
{
justice=2;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
else
{
justice=0;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
break;
case R.id.checkBox4:
if (checked)
{
destruction=4;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
else
{
destruction=0;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
break;
case R.id.checkBox5:
if (checked)
{
bane=2;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
baneDice="+2d6";
diceTotal="1d8"+baneDice+flames+keen;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
TextView textView3 = (TextView) findViewById(R.id.textView6);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
textView3.setText(diceTotal);
}
else
{
bane=0;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
baneDice="";
diceTotal="1d8"+baneDice+flames+keen;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
TextView textView3 = (TextView) findViewById(R.id.textView6);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
textView3.setText(diceTotal);
}
break;
case R.id.checkBox6:
if (checked)
{
DF=3;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
else
{
DF=0;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
break;
case R.id.checkBox7:
if (checked)
{
flames="+1d6 fire";
diceTotal="1d8"+baneDice+flames+keen;
TextView textView3 = (TextView) findViewById(R.id.textView6);
textView3.setText(diceTotal);
}
else
{
flames="";
diceTotal="1d8"+baneDice+flames+keen;
TextView textView3 = (TextView) findViewById(R.id.textView6);
textView3.setText(diceTotal);
}
break;
case R.id.checkBox8:
if (checked)
{
GMW=1;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
else
{
GMW=0;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
break;
case R.id.checkBox9:
if (checked)
{
heroism=2;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
else
{
heroism=0;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
break;
case R.id.checkBox10:
if (checked)
{
keen="+19-20 crit";
diceTotal="1d8"+baneDice+flames+keen;
TextView textView3 = (TextView) findViewById(R.id.textView6);
textView3.setText(diceTotal);
}
else
{
keen="";
diceTotal="1d8"+baneDice+flames+keen;
TextView textView3 = (TextView) findViewById(R.id.textView6);
textView3.setText(diceTotal);
}
break;
case R.id.checkBox11:
if (checked)
{
deadly=2;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
else
{
deadly=0;
attackTotal=attack+flankAttack+pbs+justice+bane+DF+GMW+heroism+deadly;
damageTotal=damage+pbs+destruction+bane+DF+GMW+deadly;
TextView textView = (TextView) findViewById(R.id.textView2);
TextView textView2 = (TextView) findViewById(R.id.textView4);
textView.setText(Integer.toString(attackTotal));
textView2.setText(Integer.toString(damageTotal));
}
}
}
}
私はプログラミングに少し慣れていませんが、誰かが作品を台無しにしている可能性があることを知っていますか?その最後のケースを除いて、全体の混乱は完全に機能します。