Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import androidx.appcompat.app.AlertDialog;
- import androidx.appcompat.app.AppCompatActivity;
- import android.content.DialogInterface;
- import android.content.res.Resources;
- import android.graphics.drawable.Drawable;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.Button;
- import android.widget.ImageView;
- import android.widget.LinearLayout;
- import android.widget.TextView;
- import android.widget.Toast;
- import java.io.File;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.List;
- import java.util.Locale;
- import java.util.Random;
- public class RingOfFireActivity extends AppCompatActivity {
- private TextView cardsleftLabel;
- private TextView cardskingLabel;
- private ImageView cardImage;
- private TextView infoLabel;
- private TextView cardLabel;
- private int cardsLeft = 51;
- private int cardsKing = 0;
- final int min = 1;
- final int max = 13;
- final int duplicate = 4;
- List<Integer> cards = new ArrayList<Integer>();
- int getCard(){
- if(cards.size()>0){
- int val = cards.get(0);
- cards.remove(0);
- return val;
- }
- return 0;
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_ring_of_fire);
- cardsleftLabel = (TextView) findViewById(R.id.cardsleftLabel);
- cardskingLabel = (TextView) findViewById(R.id.cardskingLabel);
- cardImage = (ImageView) findViewById(R.id.cardImage);
- infoLabel = (TextView) findViewById(R.id.infoLabel);
- cardLabel = (TextView) findViewById(R.id.cardLabel);
- cardImage.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- imageTapped();
- }
- });
- for (int i = min; i <= max; i++) {
- for (int j=0 ;j<duplicate; j++) {
- cards.add(i);
- }
- }
- Collections.shuffle(cards);
- startGame();
- }
- private void startGame() {
- cardsLeft = 52;
- cardsKing = 0;
- Resources res = getResources();
- String mDrawableName = "c0";
- int resID = res.getIdentifier(mDrawableName , "drawable", getPackageName());
- Drawable drawable = ((Resources) res).getDrawable(resID );
- cardImage.setImageDrawable(drawable );
- cardsleftLabel.setText("🃏\n" + cardsLeft);
- cardskingLabel.setText("👑\n" + cardsKing);
- cardLabel.setText(R.string.prepare_your_drinks);
- infoLabel.setText(R.string.tap_the_card_to_begin);
- }
- private void randomizeCard() {
- final int random = new Random().nextInt((max - min) + 1) + min;
- Resources res = getResources();
- String mDrawableName = "c"+random;
- int resID = res.getIdentifier(mDrawableName , "drawable", getPackageName());
- Drawable drawable = ((Resources) res).getDrawable(resID );
- cardImage.setImageDrawable(drawable );
- if (random == 1) {
- cardLabel.setText(R.string.waterfall);
- }
- if (random == 2) {
- cardLabel.setText(R.string.name_a_person_who_must_drink);
- }
- if (random == 3) {
- cardLabel.setText(R.string.take_a_sip);
- }
- if (random == 4) {
- cardLabel.setText(R.string.all_girls_must_drink);
- }
- if (random == 5) {
- cardLabel.setText(R.string.the_thumb);
- }
- if (random == 6) {
- cardLabel.setText(R.string.all_boys_must_drink);
- }
- if (random == 7) {
- cardLabel.setText(R.string.point_at_the_sky);
- }
- if (random == 8) {
- cardLabel.setText(R.string.drinking_partner);
- }
- if (random == 9) {
- cardLabel.setText(R.string.rhyme);
- }
- if (random == 10) {
- cardLabel.setText(R.string.category);
- }
- if (random == 11) {
- cardLabel.setText(R.string.make_a_rule);
- }
- if (random == 12) {
- cardLabel.setText(R.string.round_of_questions);
- }
- if (random == 13) {
- cardLabel.setText(R.string.pour_drink_in_the_cup);
- cardsKing += 1;
- cardskingLabel.setText("👑\n" + cardsKing);
- }
- }
- private void imageTapped() {
- if (cardsLeft != 0) {
- randomizeCard();
- cardsLeft -= 1;
- cardsleftLabel.setText("🃏\n" + cardsLeft);
- }
- }
- }
Add Comment
Please, Sign In to add comment