Advertisement
Ivan_sjc

APP - Pedra Papel Tesoura

Sep 24th, 2020
1,048
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.07 KB | None | 0 0
  1. package com.novoandroid.pedrapapeltesoura;
  2.  
  3. import androidx.appcompat.app.AppCompatActivity;
  4.  
  5. import android.os.Bundle;
  6. import android.view.View;
  7. import android.widget.ImageView;
  8. import android.widget.TextView;
  9.  
  10. import java.util.Random;
  11.  
  12. public class MainActivity extends AppCompatActivity {
  13.  
  14.     @Override
  15.     protected void onCreate(Bundle savedInstanceState) {
  16.         super.onCreate(savedInstanceState);
  17.         setContentView(R.layout.activity_main);
  18.     }
  19.  
  20.  
  21.     public void selecionarPedra(View view) {
  22.  
  23.         this.opcaoSelecionada("pedra");
  24.  
  25.     }
  26.  
  27.     public void selecionarPapel(View view) {
  28.  
  29.         this.opcaoSelecionada("papel");
  30.  
  31.     }
  32.  
  33.     public void selecionarTesoura(View view) {
  34.  
  35.         this.opcaoSelecionada("tesoura");
  36.  
  37.     }
  38.  
  39.  
  40.     public void opcaoSelecionada(String opcaoSelecionada) {
  41.  
  42.         ImageView imagemResultado = findViewById(R.id.imageView5);
  43.         TextView textResultado = findViewById(R.id.textView3);
  44.  
  45.         int numero = new Random().nextInt(3);
  46.         String[] opcoes = {"Pedra", "Papel", "Tesoura"};
  47.         String opcaoApp = opcoes[numero];
  48.  
  49.         switch (opcaoApp) {
  50.  
  51.             case "pedra":
  52.                 imagemResultado.setImageResource(R.drawable.pedra);
  53.                 break;
  54.  
  55.             case "Papel":
  56.                 imagemResultado.setImageResource(R.drawable.papel);
  57.                 break;
  58.  
  59.             case "tesoura":
  60.                 imagemResultado.setImageResource(R.drawable.tesoura);
  61.                 break;
  62.  
  63.         }
  64.  
  65.  
  66.  
  67.         if (opcaoApp == "tesoura" && opcaoSelecionada == "papel"||
  68.                 opcaoApp == "papel" && opcaoSelecionada == "pedra"||
  69.                 opcaoApp == "pedra" && opcaoSelecionada == "tesoura")
  70.         {
  71.             textResultado.setText("você perdeu");
  72.  
  73.         }else if(opcaoSelecionada == "tesoura" && opcaoApp == "papel"||
  74.                 opcaoSelecionada == "papel" && opcaoApp == "pedra"||
  75.                 opcaoSelecionada == "pedra" && opcaoApp == "tesoura"){
  76.  
  77.             textResultado.setText("Você ganhou");
  78.         }
  79.  
  80.  
  81.     }
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement