Skip to content

Commit

Permalink
Added Java program
Browse files Browse the repository at this point in the history
  • Loading branch information
AVS1508 committed Aug 2, 2020
1 parent 03f815e commit 81f281a
Showing 1 changed file with 83 additions and 0 deletions.
83 changes: 83 additions & 0 deletions Hollywood.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@

/**
* Project Title : Hollywood - A Movie Guessing Game
* Version : 1.0
* Developed By : Aditya Vikram Singh
*/

import java.util.*;

public class Hollywood {
public static String[] moviesList = { "INTERSTELLAR", "ARMAGEDDON", "INCEPTION", "PLANET OF THE APES",
"VAN HELSING", "IRON MAN", "PHANTOM THREAD", "LES MISERABLES", "THE REVENANT", "TITANIC", "THE DARK KNIGHT",
"ROCKY", "JUSTICE LEAGUE", "STAR WARS", "THE GODFATHER", "WONDER WOMAN", "COCO", "THE AVENGERS", "AVATAR",
"BRAVEHEART", "JURASSIC PARK", "MAN OF STEEL", "THE MATRIX", "LOGAN", "FORREST GUMP" };

static Scanner scan = new Scanner(System.in);

public static void main(String[] args) {
System.out.println("Hello! Let's play a game of HOLLYWOOD - a movie guessing game! ");
char toggle = 'Y';
do {
String movie = SelectRandomMovie();
String dummy = CreateDummyMovieAndEncode(movie);
System.out.println(dummy);
FillOrSlash(movie, dummy);

System.out.println("Do you want to play another game (Y/N)?");
toggle = scan.nextLine().charAt(0);
} while (toggle != 'N');
scan.close();
}

public static String SelectRandomMovie() {
return moviesList[(int) (25.0 * Math.random())];
}

public static String CreateDummyMovieAndEncode(String movie) {
char[] movieCopy = movie.toCharArray();
for (int i = 0; i < movieCopy.length; ++i) {
if (!(movieCopy[i] == 'A' || movieCopy[i] == 'E' || movieCopy[i] == 'I' || movieCopy[i] == 'O'
|| movieCopy[i] == 'U' || movieCopy[i] == ' ')) {
movieCopy[i] = '*';
}
}
return new String(movieCopy);
}

public static void FillOrSlash(String movie, String current) {
int chances = 9;
char input;
char[] currentCopy = current.toCharArray();
do {
do {
System.out.print("Guess a non-vowel alphabet: ");
input = Character.toUpperCase(scan.nextLine().charAt(0));
} while (input == 'A' || input == 'E' || input == 'I' || input == 'O' || input == 'U' || input == ' ');
boolean found = false;
for (int i = 0; i < movie.length(); ++i) {
if (input == movie.charAt(i)) {
currentCopy[i] = input;
found = true;
}
}
if (movie.equals(new String(currentCopy))) {
chances = 0;
System.out.println(movie);
System.out.println("Congratulations! You guessed the movie.");
} else if (!found) {
--chances;
System.out.println("Character not present!");
System.out.println(new String(currentCopy));
System.out.println("Chances remaining: " + chances);
} else {
System.out.println("Good guess!");
System.out.println(new String(currentCopy));
}
} while (chances > 0);
if (!movie.equals(new String(currentCopy))) {
System.out.println("Chances are over, sorry! Better luck next time!");
System.out.println("The movie was: " + movie);
}
}
}

0 comments on commit 81f281a

Please sign in to comment.