Advertisement
Guest User

Untitled

a guest
Dec 6th, 2019
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.09 KB | None | 0 0
  1. public static void main(String[] args) throws Exception {
  2.         if(args.length==0) {
  3.             throw new Exception("no arg given brother man");
  4.         }
  5.        
  6.         File file_voc=new File(args[0]);
  7.         Scanner scanner=new Scanner(file_voc);
  8.        
  9.         String[] my_words=WordPuzzle.scanVocabulary(scanner);
  10.         printReadVocabulary(args[0], my_words.length);
  11.         //System.out.println("Read "+my_words.length+" words from "+args[0]);
  12.        
  13.         printSettingsMessage();
  14.         //System.out.println("--- Setting stage ---");
  15.         Scanner online_scan=new Scanner(System.in);
  16.        
  17.         Random generator = new MyRandom(new int[]{0,1,2,3,4,5},new float[]{0.0f,0.1f,0.2f,0.3f,0.4f,0.5f,0.6f,0.7f,0.8f,0.9f,1.0f});
  18.        
  19.         printEnterHidingProbability();
  20.         //System.out.println("Enter your hiding probability:");
  21.                
  22.         String userProbStr = online_scan.nextLine();
  23.         float userProbFloat = Float.parseFloat(userProbStr);
  24.  
  25.         boolean flagish = false;
  26.         String no = "no";
  27.         String yes = "yes";
  28.        
  29.         String randWord = null;
  30.         char[] thePuzzleCreated = null;
  31.        
  32.        
  33.         while (flagish != true) {
  34.            
  35.                 randWord = getRandomWord(my_words, generator);
  36.                 thePuzzleCreated = getRandomPuzzle(randWord, userProbFloat, generator);
  37.  
  38.                 printPuzzle(thePuzzleCreated);
  39.                 printReplacePuzzleMessage();
  40.                
  41.                 String ans = online_scan.next();
  42.                 while (!!!ans.equals(yes) && !!!ans.equals(no)) {
  43.                     printReplacePuzzleMessage();
  44.                    
  45.                     ans = online_scan.next();
  46.                 }
  47.                 if (!!ans.equals(no)) {
  48.                     flagish = true;
  49.                 }
  50.             }
  51.        
  52.         printGameStageMessage();
  53.         System.out.println(thePuzzleCreated);
  54.         //System.out.println("--- Game stage ---");
  55.                
  56.          int numOfHidden = countHowMany(thePuzzleCreated,HIDDEN_CHAR);
  57.          int attempts = numOfHidden +3 ;
  58.        
  59.         /*for(char ch:her_puzzle) {
  60.             if (ch=='_') {
  61.                 counter_hidden++;
  62.             }
  63.         }*/
  64.          
  65.         /*
  66.          * for(char ch: her_puzzle) System.out.print(ch);
  67.          */
  68.        
  69.          while (attempts>0) {
  70.              
  71.             printEnterYourGuessMessage();
  72.             String guess =online_scan.next();
  73.            
  74.             if(WordPuzzle.applyGuess(guess.charAt(0),randWord, thePuzzleCreated)>=1) {
  75.                     /*
  76.                      * int counting_hidden=0; for(char ch:her_puzzle) { if (ch=='_') {
  77.                      * counting_hidden++; } }
  78.                      */
  79.                
  80.                 int numOfHiddenNew = countHowMany(thePuzzleCreated,HIDDEN_CHAR);
  81.                
  82.                 if(numOfHiddenNew==0) {
  83.                     printWinMessage();
  84.                     break;
  85.                 }
  86.                
  87.                 else {
  88.                     int a = attempts - 1 ;
  89.                     printCorrectGuess(a);
  90.                     //System.out.println("Correct Guess, "+(attempts-1)+" guesses left");
  91.                     System.out.println(thePuzzleCreated);
  92.                 }
  93.             }
  94.             else if(guess.equals("H")){
  95.                 getHelp(randWord, thePuzzleCreated);
  96.                 int tempNumhidden = countHowMany(thePuzzleCreated, HIDDEN_CHAR);
  97.                 if(tempNumhidden==0) {
  98.                     printWinMessage();
  99.                     break;
  100.                 }
  101.                
  102.                 System.out.println(thePuzzleCreated);
  103.                
  104.                 attempts--;
  105.                
  106.             }
  107.             else {
  108.                 int attemptsNum = attempts -1;
  109.                 printWrongGuess(attemptsNum);
  110.                 //System.out.println("Wrong Guess, "+(attempts-1)+" guesses left");
  111.             }
  112.             attempts--;
  113.             }
  114.             if(attempts==0) {
  115.                 printGameOver();
  116.             }
  117.        
  118.        
  119.                    
  120.         scanner.close();
  121.         online_scan.close();
  122.  
  123.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement