Last active
February 2, 2017 21:21
-
-
Save Apexal/7757f89647ca568ef95e337a7e7b3b38 to your computer and use it in GitHub Desktop.
Rock Paper Scissors
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Scanner; | |
class Main { | |
public static void main(String[] args) { | |
int monCoup = 0; | |
int monScore = 0; | |
int leScoredeLOrdinateur = 0; | |
String monChoix; | |
int maxScore = 4; | |
// Choix de l'ordinateur | |
while (monScore <= maxScore && leScoredeLOrdinateur <= maxScore){ | |
double leCoupDeLOrdinateur = Math.random(); | |
if (leCoupDeLOrdinateur<.33){ | |
leCoupDeLOrdinateur = 1; | |
} | |
else if (leCoupDeLOrdinateur < .66){ | |
leCoupDeLOrdinateur = 2; | |
} | |
else{ | |
leCoupDeLOrdinateur = 3; | |
} | |
System.out.println("Computer's choice is " + leCoupDeLOrdinateur); | |
// renter le choix de l'uitilisateur et le convertir | |
Scanner keyboard = new Scanner (System.in); | |
System.out.print("Enter rock, paper, or scissors: "); | |
monChoix = keyboard.next(); | |
if(monChoix.equalsIgnoreCase("rock")){ | |
monCoup = 1; | |
} | |
if (monChoix.equalsIgnoreCase("paper")){ | |
monCoup = 2; | |
} | |
if (monChoix.equalsIgnoreCase("cisor")){ | |
monCoup = 3; | |
} | |
if (leCoupDeLOrdinateur == monCoup) { | |
System.out.println("Tie!"); | |
} | |
else if (leCoupDeLOrdinateur == 1 && monCoup == 3){ | |
leScoredeLOrdinateur+= 1; | |
System.out.println("You lose!"); | |
} | |
else if (leCoupDeLOrdinateur == 3 && monCoup == 1){ | |
monScore += 1; | |
System.out.println("You win!"); | |
} | |
else if (leCoupDeLOrdinateur>monCoup){ | |
leScoredeLOrdinateur+= 1; | |
System.out.println("You lose!"); | |
} | |
else if (monCoup > leCoupDeLOrdinateur){ | |
monScore+= 1; | |
System.out.println("You win!"); | |
} | |
} | |
if (monScore >= maxScore){ | |
System.out.println ("You win " + monScore + " to " + leScoredeLOrdinateur + "."); | |
} | |
if (leScoredeLOrdinateur >= maxScore){ | |
System.out.println ("You lose " + leScoredeLOrdinateur + " to " + monScore + "."); | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment