Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.example.myapplication;
- import androidx.appcompat.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.ImageView;
- import android.widget.TextView;
- import android.widget.Toast;
- import java.util.Random;
- public class MainActivity extends AppCompatActivity {
- public int ustaw(int arg){
- if(arg==1){
- return R.drawable.k6_1;
- }
- else if(arg==2){
- return R.drawable.k6_2;
- }
- else if(arg==3){
- return R.drawable.k6_3;
- }
- else if(arg==4){
- return R.drawable.k6_4;
- }
- else if(arg==5){
- return R.drawable.k6_5;
- }
- else if(arg==6){
- return R.drawable.k6_6;
- }
- else{
- return R.drawable.k6_0;
- }
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- Random random = new Random();
- Button button = findViewById(R.id.button2);
- TextView tekst = findViewById(R.id.textView);
- ImageView image1=findViewById(R.id.imageView2);
- ImageView image2=findViewById(R.id.imageView3);
- ImageView image3=findViewById(R.id.imageView4);
- ImageView image4=findViewById(R.id.imageView5);
- ImageView image5=findViewById(R.id.imageView6);
- button.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- int[] tab = {random.nextInt(6)+1, random.nextInt(6)+1,random.nextInt(6)+1,random.nextInt(6)+1,random.nextInt(6)+1};
- image1.setImageResource(ustaw(tab[0]));
- image2.setImageResource(ustaw(tab[1]));
- image3.setImageResource(ustaw(tab[2]));
- image4.setImageResource(ustaw(tab[3]));
- image5.setImageResource(ustaw(tab[4]));
- int suma=0;
- int licz1=0;
- int licz2=0;
- int licz3=0;
- int licz4=0;
- int licz5=0;
- int licz6=0;
- for(int i=0;i<5;i++){
- if(tab[i]==1){
- licz1++;
- }
- else if(tab[i]==2){
- licz2++;
- }
- else if(tab[i]==3){
- licz3++;
- }
- else if(tab[i]==4){
- licz4++;
- }
- else if(tab[i]==5){
- licz5++;
- }
- else if(tab[i]==6) {
- licz6++;
- }
- }
- if(licz1>1){
- suma+=licz1*1;
- }
- if(licz2>1){
- suma+=licz2*2;
- }
- if(licz3>1){
- suma+=licz3*3;
- }
- if(licz4>1){
- suma+=licz4*4;
- }
- if(licz5>1){
- suma+=licz5*5;
- }
- tekst.setText(String.valueOf(suma));
- }
- });
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement