Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.company;
- import java.sql.SQLOutput;
- import java.util.Scanner;
- import java.util.Random;
- import java.util.Arrays;
- public class Main {
- public static void main(String[] args) {
- Random rand= new Random();
- Scanner Keyboard= new Scanner(System.in);
- int randomnumber = rand.nextInt();
- char [] word1 = {'f','i','n','g','e','r'};
- char [] word2 = {'s','c','h','o','o','l'};
- char [] word3 = {'d','o','l','l','a','r'};
- char [] word4 = {'f','a','m','i','l','y'};
- char [] word5 = {'d','e','v','i','c','e'};
- char dash [] = {'-','-','-','-','-','-'};
- char [] finalWord=null;
- int randint = rand.nextInt(6);
- if (randint==1) {
- finalWord =word1 ;
- } else if (randint==2) {
- finalWord =word2 ;
- } else if (randint==3) {
- finalWord =word3;
- }else if (randint==5){
- finalWord =word4;
- } else {
- finalWord =word5;
- }
- String misses = "Misses: ";
- String play = "yes";
- int tries = 0;
- int maxTries=10;
- while(play =="yes") {
- int total = 0;
- System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
- System.out.print("Word: ");
- for (int i = 0; i < dash.length; i++) {
- System.out.print(dash[i] + " ");
- }
- if ((Arrays.equals(finalWord,dash))) {
- System.out.println("\nYou did it! It took you " + tries + " tries");
- System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
- break;
- }
- Scanner keyboard = new Scanner(System.in);
- System.out.print("\n" + misses);
- System.out.print("\nGuess:");
- String input = keyboard.next();
- for (int i = 0; i < dash.length; i++) {
- if (input.charAt(0) == finalWord[i]) {
- dash[i] = finalWord[i];
- total++;
- }
- }
- if(total == 0){
- misses = misses + input.charAt(0);
- }
- tries++;
- if (tries==maxTries){
- System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
- System.out.println("GAME OVER");
- System.out.println("You couldn't guess the word in 10 tries!");
- System.out.println("-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-");
- break;
- }
- //scanner asking if play again yes== play , anything else will break the loop
- }
- }
- }
Add Comment
Please, Sign In to add comment