Computer Science, asked by anamsaleem209, 10 months ago

i want know about the ideas used in hang man game in c++to improve my assignment

Answers

Answered by renu51622
0

Answer:

Hangman is a popular word guessing game where the player attempts to build a missing word by guessing one letter at a time. After a certain number of incorrect guesses, the game ends and the player loses. The game also ends if the player correctly identifies all the letters of the missing word.

Using the Code

The program consists of several classes. The class diagram is shown below:

Hangman_Class_Diagram.jpg

The main thing from the program is holding the guessed letters in an array collection and manipulating against the randomly picked word. In addition, you need to count the missing letters. Let's see the code that verifies the user's guessed letter and builds the word.

Hide Shrink Copy Code

/// <summary>

/// Process the user guessed letter against the random picked word

/// </summary>

public void Play()

{

guessed_FoundLetters = new List<string>();

for (int i = 0; i < PickedWord.WordLength; i++)

// Add underscore to the guessed and found string collection

{

guessed_FoundLetters.Add(" _ ");

}

for (int i = 0; i < PickedWord.WordLength; i++)

{

string letter = PickedWord.Content.Substring(i, 1);

if (GuessedLetters.Count > 0)

{

foreach (string guessedLetter in this.GuessedLetters)

{

if (letter.Equals(guessedLetter.Trim().ToUpper()))

// If the guessed letter is found from the picked

// word then replace underscore with the letter

{

guessed_FoundLetters.RemoveAt(i);

guessed_FoundLetters.Insert(i, " " + letter + " ");

}

}

}

}

drawHangMan();

Console.WriteLine(buildString(guessed_FoundLetters, false));

Console.WriteLine();

}

The enumeration class is an indicator whether a user is winning or losing the game.

Answered by randhirgupta100008
0

Explanation:

xkvkxrahAukfkHjdjdgsktkkjjketSyddddjhfsyslud

Similar questions