Advertisement
CamiloCastilla

Untitled

Mar 3rd, 2020
141
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.69 KB | None | 0 0
  1. package com.company;
  2. import java.sql.SQLOutput;
  3. import java.util.Scanner;
  4. import java.util.Random;
  5. public class Main {
  6.  
  7.     public static void main(String[] args) {
  8.  
  9.         Random rand= new Random();
  10.         Scanner Keyboard= new Scanner(System.in);
  11.         int randomnumber = rand.nextInt();
  12.  
  13.  
  14.  
  15.         char [] word1 = {'g','e','n','g','a','r'};
  16.         char [] word2 = {'e','s','p','e','o','n'};
  17.         char dash [] = {'-','-','-','-','-','-'};
  18.  
  19.         String misses = "Misses: ";
  20.  
  21.         int tries = 0;
  22.         while(true) {
  23.  
  24.             int total = 0;
  25.             System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
  26.                 System.out.print("Word: ");
  27.                 for (int i = 0; i < dash.length; i++) {
  28.                     System.out.print(dash[i] + " ");
  29.                 }
  30.  
  31.                 Scanner keyboard = new Scanner(System.in);
  32.                 System.out.print("\n" + misses);
  33.                 System.out.print("\nGuess:");
  34.                 String input = keyboard.next();
  35.  
  36.  
  37.                 for (int i = 0; i < dash.length; i++) {
  38.                     if (input.charAt(0) == word1[i]) {
  39.                         dash[i] = word1[i];
  40.                         total++;
  41.                     }
  42.                 }
  43.  
  44.                 if(total == 0){
  45.                     misses = misses + input;
  46.                 }
  47.  
  48.                 tries++;
  49.  
  50.                 if (tries==10){
  51.                     System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
  52.                     System.out.println("GAME OVER");
  53.                     System.out.println("The word was " + word1);
  54.                     break;
  55.                 }
  56.                
  57.  
  58.  
  59.  
  60.         }
  61.     }
  62.  
  63. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement