Guest User

Untitled

a guest
May 22nd, 2020
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 4.61 KB | None | 0 0
  1. import androidx.appcompat.app.AlertDialog;
  2. import androidx.appcompat.app.AppCompatActivity;
  3.  
  4. import android.content.DialogInterface;
  5. import android.content.res.Resources;
  6. import android.graphics.drawable.Drawable;
  7. import android.os.Bundle;
  8. import android.view.View;
  9. import android.widget.Button;
  10. import android.widget.ImageView;
  11. import android.widget.LinearLayout;
  12. import android.widget.TextView;
  13. import android.widget.Toast;
  14.  
  15. import java.io.File;
  16. import java.util.ArrayList;
  17. import java.util.Collections;
  18. import java.util.List;
  19. import java.util.Locale;
  20. import java.util.Random;
  21.  
  22. public class RingOfFireActivity extends AppCompatActivity {
  23.  
  24.     private TextView cardsleftLabel;
  25.     private TextView cardskingLabel;
  26.     private ImageView cardImage;
  27.     private TextView infoLabel;
  28.     private TextView cardLabel;
  29.  
  30.     private int cardsLeft = 51;
  31.     private int cardsKing = 0;
  32.  
  33.     final int min = 1;
  34.     final int max = 13;
  35.     final int duplicate = 4;
  36.     List<Integer> cards = new ArrayList<Integer>();
  37.  
  38.     int getCard(){
  39.         if(cards.size()>0){
  40.             int val = cards.get(0);
  41.             cards.remove(0);
  42.             return val;
  43.         }
  44.         return 0;
  45.     }
  46.  
  47.     @Override
  48.     protected void onCreate(Bundle savedInstanceState) {
  49.         super.onCreate(savedInstanceState);
  50.         setContentView(R.layout.activity_ring_of_fire);
  51.  
  52.         cardsleftLabel = (TextView) findViewById(R.id.cardsleftLabel);
  53.         cardskingLabel = (TextView) findViewById(R.id.cardskingLabel);
  54.         cardImage = (ImageView) findViewById(R.id.cardImage);
  55.         infoLabel = (TextView) findViewById(R.id.infoLabel);
  56.         cardLabel = (TextView) findViewById(R.id.cardLabel);
  57.  
  58.         cardImage.setOnClickListener(new View.OnClickListener() {
  59.             @Override
  60.             public void onClick(View v) {
  61.                 imageTapped();
  62.             }
  63.         });
  64.  
  65.         for (int i = min; i <= max; i++) {
  66.             for (int j=0 ;j<duplicate; j++) {
  67.                 cards.add(i);
  68.             }
  69.         }
  70.         Collections.shuffle(cards);
  71.  
  72.         startGame();
  73.     }
  74.  
  75.     private void startGame() {
  76.  
  77.         cardsLeft = 52;
  78.         cardsKing = 0;
  79.  
  80.         Resources res = getResources();
  81.         String mDrawableName = "c0";
  82.         int resID = res.getIdentifier(mDrawableName , "drawable", getPackageName());
  83.         Drawable drawable = ((Resources) res).getDrawable(resID );
  84.         cardImage.setImageDrawable(drawable );
  85.  
  86.         cardsleftLabel.setText("🃏\n" + cardsLeft);
  87.         cardskingLabel.setText("👑\n" +  cardsKing);
  88.  
  89.         cardLabel.setText(R.string.prepare_your_drinks);
  90.         infoLabel.setText(R.string.tap_the_card_to_begin);
  91.     }
  92.  
  93.     private void randomizeCard() {
  94.         final int random = new Random().nextInt((max - min) + 1) + min;
  95.  
  96.         Resources res = getResources();
  97.         String mDrawableName = "c"+random;
  98.         int resID = res.getIdentifier(mDrawableName , "drawable", getPackageName());
  99.         Drawable drawable = ((Resources) res).getDrawable(resID );
  100.         cardImage.setImageDrawable(drawable );
  101.  
  102.         if (random == 1) {
  103.             cardLabel.setText(R.string.waterfall);
  104.         }
  105.         if (random == 2) {
  106.             cardLabel.setText(R.string.name_a_person_who_must_drink);
  107.         }
  108.         if (random == 3) {
  109.             cardLabel.setText(R.string.take_a_sip);
  110.         }
  111.         if (random == 4) {
  112.             cardLabel.setText(R.string.all_girls_must_drink);
  113.         }
  114.         if (random == 5) {
  115.             cardLabel.setText(R.string.the_thumb);
  116.         }
  117.         if (random == 6) {
  118.             cardLabel.setText(R.string.all_boys_must_drink);
  119.         }
  120.         if (random == 7) {
  121.             cardLabel.setText(R.string.point_at_the_sky);
  122.         }
  123.         if (random == 8) {
  124.             cardLabel.setText(R.string.drinking_partner);
  125.         }
  126.         if (random == 9) {
  127.             cardLabel.setText(R.string.rhyme);
  128.         }
  129.         if (random == 10) {
  130.             cardLabel.setText(R.string.category);
  131.         }
  132.         if (random == 11) {
  133.             cardLabel.setText(R.string.make_a_rule);
  134.         }
  135.         if (random == 12) {
  136.             cardLabel.setText(R.string.round_of_questions);
  137.         }
  138.         if (random == 13) {
  139.             cardLabel.setText(R.string.pour_drink_in_the_cup);
  140.             cardsKing += 1;
  141.             cardskingLabel.setText("👑\n" + cardsKing);
  142.         }
  143.     }
  144.  
  145.     private void imageTapped() {
  146.  
  147.         if (cardsLeft != 0) {
  148.  
  149.             randomizeCard();
  150.  
  151.             cardsLeft -= 1;
  152.  
  153.             cardsleftLabel.setText("🃏\n" + cardsLeft);
  154.         }
  155.     }
  156. }
Add Comment
Please, Sign In to add comment