Oop Java Project 2 Guess The Movie
Oop Java Project 2 Guess The Movie
Ok, it's time to build your own project in Java, this time you'll be completing a game where
the player gets to guess the movie name given the number of letters in it (pretty much like
hangman but with movies)!
The rules are simple, the computer randomly picks a movie title, and shows you how many
letters it's made up of. Your goal is to try to figure out the movie by guessing one letter at a
time.
If a letter is indeed in the title the computer will reveal its correct position in the word, if
not, you lose a point. If you lose 10 points, game over!
BUT the more correct letters you guess the more obvious the movie becomes and at a
certain point you should be able to figure it out.
The program will randomly pick a movie title from a text file that contains a large list of
movies.
You can download a sample text file to play with from the resources tab or create your own
list of movie titles.
Once the computer picks a random title, it will display underscores "_" in place of the real
letters, thereby only giving away the number of letters in the movie title.
Then it will wait for the player to enter their first letter guess.
If the letter was indeed in the word, the underscores "_" that match that letter will be
replaced with the correct letter revealing how many letters have matched their guess and
where they are.
If their guess isn't in the movie title, then the output will display the same output as the
previous step as well as any letters that have been previously guessed wrong.
Eventually, if the player manages to guess all the letters in the movie title correctly before
they lost 10 points, they win
Everything you need to know to be able to build this game should be covered in the
previous lessons, but of course that doesn't mean it has to be easy! It's ok to get stuck and
it's absolutely normal for things to not work from the first time.
Just take it step by step, build a small part of the game first, test it and make sure it works
and then continue to add more to it.
And, whenever you reach a roadblock, head to the forum straight away, there are tons of
other students and mentors there that will be more than happy to help.
Download the movie list from here, and start coding. Good luck :)
Hints to help building Guess The Movie game
It's an important study in Cryptanalysis. More info about this, please read Letter
frequency from Wikipedia.
Use classes
This program will have more code than all of the exercises we've previously
covered, so it's a good idea to divide your code into classes instead of writing
everything in 1 class
A simple design would be to have at least one more class called Game that will
include methods responsible for handling a single guess or displaying the hidden
movie title etc.
Then have another class that contains the main method and controls the logic of
reading the user's input and calling the methods in the Game class
1. Write some code that will simply read the movie list and display the whole
list.
2. Then add to your code to randomly pick one movie and display that title only.
3. Then convert its letters to underscores (_) and display that instead, and so
on.
4. Once you've got that part done start reading the user's input and search for
it in the title.
5. Work on revealing the correct letters and displaying them.
6. Add the logic to keep track of wrong letters so they don't lose points for
guessing the same letter twice.
7. After that, you can keep track of how many wrong guesses and end the game
if they lose.
8. Finally, detect when they have guessed all the letters and let them know
they've won!
You can also start by hard coding a single movie title in the code instead of
randomly picking one from the file, then add the file reading functionality at the
end.
Test often
Every time you add new code that does something new, test it.
Make sure when testing to try all possible cases that you can think of (what if the
user tries to guess a space character? what if they type in a number? etc)
If you test often while building your code you will end up with fewer bugs as you get
closer to finishing it.
String methods
Check out all the powerful methods that Java has already written for you here.
Knowing the capabilities of your programming language can save you hours and
even days of re-writing code that already exists
For example: