[JAVA] I want to know the answer of the rock-paper-scissors app

import android.app.Activity; import android.graphics.Color; import android.media.Image; import android.support.v4.widget.TextViewCompat; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.View; import android.widget.ImageView; import android.widget.TextView;

import java.util.Random;

public class MainActivity extends AppCompatActivity {

    private int selectedItem = -1;

protected void onCreate(Bundle savedInstanceState) {


// public void onClickAction(View view) { // ImageView image =(ImageView)findViewById(R.id.imageView); // image.setImageResource(R.drawable.Androidkun);

// }

public void itemSelectAction(View view) {
    ImageView[] items = new ImageView[3];
    items[0] = (ImageView)findViewById(R.id.imgGu);
    items[1] = (ImageView)findViewById(R.id.imgch);
    items[2] = (ImageView)findViewById(R.id.imgPa);

    for (int i = 0; i < items.length; i++){
        if(items[i] == view) {
            selectedItem = i;
        else {


public void startClickAction(View view) {
    int[] item = {R.drawable.j_gu02,R.drawable.j_ch02,R.drawable.j_pa02};
    Random rd = new Random();
    int cpu = rd.nextInt(3);

    ImageView src =(ImageView)findViewById(R.id.imgCpu);

    //ImageView cpu = (ImageView) findViewById(R.id.imgCpu);
   // cpu.setVisibility(View.INVISIBLE);

    //ImageView cpu = (ImageView) findViewById(R.id.imgCpu);


private int judgement(int cpu) {
    int result = -1;

     if (selectedItem == 0 && cpu == 1 || selectedItem == 1 && cpu == 2 || selectedItem == 2 && cpu == 0) {

result = 0; // Player wins } else if (selectedItem == 0 && cpu == 2 || selectedItem == 1 && cpu == 0 || selectedItem == 2 && cpu == 1) { result = 1; // Player loses } else if (selectedItem == cpu) { result = 2; // Draw } else { result = -1; // Other than win, lose, and draw (basically no) } return result;

private int judgement(int cpu) {

     /*if (selectedItem == 0 && cpu == 1 || selectedItem == 1 && cpu == 2 || selectedItem == 2 && cpu == 0){

TextView.setText ("win"); }else if(selectedItem == 0 && cpu == 2 || selectedItem == 1 && cpu == 0 || selectedItem == 2 && cpu == 1){ TextView.setText ("losing"); }else if (selectedItem == cpu){ TextView.setText ("draw"); }*/



Recommended Posts

I want to know the answer of the rock-paper-scissors app
I want to output the day of the week
I want to var_dump the contents of the intent
I want to display the name of the poster of the comment
I want to dark mode with the SWT app
I want to be aware of the contents of variables!
I want to return the scroll position of UITableView!
I want to expand the clickable part of the link_to method
I want to narrow down the display of docker ps
[Ruby] I want to reverse the order of the hash table
I want to temporarily disable the swipe gesture of UIPageViewController
I want to create a chat screen for the Swift chat app!
I want to understand the flow of Spring processing request parameters
I want to make an ios.android app
The story of Collectors.groupingBy that I want to keep for posterity
Want to know what Ruby n is the power of 2? (Power judgment of 2)
I want to limit the input by narrowing the range of numbers
I want to control the default error message of Spring Boot
I want to change the value of Attribute in Selenium of Ruby
I want to know the Method of the Controller where the Exception was thrown in the ExceptionHandler of Spring Boot
I want to display the number of orders for today using datetime.
[Ruby] I want to extract only the value of the hash and only the key
I want to pass the argument of Annotation and the argument of the calling method to aspect
I want to get the field name of the [Java] field. (Old tale tone)
I want you to use Enum # name () for the Key of SharedPreference
I want to truncate after the decimal point
I want to get the value in Ruby
[RxSwift] I want to deepen my understanding by following the definition of Observable
I want to get the value of Cell transparently regardless of CellType (Apache POI)
I want to play a GIF image on the Andorid app (Java, Kotlin)
I want to separate the handling of call results according to the API caller (call trigger)
I want to see the contents of Request without saying four or five
I want to recursively get the superclass and interface of a certain class
I want to call a method of another class
[Java] I want to calculate the difference from the date
I was addicted to the record of the associated model
I tried to summarize the state transition of docker
I want to judge the range using the monthly degree
I tried to reduce the capacity of Spring Boot
[Rails] I don't know how to use the model ...
I want to call the main method using reflection
[Rough commentary] I want to marry the pluck method
I want to simplify the log output on Android
I want to add a delete function to the comment function
[Ruby] I want to make a program that displays today's day of the week!
Rails The concept of view componentization of Rails that I want to convey to those who want to quit
[Active Admin] I want to specify the scope of the collection to be displayed in select_box
[Rails] I want to display the link destination of link_to in a separate tab
I want to reduce the number of unnecessary queries. From considering counter_cache to introducing counter_culture.
I want to convert characters ...
[Beginner] I want to modify the migration file-How to use rollback-
I tried to introduce Bootstrap 4 to the Rails 6 app [for beginners]
I want to set the conditions to be displayed in collection_check_boxes
[Rails] [bootstrap] I want to change the font size responsively
I tried to summarize the basics of kotlin and java
I want to use screen sharing on the login screen on Ubuntu 18
(ยด-`) .. oO (I want to easily find the standard output "Hello".
I want to push an app made with Rails 6 to GitHub
I want to bring Tomcat to the server and start the application
[Swift] I tried to implement the function of the vending machine
I want to call a method and count the number