This code is not printing the hangman after every wrong guess and i'm not sure how to fix

Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
icon
Related questions
Question
using System;
using System.Linq;
class MainClass
{
publicstaticvoid Main (string[] args)
{
string[] words = newstring[4]{"sheep","goat","mouse","lion"};
Random rnd = new Random();
int random = rnd.Next(1, 3);
string secretWord = words[random];
bool wordTest = secretWord.All(Char.IsLetter);
while (wordTest == false || secretWord.Length == 0)
{
Console.WriteLine("A word must contain (only) letters");
Console.Write("Please enter a word: ");
secretWord = Console.ReadLine();
wordTest = secretWord.All(Char.IsLetter);
}
secretWord = secretWord.ToUpper();
MyGame(secretWord);
}
publicstaticvoid MyGame(String secretWord)
{
Console.WriteLine("\n\n");
int lives = 5;
int counter = -1;
int wordLength = secretWord.Length;
char[] secretArray = secretWord.ToCharArray();
char[] printArray = newchar[wordLength];
char[] guessedLetters = newchar[26];
int numberStore = 0;
bool victory = false;
foreach(char letter in printArray)
{
counter++;
printArray[counter] = '-';
}
while(lives > 0)
{
counter = -1;
string printProgress = String.Concat(printArray);
bool letterFound = false;
int multiples = 0;
if (printProgress == secretWord)
{
victory = true;
break;
}
if (lives > 1)
{
Console.WriteLine("You have {0} lives!", lives);
}
else
{
Console.WriteLine("You only have {0} life left!!", lives);
}
Console.WriteLine("current progress: " + printProgress);
Console.Write("\n\n\n");
Console.Write("Guess a letter: ");
string playerGuess = Console.ReadLine();
bool guessTest = playerGuess.All(Char.IsLetter);
while (guessTest == false || playerGuess.Length != 1)
{
Console.WriteLine("Please enter only a single letter!");
Console.Write("Guess a letter: ");
playerGuess = Console.ReadLine();
guessTest = playerGuess.All(Char.IsLetter);
}
playerGuess = playerGuess.ToUpper();
char playerChar = Convert.ToChar(playerGuess);
if (guessedLetters.Contains(playerChar) == false)
{
guessedLetters[numberStore] = playerChar;
numberStore++;
foreach(char letter in secretArray)
{
counter++;
if (letter == playerChar)
{
printArray[counter] = playerChar;
letterFound = true;
multiples++;
}
}
if (letterFound)
{
Console.WriteLine("Found {0} letter {1}!", multiples, playerChar);
}
else
{
Console.WriteLine("No letter {0}!", playerChar);
lives--;
}
}
else
{
Console.WriteLine("You already guessed {0}!!", playerChar);
}
}
if (victory)
{
Console.WriteLine("\n\nThe word was: {0}", secretWord);
Console.WriteLine("\n\nYOU WIN!!!!!!!!!!!");
}
else
{
Console.WriteLine("\n\nThe word was: {0}", secretWord);
Console.WriteLine("\n\nYOU LOSE!!!!!!!!!");
}
}
privatestaticstring DrawGuy(int livesLeft)
{
string drawHangman = "";
if (livesLeft < 5)
{
drawHangman += "--------\n";
}
if (livesLeft < 4)
{
drawHangman += " |\n";
}
if (livesLeft < 3)
{
drawHangman += " O\n";
}
if (livesLeft < 2)
{
drawHangman += " /|\\ \n";
}
if (livesLeft == 0)
{
drawHangman += " / \\ \n";
}
return drawHangman;
}
}
 
This code is not printing the hangman after every wrong guess and i'm not sure how to fix it.
Run
main.cs
Console
Shell
using System;
using System.Ling;
class MainClass
1
3
Guess a letter: a
No letter A!
{
public static void Main (string[] args)
You have 4 lives!
current progress:
{
string[] words = new string[4]{"sheep","goat","mouse","lion"};
Random rnd = new Random();
6
int random = rnd. Next(1, 3);
string secretword - words[random];
bool wordTest = secretword.All(Char.IsLetter);
while (wordTest == false || secretword.Length == 0)
{
Console.WriteLine("A word must contain (only) letters");
Console.Write("Please enter a word: ");
Guess a letter: o
10
Found 1 letter o!
You have 4 lives!
11
current progress: -0---
12
13
14
15
Guess a letter: t
No letter T!
secretword = Console.ReadLine();
wordTest - secretword.All(Char.IsLetter);
16
You have 3 lives!
17
current progress: -o---
}
secretword - secretword. ToUpper();
18
19
MyGame (secretWord);
}
public static void MyGame (String secretword)
{
Console.Writeline("\n\n");
20
21
Guess a letter: m
Found 1 letter M!
22
You have 3 lives!
23
current progress: MO---
24
25
int lives = 5;
int counter = -1;
int wordLength = secretword. Length;
char[] secretArray = secretword.TocharArray ();
char[] printArray = new char[wordLength];
char[] guessedLetters = new char[26];
26
Guess a letter: u
27
Found 1 letter U!
28
You have 3 lives!
29
current progress: MOU--
30
31
int numberstore = 0;
32
bool victory = false;
foreach(char letter in printArray)
{
Guess a letter: s
33
Found 1 letter S!
34
You have 3 lives!
35
counter++;
current progress: MOUS-
printArray[counter] = '-';
36
37
}
while(lives > 0)
{
38
Guess a letter: e
39
Found 1 letter E!
40
counter - -1;
string printProgress = String.Concat (printArray);
bool letterFound = false;
int multiples = 0;
41
42
The word was: MOUSE
43
if (printProgress == secretword)
{
44
YOU WIN!!!!!!!!!!!
45
Transcribed Image Text:Run main.cs Console Shell using System; using System.Ling; class MainClass 1 3 Guess a letter: a No letter A! { public static void Main (string[] args) You have 4 lives! current progress: { string[] words = new string[4]{"sheep","goat","mouse","lion"}; Random rnd = new Random(); 6 int random = rnd. Next(1, 3); string secretword - words[random]; bool wordTest = secretword.All(Char.IsLetter); while (wordTest == false || secretword.Length == 0) { Console.WriteLine("A word must contain (only) letters"); Console.Write("Please enter a word: "); Guess a letter: o 10 Found 1 letter o! You have 4 lives! 11 current progress: -0--- 12 13 14 15 Guess a letter: t No letter T! secretword = Console.ReadLine(); wordTest - secretword.All(Char.IsLetter); 16 You have 3 lives! 17 current progress: -o--- } secretword - secretword. ToUpper(); 18 19 MyGame (secretWord); } public static void MyGame (String secretword) { Console.Writeline("\n\n"); 20 21 Guess a letter: m Found 1 letter M! 22 You have 3 lives! 23 current progress: MO--- 24 25 int lives = 5; int counter = -1; int wordLength = secretword. Length; char[] secretArray = secretword.TocharArray (); char[] printArray = new char[wordLength]; char[] guessedLetters = new char[26]; 26 Guess a letter: u 27 Found 1 letter U! 28 You have 3 lives! 29 current progress: MOU-- 30 31 int numberstore = 0; 32 bool victory = false; foreach(char letter in printArray) { Guess a letter: s 33 Found 1 letter S! 34 You have 3 lives! 35 counter++; current progress: MOUS- printArray[counter] = '-'; 36 37 } while(lives > 0) { 38 Guess a letter: e 39 Found 1 letter E! 40 counter - -1; string printProgress = String.Concat (printArray); bool letterFound = false; int multiples = 0; 41 42 The word was: MOUSE 43 if (printProgress == secretword) { 44 YOU WIN!!!!!!!!!!! 45
Expert Solution
steps

Step by step

Solved in 3 steps with 2 images

Blurred answer
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY