Skip to content
Snippets Groups Projects
Commit c97c853f authored by Samuel Turpin's avatar Samuel Turpin :computer:
Browse files

ajout du jeu devine nombre

parent 0148e055
Branches
No related tags found
No related merge requests found
package projetjeu.autre;
public class Jeu {
public static void main(String[] args) {
}
}
package projetjeu.devinelenombre; package projetjeu.devinelenombre;
import java.util.Random;
import java.util.Scanner;
public class DevineNombre public class DevineNombre
{ {
private static void m(String m) private static void m(String m)
...@@ -10,8 +13,36 @@ public class DevineNombre ...@@ -10,8 +13,36 @@ public class DevineNombre
public static void main(String[] args) public static void main(String[] args)
{ {
m("Jouons à un jeu..."); m("Jouons à un jeu...");
m("Je vais penser à un nombre..."); m("Je vais penser à un nombre entre 1 et 100...");
m("Et toi tu devras le retrouver..."); m("Et toi tu devras le retrouver...");
m("Tu dispose de 5 tentatives..."); m("Tu dispose de 5 tentatives...");
Random rnd = new Random();
Scanner sc = new Scanner(System.in);
int nb = rnd.nextInt(1,100);
int lives = 5;
int reponse = 0;
while(lives != 0)
{
m("Nombre de Vies : " + lives);
reponse = sc.nextInt();
if(reponse == nb)
{
m("Bravo tu as réussis le nombre était " + nb);
lives=0;
}
else if (reponse < nb)
{
m("C'est plus !");
}
else if (reponse > nb)
{
m("C'est moins !");
}
lives=lives-1;
}
if(reponse != nb)
{
m("Perdu, le nombre était " + nb);
}
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment