Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static void main(String[] args) {
- Scanner input = new Scanner(System.in);
- boolean UserCheck = true;
- String respond = "Y" ;
- int respondCount = 0 ;
- int[] randomCheckA = new int[150];
- int[] randomCheckB = new int[150];
- int[] randomCheckC = new int[150];
- int countrandomA = 0;
- int countrandomB = 0;
- int countrandomC = 0;
- while (UserCheck) {
- System.out.println("Welcome to Puzzle game");
- if (respondCount < 1) {
- System.out.println("Do you want to play press (Y) / (N)");
- }
- if (respondCount == 0) {
- respond = input.next();
- }
- if (respond.equals("y") || respond.equals("Y") || respondCount > 0) {
- Random Ran = new Random();
- String choice;
- String[] cities = new String[3];
- String[] animals = new String[3];
- String[] cars = new String[3];
- System.out.println("Select a catagorie n (a)Cars n (b)Cities n (c)Animals ");
- String ch = input.next();
- char c = ch.charAt(0);
- switch(c) {
- case 'a':
- if (countrandomC >= 3) {
- System.out.println("You have finished this catagories");
- break;
- }
- cars[0] = "ford";
- cars[1] = "nissan";
- cars[2] = "lexus";
- int random = Ran.nextInt(3);
- randomCheckC[random]++;
- while (true) {
- if (randomCheckC[random] > 1) {
- random = Ran.nextInt(3);
- }//if
- else {
- randomCheckC[random]++;
- countrandomB++;
- break;
- }
- }
- choice = cars[random];
- search(choice);
- break;
- case 'b':
- if (countrandomB >= 3) {
- System.out.println("You have finished this catagories");
- break;
- }//if
- animals[0] = "lion";
- animals[1] = "tiger";
- animals[2] = "cat";
- random = Ran.nextInt(3);
- randomCheckB[random]++;
- while (true) {
- if (randomCheckB[random] > 1) {
- random = Ran.nextInt(3);
- } //if
- else {
- randomCheckB[random]++;
- countrandomB++;
- break;
- }
- }
- choice = animals[random];
- search(choice);
- break;
- case 'c':
- if (countrandomA >= 3) {
- System.out.println("You have finished this catagories");
- break;
- }//if
- cities[0] = "alquds";
- cities[1] = "istanbul";
- cities[2] = "amman";
- random = Ran.nextInt(3);
- randomCheckA[random]++;
- while (true) {
- if (randomCheckA[random] > 1) {
- random = Ran.nextInt(3);
- }
- else {
- randomCheckA[random]++;
- countrandomA++;
- break;
- }
- }
- choice = cities[random];
- search(choice);
- break;
- default:
- System.out.println("Sorry your enter is not valid");
- break;
- }
- System.out.println("Congrats! you solved it n Do you want to play again?");
- String respond2 = input.next();
- if (!(respond2.equals("Y") || respond2.equals("y"))) {
- break;
- }
- respondCount++;
- }//if
- else {
- break;
- }
- }//while
- }//main
- public static String convert(String x) {
- String worda = x.replaceAll(".", "-");
- return worda;
- }
- public static void search(String choice) {
- int Try = 0;
- int[] lettersCheck = new int[150];
- Scanner input = new Scanner(System.in);
- int countWord;
- int count = 0;
- int count2 = 0;
- countWord = choice.length();
- System.out.println("The number of letters in the word is :" + countWord);
- System.out.println(convert(choice));
- StringBuilder FinalAnswer = new StringBuilder();
- while (count < countWord) {
- StringBuilder Answer = new StringBuilder();
- String c1 = input.next();
- char look = c1.charAt(0);
- lettersCheck[look]++;
- if ((choice.indexOf(look) != -1) && lettersCheck[look] <= 1) {
- for (int i = 0; i < choice.length(); i++) {
- if (choice.charAt(i) == look) {
- if (count2 == 0) {
- Answer.append(choice.charAt(i));
- FinalAnswer.append(choice.charAt(i));
- count++;
- }//if
- else {
- Answer.append(choice.charAt(i));
- FinalAnswer.replace(i, i + 1, "" + look);
- count++;
- }//else
- }//if
- else {
- if (count2 == 0) {
- FinalAnswer.append('-');
- }//if
- if (FinalAnswer.charAt(i) == '-') {
- Answer.append('-');
- } else {
- Answer.append(FinalAnswer.charAt(i));
- }
- }//else if
- }//for
- count2++;
- System.out.println(Answer);
- }//if
- else {
- if ((choice.indexOf(look) != -1) || lettersCheck[look] > 1) {
- System.out.println("You have already enter this charachter");
- }//if
- else {
- System.out.println("The letter is wrong reenter your letter");
- Try++;
- }
- if (Try >= 10) {
- System.out.println("Sorry you lost");
- break;
- }//if
- }//else if
- }//while
- }
Add Comment
Please, Sign In to add comment