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;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
// 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) {
items[i].setBackgroundColor(Color.RED);
selectedItem = i;
}
else {
items[i].setBackgroundColor(Color.WHITE);
}
}
}
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);
src.setImageResource(item[cpu]);
//ImageView cpu = (ImageView) findViewById(R.id.imgCpu);
// cpu.setVisibility(View.INVISIBLE);
//ImageView cpu = (ImageView) findViewById(R.id.imgCpu);
//cpu.setVisibility(View.VISIBLE);
}
private int judgement(int cpu) {
int result = -1;
if (selectedItem == 0 && cpu == 1 || selectedItem == 1 && cpu == 2 || selectedItem == 2 && cpu == 0) {
result = 0; // Le joueur gagne } else if (selectedItem == 0 && cpu == 2 || selectedItem == 1 && cpu == 0 || selectedItem == 2 && cpu == 1) { result = 1; // Le joueur perd } else if (selectedItem == cpu) { result = 2; // Dessiner } else { result = -1; // Autre que gagner, perdre, dessiner (fondamentalement pas venir) } return result;
private int judgement(int cpu) {
/*if (selectedItem == 0 && cpu == 1 || selectedItem == 1 && cpu == 2 || selectedItem == 2 && cpu == 0){
TextView.setText ("gagner"); }else if(selectedItem == 0 && cpu == 2 || selectedItem == 1 && cpu == 0 || selectedItem == 2 && cpu == 1){ TextView.setText ("perdre"); }else if (selectedItem == cpu){ TextView.setText ("dessiner"); }*/
}
}
}
Recommended Posts