Jankengame.java
import java.util.Scanner;
public class Jankengeme {
	public static void main(String[] args) {
		int playerHand;
	    int cpuHand;
	    Scanner sc = new Scanner(System.in);
	    String rpfHands[] = {"Goo","Choki","Par"};
	    int replay;
	    int replay2=1;
	 try {
	    do{
	    //Traitement côté joueur
	    System.out.println("Veuillez saisir un nombre. 0: Goo, 1: Choki, 2: Par");
	    playerHand = sc.nextInt(); //Demandez aux élèves de saisir des nombres avec une entrée standard
	    System.out.println("La main que tu as tendue" + rpfHands[playerHand]); //Sortie manuelle du lecteur
	    //Traitement côté ordinateur
	     cpuHand = (int)(Math.random()*3); //Méthode aléatoire pour décider quoi faire de l'ordinateur
	     System.out.println("La main de l'ordinateur" + rpfHands[cpuHand]); //Sortie manuelle de l'ordinateur
	     //Jugement
	     Result result1 = new Result();
	     result1.result(cpuHand,playerHand);
	     System.out.println("Voudriez-vous essayer à nouveau? 0: Oui 1: Non");
	     replay = sc.nextInt();
	  }while(replay!=replay2);
	 		} catch( java.lang.ArrayIndexOutOfBoundsException e) {
	 			System.err.println("Erreur" + e.getMessage());
	 			} finally {
	 					System.out.println("terminer");
	 				}
	 					sc.close();
        }
}
Result.java
public class Result {
	   String result;
	   int rock = 0;
	   int scissors = 1;
	   int paper = 2;
	    public void result(int a, int b){
	        if(a == b){
	            result = "Je suis Aiko";
	        }else if((a == rock && b == scissors) || (a == scissors && b == paper ) ||
	        		(a == paper && b == rock )){
	        	result = "L'ordinateur gagne. Tu as perdu";
	        }else if((a == rock && b == paper) || (a == scissors && b == rock ) ||
	        		(a == paper && b == scissors )){
	        	result = "Vous gagnez. Ordinateur perdant";
	    }
	        System.out.println(result);
	}
}
        Recommended Posts