我试图做出基于决策的故事。即,您选择选项a或b,故事根据您的选择而变化。我遇到的问题是,如果我选择了选项a或b,那么当我进入故事的时候,它会让我回到故事的另一部分,它应该不会。
MainActivity.java:
public class MainActivity extends AppCompatActivity {
private TextView story;
private Button buttonA;
private Button buttonB;
private int sPoint = 1;
@Override
protected void onCreate(final Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
story = (TextView) findViewById(R.id.nView);
buttonA = (Button) findViewById(R.id.buttonTop);
buttonB = (Button) findViewById(R.id.buttonBottom);
buttonA.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if ( sPoint == 1 | sPoint == 2 ) {
story.setText(R.string.V1_Story);
buttonA.setText(R.string.V1_Ans1);
buttonB.setText(R.string.V1_Ans2);
sPoint = 3;
}
else if (sPoint == 3 | sPoint == 4 ) {
story.setText(R.string.V3_Story);
buttonA.setText(R.string.V3_Ans1);
buttonB.setText(R.string.V3_Ans2);
sPoint = 5;
}
else if (sPoint == 5 | sPoint == 6 ) {
story.setText(R.string.V6_Story);
buttonA.setText(R.string.V6_Ans1);
buttonB.setText(R.string.V6_Ans2);
sPoint = 7;
}
else if (sPoint == 7) {
story.setText(R.string.V6_Story);
buttonA.setText(R.string.V6_Ans1);
buttonB.setText(R.string.V6_Ans2);
sPoint = 9;
}
}
});
buttonB.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if ( sPoint == 2 | sPoint == 3 ) {
story.setText(R.string.V2_Story);
buttonA.setText(R.string.V2_Ans1);
buttonB.setText(R.string.V2_Ans2);
sPoint = 4;
}
else if (sPoint == 4 | sPoint == 5) {
story.setText(R.string.V4_Story);
buttonA.setText(R.string.V4_Ans1);
buttonB.setText(R.string.V4_Ans2);
sPoint = 6;
}
else if (sPoint == 6 | sPoint == 7 ) {
story.setText(R.string.V6_Story);
buttonA.setText(R.string.V6_Ans1);
buttonB.setText(R.string.V6_Ans2);
sPoint = 8;
}
}
});
}
}