Created
May 11, 2018 16:26
-
-
Save edenizk/f17f314d708d04fbb3b3ebdd1bbb2d56 to your computer and use it in GitHub Desktop.
user throw dice at the same time as many dice as user wants.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.deniz.dicetheory; | |
import android.annotation.SuppressLint; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.CheckBox; | |
import android.widget.EditText; | |
import android.widget.ImageButton; | |
import android.widget.ImageView; | |
import android.widget.TextView; | |
import java.security.SecureRandom; | |
public class MainActivity extends AppCompatActivity { | |
int num1=0,num2=0,num3=0,num4=0,num5=0,num6=0; | |
SecureRandom secureRandomNum = new SecureRandom(); | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
final TextView txtDice[] = {(TextView) findViewById(R.id.txtdice1), | |
(TextView) findViewById(R.id.txtdice2), | |
(TextView) findViewById(R.id.txtdice3), | |
(TextView) findViewById(R.id.txtdice4), | |
(TextView) findViewById(R.id.txtdice5), | |
(TextView) findViewById(R.id.txtdice6)}; | |
final EditText edtNum = (EditText) findViewById(R.id.edtnumber); | |
Button Roll = (Button) findViewById(R.id.Roll); | |
ImageButton refresh = (ImageButton) findViewById(R.id.refresh); | |
final CheckBox addP = (CheckBox) findViewById(R.id.addP); | |
Roll.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
if (edtNum.getText().toString().matches("")) { | |
edtNum.setHint("Please Input a Number!!!!!"); | |
} else { | |
if (addP.isChecked()) { | |
} else { | |
num1 = 0; | |
num2 = 0; | |
num3 = 0; | |
num4 = 0; | |
num5 = 0; | |
num6 = 0; | |
for (int i = 0; i < 6; i++) { | |
txtDice[i].setText("0"); | |
} | |
} | |
int times = Integer.parseInt(edtNum.getText().toString()); | |
for (int i = 0; i < times; i++) { | |
int randomNum = 1 + secureRandomNum.nextInt(6); | |
switch (randomNum) { | |
case 1: | |
++num1; | |
break; | |
case 2: | |
++num2; | |
break; | |
case 3: | |
++num3; | |
break; | |
case 4: | |
++num4; | |
break; | |
case 5: | |
++num5; | |
break; | |
case 6: | |
++num6; | |
break; | |
} | |
txtDice[0].setText(num1 + ""); | |
txtDice[1].setText(num2 + ""); | |
txtDice[2].setText(num3 + ""); | |
txtDice[3].setText(num4 + ""); | |
txtDice[4].setText(num5 + ""); | |
txtDice[5].setText(num6 + ""); | |
} | |
} | |
} | |
}); | |
refresh.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
num1 = 0; | |
num2 = 0; | |
num3 = 0; | |
num4 = 0; | |
num5 = 0; | |
num6 = 0; | |
for(int i=0;i<6;i++){ | |
txtDice[i].setText("0"); | |
} | |
edtNum.setText(""); | |
edtNum.setHint("(How Many Dice You Wanna Roll?)"); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment