Handling 20-face dice
This commit is contained in:
parent
531ebd6646
commit
e0ed947d30
@ -7,6 +7,7 @@ import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.Random;
|
||||
import java.util.StringTokenizer;
|
||||
|
||||
/**
|
||||
* Created by thibaud on 20/04/17.
|
||||
@ -15,14 +16,17 @@ import java.util.Random;
|
||||
public class DiceActivity extends Activity implements View.OnClickListener {
|
||||
|
||||
private TextView textResult;
|
||||
private int max;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_dice);
|
||||
|
||||
max = getIntent().getIntExtra("max", 0);
|
||||
|
||||
TextView textTitle = (TextView)findViewById(R.id.textTitle);
|
||||
textTitle.setText("6-sided dice");
|
||||
textTitle.setText(String.valueOf(max) + "-sided dice");
|
||||
|
||||
textResult = (TextView)findViewById(R.id.textResult);
|
||||
textResult.setText("");
|
||||
@ -34,7 +38,7 @@ public class DiceActivity extends Activity implements View.OnClickListener {
|
||||
@Override
|
||||
public void onClick(View v){
|
||||
Random rand = new Random();
|
||||
int result = rand.nextInt(6) + 1;
|
||||
this.textResult.setText(result);
|
||||
int result = rand.nextInt(max) + 1;
|
||||
this.textResult.setText(String.valueOf(result));
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(MainActivity.this, DiceActivity.class);
|
||||
intent.putExtra("max", 6);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
@ -27,6 +28,7 @@ public class MainActivity extends AppCompatActivity {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent intent = new Intent(MainActivity.this, DiceActivity.class);
|
||||
intent.putExtra("max", 20);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user