public class MainActivity extends AppCompatActivity {
EditText edt, edt1, edt2;
TextView o1, o2;
Button ras, tem;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
edt = (EditText) findViewById(R.id.editText);
edt1 = (EditText) findViewById(R.id.editText2);
edt2 = (EditText) findViewById(R.id.editText3);
o1 = (TextView) findViewById(R.id.textView);
o2 = (TextView) findViewById(R.id.textView2);
tem = (Button) findViewById(R.id.button2);
ras = (Button) findViewById(R.id.button);
tem.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
edt1.setText("");
edt2.setText("");
}
});
ras.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Oyuncu 1
int say = 0;
int toplam = 0;
Random rnd = new Random();
//Oyuncu 2
int say2 = 0;
int toplam2 = 0;
Random rnd2 = new Random();
int x = 0;
while(x < 5) {
//Oyuncu 1
say = rnd.nextInt(10) + 1;
toplam = toplam + say;
edt1.setText(edt1.getText() + String.valueOf(say) + ", ");
//Oyuncu 2
say2 = rnd2.nextInt(10) + 1;
toplam2 = toplam2 + say2;
edt2.setText(edt2.getText() + String.valueOf(say2) + ", ");
x++;
}
if (say > say2) {
Toast.makeText(getApplicationContext(), "Oyuncu 1 kazandı!", Toast.LENGTH_SHORT).show();
edt.setText("Skor: "+String.valueOf(toplam));
} else if (say2 > say){
Toast.makeText(getApplicationContext(), "Oyuncu 2 kazandı!", Toast.LENGTH_SHORT).show();
edt.setText("Skor: "+String.valueOf(toplam2));
} else {
Toast.makeText(getApplicationContext(), "Berabere!", Toast.LENGTH_SHORT).show();
edt.setText("Skor: "+String.valueOf(toplam));
}
}
});
}
}