Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Create the word game GHOST in Java. Based in the following instructions. At the beginning of the program, read a file words.txt and save the

Create the word game GHOST in Java. Based in the following instructions.

At the beginning of the program, read a file words.txt and save the words into a regular array(Not array list). There will be 279496 words in the file. Do not read the file more than once in the program.

Ask for the number of players. Then, begin prompting players to enter a letter, one at a time. In the prompt, show the letters that have been entered so far. After the final player enters a letter, the first player goes again and so on until the game ends.

The game ends when either of two conditions occurs:

1) the letters entered form a word of at least four letters, or

2) the player enters a * to challenge the previous player.

If the letters form a word of at least four letters, the last player to enter a letter loses. If a * is entered, check to see if any word begins with the sequence of letters entered so far. If so, the player who entered a * loses. Otherwise, the last player to enter a letter loses. When the game ends, output the loser and end the program.

Sample out put:

Enter the number of players: 3 Player 1, it's your turn. The letters are . Enter a letter or enter * to challenge. S Player 2, it's your turn. The letters are S. Enter a letter or enter * to challenge. I Player 3, it's your turn. The letters are SI. Enter a letter or enter * to challenge. G Player 1, it's your turn. The letters are SIG. Enter a letter or enter * to challenge. N SIGN is a word. Player 1 loses!

Enter the number of players: 4 Player 1, it's your turn. The letters are . Enter a letter or enter * to challenge. G Player 2, it's your turn. The letters are G. Enter a letter or enter * to challenge. H Player 3, it's your turn. The letters are GH. Enter a letter or enter * to challenge. O Player 4, it's your turn. The letters are GHO. Enter a letter or enter * to challenge. T Player 1, it's your turn. The letters are GHOT. Enter a letter or enter * to challenge. * No word begins with those letters. Player 4 loses!

Enter the number of players: 4 Player 1, it's your turn. The letters are . Enter a letter or enter * to challenge. A Player 2, it's your turn. The letters are A. Enter a letter or enter * to challenge. A Player 3, it's your turn. The letters are AA. Enter a letter or enter * to challenge. R Player 4, it's your turn. The letters are AAR. Enter a letter or enter * to challenge. G Player 1, it's your turn. The letters are AARG. Enter a letter or enter * to challenge. * AARGH begins with those letters. Player 1 loses!

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design Application And Administration

Authors: Michael Mannino, Michael V. Mannino

2nd Edition

0072880678, 9780072880670

Students also viewed these Databases questions