CPQ6: The Disappearing Player
VerifiedAdded on 2019/10/18
|6
|1055
|336
Practical Assignment
AI Summary
This practical assignment requires students to develop an interactive game in Java called "The Disappearing Player." The game is a variation of Hangman where the player guesses letters or the entire word to avoid losing body parts. The assignment provides a shell with a main method and several methods to be implemented by the student. Students must handle letter and word guesses, update the game state, and display the game's progress to the user. The assignment includes specific instructions on handling characters, using ArrayLists, and managing game logic. Extra credit is offered for preventing word repetition. The provided code includes examples and instructions for implementing the game's functionality.

Write an interactive game called The Disappearing Player. The Disappearing Player is a more
magical version of Hangman. In this game, the computer will make up a word, and the user will
try to guess that word before he or she disappears (the player has 8 body parts). The user can
guess either a letter or the full word.
Ex. of a game:
Welcome to The Disappearing Player. What is your name?
Joanna
O
/ | \
/ \
-
The secret word is: _ _ _ _ _ _ _ _
Guess a letter: A
A is not in the word. Joanna, you have only 7 body parts remaining.
O
/ | \
/ \
The secret word is: _ _ _ _ _ _ _ _ Incorrect guesses: A
Guess a letter or word: Z
Z is not in the word. Joanna, you have only 6 body parts remaining.
O
/ | \
/ \
The secret word is: _ _ _ _ _ _ _ _ Incorrect guesses: AZ
Guess a letter or word: E
E is in the word! Joanna, you still have only 6 body parts remaining.
magical version of Hangman. In this game, the computer will make up a word, and the user will
try to guess that word before he or she disappears (the player has 8 body parts). The user can
guess either a letter or the full word.
Ex. of a game:
Welcome to The Disappearing Player. What is your name?
Joanna
O
/ | \
/ \
-
The secret word is: _ _ _ _ _ _ _ _
Guess a letter: A
A is not in the word. Joanna, you have only 7 body parts remaining.
O
/ | \
/ \
The secret word is: _ _ _ _ _ _ _ _ Incorrect guesses: A
Guess a letter or word: Z
Z is not in the word. Joanna, you have only 6 body parts remaining.
O
/ | \
/ \
The secret word is: _ _ _ _ _ _ _ _ Incorrect guesses: AZ
Guess a letter or word: E
E is in the word! Joanna, you still have only 6 body parts remaining.
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

O
/ | \
/ \
The secret word is: _ _ _ _ _ _ E _ Incorrect guesses: AZ
Guess a letter or word: R
R is in the word! Joanna, you still have only 6 body parts remaining.
O
/ | \
/ \
The secret word is: _ _ _ _ _ _ E R Incorrect guesses: AZ
Guess a letter or word: SPITTER
Your word guess is wrong. Joanna, you have only 5 body parts remaining.
O
/ | \
/
The secret word is: _ _ _ _ _ _ E R Incorrect guesses: AZ
Guess a letter or word: COMPUTER
Your word guess is right! Joanna, you won!
Would you like to play again, Joanna? (y or n)
N
Your record was 1-0. Thank you for playing!
If the player loses all the body parts, they lose the game, and should be told the secret word. The
player can win by choosing the last letter correctly or by guessing the full word.
NOTE: If you want to print a backwards slash, write two of them in a string (and just one will be
printed).
System.out.println("/ \\"); // this prints: / \
NOTE: This is how you create an ArrayList of characters
/ | \
/ \
The secret word is: _ _ _ _ _ _ E _ Incorrect guesses: AZ
Guess a letter or word: R
R is in the word! Joanna, you still have only 6 body parts remaining.
O
/ | \
/ \
The secret word is: _ _ _ _ _ _ E R Incorrect guesses: AZ
Guess a letter or word: SPITTER
Your word guess is wrong. Joanna, you have only 5 body parts remaining.
O
/ | \
/
The secret word is: _ _ _ _ _ _ E R Incorrect guesses: AZ
Guess a letter or word: COMPUTER
Your word guess is right! Joanna, you won!
Would you like to play again, Joanna? (y or n)
N
Your record was 1-0. Thank you for playing!
If the player loses all the body parts, they lose the game, and should be told the secret word. The
player can win by choosing the last letter correctly or by guessing the full word.
NOTE: If you want to print a backwards slash, write two of them in a string (and just one will be
printed).
System.out.println("/ \\"); // this prints: / \
NOTE: This is how you create an ArrayList of characters

ArrayList<Character> guesses = new ArrayList<Character> ();
// ArrayList must hold an object, not a built in type like char
a Character object get be automatically converted to a char, like with:
char letter = guesses.get(i); // a Character gets assigned as a char
For this program, you are expected to call and write a number of methods. You will find the
methods that you need to write in the shell attached on PowerSchool. Please do not change
anything from the main or from playGame without checking with me first. I want you to use
what I’ve given you in the way that I gave it to you. When you turn in your code add your name
to the shell’s file name.
Extra credit, don't repeat words unless all the words were used
Shell that must be used
import java.util.ArrayList;
import java.util.Scanner;
public class CPQ6Shell {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
String user = introAndGetUserName();
int wins = 0;
int losses = 0;
String repeatGame="";
do {
boolean userWins = playGame(user); // returns true if user wins, false otherwise
// ArrayList must hold an object, not a built in type like char
a Character object get be automatically converted to a char, like with:
char letter = guesses.get(i); // a Character gets assigned as a char
For this program, you are expected to call and write a number of methods. You will find the
methods that you need to write in the shell attached on PowerSchool. Please do not change
anything from the main or from playGame without checking with me first. I want you to use
what I’ve given you in the way that I gave it to you. When you turn in your code add your name
to the shell’s file name.
Extra credit, don't repeat words unless all the words were used
Shell that must be used
import java.util.ArrayList;
import java.util.Scanner;
public class CPQ6Shell {
static Scanner sc = new Scanner(System.in);
public static void main(String[] args) {
String user = introAndGetUserName();
int wins = 0;
int losses = 0;
String repeatGame="";
do {
boolean userWins = playGame(user); // returns true if user wins, false otherwise
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide

if (userWins)
wins++;
else losses++;
repeatGame = askUserForAnotherGame(user); //returns "y" to repeat" and "n"
to quit
} while (repeatGame.equals("y"));
System.out.println("Your record was " + wins + "-" + losses + ". Thanks for playing!");
}
public static boolean playGame (String userName) {
char[] secretWord = computerChoosesSecretWord(); //randomly chooses from at least
20 words
char[] displayWord = initializeDisplayedWord(secretWord); //creates a char[] of same
size as
//secretWord, with all letters with '-'
ArrayList<Character> wrongLetters = new ArrayList<Character> (); // initializes empty list
while (!gameOver (displayWord, wrongLetters)) {
printPlayer (userName, wrongLetters);
System.out.print ("The secret word is: ");
showDisplayWord (displayWord);
System.out.print ("Guess a letter or word:");
String guess = sc.next ();
if (guess.length() == 1 && isInWord(guess, secretWord))
// updates displayWord and prints correct message
wins++;
else losses++;
repeatGame = askUserForAnotherGame(user); //returns "y" to repeat" and "n"
to quit
} while (repeatGame.equals("y"));
System.out.println("Your record was " + wins + "-" + losses + ". Thanks for playing!");
}
public static boolean playGame (String userName) {
char[] secretWord = computerChoosesSecretWord(); //randomly chooses from at least
20 words
char[] displayWord = initializeDisplayedWord(secretWord); //creates a char[] of same
size as
//secretWord, with all letters with '-'
ArrayList<Character> wrongLetters = new ArrayList<Character> (); // initializes empty list
while (!gameOver (displayWord, wrongLetters)) {
printPlayer (userName, wrongLetters);
System.out.print ("The secret word is: ");
showDisplayWord (displayWord);
System.out.print ("Guess a letter or word:");
String guess = sc.next ();
if (guess.length() == 1 && isInWord(guess, secretWord))
// updates displayWord and prints correct message
Paraphrase This Document
Need a fresh take? Get an instant paraphrase of this document with our AI Paraphraser

printCorrectLetterMessage(guess, displayWord, secretWord, userName,
wrongLetters);
if (guess.length() == 1 && !isInWord(guess, secretWord))
// updates wrong letters and prints message
printIncorrectLetterMessage(guess, displayWord, secretWord,
userName, wrongLetters);
if (guess.length() > 1 && isCorrectWord(guess, secretWord)) {
printCorrectWordMessage(displayWord, secretWord, userName,
wrongLetters);
return true;
}
if (guess.length() > 1 && !isCorrectWord(guess, secretWord)) {
printIncorrectWordMessage(displayWord, secretWord, userName,
wrongLetters);
}
}
if (wrongLetters.size() == 8) {
printGameLosingMessage();
return false;
} else {
return true;
}
}
wrongLetters);
if (guess.length() == 1 && !isInWord(guess, secretWord))
// updates wrong letters and prints message
printIncorrectLetterMessage(guess, displayWord, secretWord,
userName, wrongLetters);
if (guess.length() > 1 && isCorrectWord(guess, secretWord)) {
printCorrectWordMessage(displayWord, secretWord, userName,
wrongLetters);
return true;
}
if (guess.length() > 1 && !isCorrectWord(guess, secretWord)) {
printIncorrectWordMessage(displayWord, secretWord, userName,
wrongLetters);
}
}
if (wrongLetters.size() == 8) {
printGameLosingMessage();
return false;
} else {
return true;
}
}

}
⊘ This is a preview!⊘
Do you want full access?
Subscribe today to unlock all pages.

Trusted by 1+ million students worldwide
1 out of 6
Your All-in-One AI-Powered Toolkit for Academic Success.
+13062052269
info@desklib.com
Available 24*7 on WhatsApp / Email
Unlock your academic potential
Copyright © 2020–2026 A2Z Services. All Rights Reserved. Developed and managed by ZUCOL.