0% found this document useful (0 votes)
47 views4 pages

W W - W Ismultiply Math - Random W: 3. Player Will Guess Letter by Letter Until They Get The Correct Words

This document describes the formal statements for the rules and logic of a Hangman game. It defines: 1) An array of words for the player to guess from that is randomly selected 2) How the letters of the selected word are represented with asterisks initially 3) How the player guesses letters and the word is revealed if correct or hangman image progresses if incorrect 4) The increasing hangman image that is displayed based on the number of incorrect guesses

Uploaded by

Siti Syahirah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views4 pages

W W - W Ismultiply Math - Random W: 3. Player Will Guess Letter by Letter Until They Get The Correct Words

This document describes the formal statements for the rules and logic of a Hangman game. It defines: 1) An array of words for the player to guess from that is randomly selected 2) How the letters of the selected word are represented with asterisks initially 3) How the player guesses letters and the word is revealed if correct or hangman image progresses if incorrect 4) The increasing hangman image that is displayed based on the number of incorrect guesses

Uploaded by

Siti Syahirah
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Formal Statement

1. At the beginning of the Hangman, there are six words that the player must guess. The words are:
i. “terminator”
ii. “banana”
iii. “computer”
iv. “cow”
v. “rain”
vi. “water”
The informal statements are:
private static String[] words = {"terminator", "banana", "computer", "cow", "rain", "water" };
private static String word = words[(int) (Math.random() * words.length)];
private static String asterisk = new String(new char[word.length()]).replace("\0", "*");
 Denoted words in array is W
 Denoted word as w
 Words in array are multiply by Math.random to get the length of the words and become a
new declaration which is w
The formal statements:
∀ w ∈ W | W isMultiply Math.random  w

2. After the program select any words in array that the player must guess, it changes each letters of the
words to symbol “*” depends on the word length.
The formal statement:
private static String asterisk = new String(new char[word.length()]).replace("\0", "*");
 Denoted asterisk as A
 Denoted char as C
The informal statement:
∀ A ∈ w, C ∈ A | C(w.length()) isReplace(“\0”, “*”)  *

3. Player will guess letter by letter until they get the correct words.
The informal statement:
for (int i = 0; i < word.length(); i++)
{
if (word.charAt(i) == guess.charAt(0))
{
newasterisk += guess.charAt(0);
}
else if (asterisk.charAt(i) != '*')
{
newasterisk += word.charAt(i);
}
else
{
newasterisk += "*";
}
}

4. If the player got one wrong letter, the hangman image will appear little by little until 7 trial of
guessing the word.
The formal statement:
if (asterisk.equals(newasterisk))
{
count++;
hangmanImage();
}
 Denoted newasterisk as a
The informal statement:
 A ∈ a  count++, display hangmanImage(count == 1)

5. The hangman image is depending on count


Formal statement:
if (count == 1) {
System.out.println("Wrong guess, try again");
System.out.println();
System.out.println();
System.out.println();
System.out.println();
System.out.println("___|___");
System.out.println();
}
if (count == 2) {
System.out.println("Wrong guess, try again");
System.out.println(" |");
System.out.println(" |");
System.out.println(" |");
System.out.println(" |");
System.out.println(" |");
System.out.println(" |");
System.out.println(" |");
System.out.println("___|___");
}
if (count == 3) {
System.out.println("Wrong guess, try again");
System.out.println(" ____________");
System.out.println(" |");
System.out.println(" |");
System.out.println(" |");
System.out.println(" |");
System.out.println(" |");
System.out.println(" |");
System.out.println(" | ");
System.out.println("___|___");
}
if (count == 4) {
System.out.println("Wrong guess, try again");
System.out.println(" ____________");
System.out.println(" | _|_");
System.out.println(" | / \\");
System.out.println(" | | |");
System.out.println(" | \\_ _/");
System.out.println(" |");
System.out.println(" |");
System.out.println(" |");
System.out.println("___|___");
}
if (count == 5) {
System.out.println("Wrong guess, try again");
System.out.println(" ____________");
System.out.println(" | _|_");
System.out.println(" | / \\");
System.out.println(" | | |");
System.out.println(" | \\_ _/");
System.out.println(" | |");
System.out.println(" | |");
System.out.println(" |");
System.out.println("___|___");
}
if (count == 6) {
System.out.println("Wrong guess, try again");
System.out.println(" ____________");
System.out.println(" | _|_");
System.out.println(" | / \\");
System.out.println(" | | |");
System.out.println(" | \\_ _/");
System.out.println(" | |");
System.out.println(" | |");
System.out.println(" | / \\ ");
System.out.println("___|___ / \\");
}
if (count == 7) {
System.out.println("GAME OVER!");
System.out.println(" ____________");
System.out.println(" | _|_");
System.out.println(" | / \\");
System.out.println(" | | |");
System.out.println(" | \\_ _/");
System.out.println(" | _|_");
System.out.println(" | / | \\");
System.out.println(" | / \\ ");
System.out.println("___|___ / \\");
System.out.println("GAME OVER! The word was " + word);
}
 Denoted count as O
The informal statement:
 O ∈ w | O isCount++  display hangmanImage

You might also like