CamiloCastilla

Untitled

Mar 4th, 2020
488
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.77 KB | None | 0 0
  1. package com.company;
  2. import java.sql.SQLOutput;
  3. import java.util.Scanner;
  4. import java.util.Random;
  5. import java.util.Arrays;
  6. public class Main {
  7.  
  8.     public static void main(String[] args) {
  9.  
  10.         Random rand= new Random();
  11.         Scanner Keyboard= new Scanner(System.in);
  12.         int randomnumber = rand.nextInt();
  13.  
  14.  
  15.  
  16.         char [] word1 = {'f','i','n','g','e','r'};
  17.         char [] word2 = {'s','c','h','o','o','l'};
  18.         char [] word3 = {'d','o','l','l','a','r'};
  19.         char [] word4 = {'f','a','m','i','l','y'};
  20.         char [] word5 = {'d','e','v','i','c','e'};
  21.         char dash [] = {'-','-','-','-','-','-'};
  22.  
  23.         char [] finalWord=null;
  24.         int randint = rand.nextInt(6);
  25.  
  26.         if (randint==1) {
  27.             finalWord =word1 ;
  28.         } else if (randint==2) {
  29.             finalWord =word2 ;
  30.         } else if  (randint==3) {
  31.             finalWord =word3;
  32.         }else if  (randint==5){
  33.             finalWord =word4;
  34.         } else {
  35.             finalWord =word5;
  36.         }
  37.  
  38.  
  39.  
  40.         String misses = "Misses: ";
  41.  
  42.         String play = "yes";
  43.         int tries = 0;
  44.         int maxTries=10;
  45.         while(play =="yes") {
  46.  
  47.             int total = 0;
  48.             System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
  49.                 System.out.print("Word: ");
  50.                 for (int i = 0; i < dash.length; i++) {
  51.                     System.out.print(dash[i] + " ");
  52.                 }
  53.  
  54.                 if ((Arrays.equals(finalWord,dash))) {
  55.                     System.out.println("\nYou did it! It took you " + tries + " tries");
  56.                     System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
  57.                     break;
  58.                 }
  59.                 Scanner keyboard = new Scanner(System.in);
  60.                 System.out.print("\n" + misses);
  61.                 System.out.print("\nGuess:");
  62.                 String input = keyboard.next();
  63.  
  64.  
  65.                 for (int i = 0; i < dash.length; i++) {
  66.                     if (input.charAt(0) == finalWord[i]) {
  67.                         dash[i] = finalWord[i];
  68.                         total++;
  69.                     }
  70.                 }
  71.  
  72.                 if(total == 0){
  73.                     misses = misses + input.charAt(0);
  74.                 }
  75.  
  76.                 tries++;
  77.  
  78.  
  79.  
  80.                 if (tries==maxTries){
  81.                     System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
  82.                     System.out.println("GAME OVER");
  83.                     System.out.println("You couldn't guess the word in 10 tries!");
  84.                     System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
  85.                     break;
  86.                 }
  87.  
  88.  
  89. //scanner asking if play again yes== play , anything else will break the loop
  90.  
  91.  
  92.  
  93.  
  94.         }
  95.  
  96.  
  97.     }
  98.  
  99. }
Add Comment
Please, Sign In to add comment